/// <summary> /// Retrieve information about object media /// </summary> /// <param name="primID">UUID of the primitive</param> /// <param name="sim">Simulator where prim is located</param> /// <param name="callback">Call this callback when done</param> public void RequestObjectMedia(UUID primID, Simulator sim, ObjectMediaCallback callback) { Uri url; if (sim.Caps != null && null != (url = sim.Caps.CapabilityURI("ObjectMedia"))) { ObjectMediaRequest req = new ObjectMediaRequest(); req.PrimID = primID; req.Verb = "GET"; CapsClient request = new CapsClient(url); request.OnComplete += (CapsClient client, OSD result, Exception error) => { if (result == null) { Logger.Log("Failed retrieving ObjectMedia data", Helpers.LogLevel.Error, Client); try { callback(false, string.Empty, null); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } return; } ObjectMediaMessage msg = new ObjectMediaMessage(); msg.Deserialize((OSDMap)result); if (msg.Request is ObjectMediaResponse) { ObjectMediaResponse response = (ObjectMediaResponse)msg.Request; if (Client.Settings.OBJECT_TRACKING) { Primitive prim = sim.ObjectsPrimitives.Find((Primitive p) => { return p.ID == primID; }); if (prim != null) { prim.MediaVersion = response.Version; prim.FaceMedia = response.FaceMedia; } } try { callback(true, response.Version, response.FaceMedia); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } } else { try { callback(false, string.Empty, null); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } } }; request.BeginGetResponse(req.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT); } else { Logger.Log("ObjectMedia capability not available", Helpers.LogLevel.Error, Client); try { callback(false, string.Empty, null); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } } }
/// <summary> /// Handle a fetch request for media textures /// </summary> /// <param name="omr"></param> /// <returns></returns> protected string HandleObjectMediaRequest(ObjectMediaRequest omr) { UUID primId = omr.PrimID; SceneObjectPart part = m_scene.GetSceneObjectPart(primId); if (null == part) { m_log.WarnFormat( "[MOAP]: Received a GET ObjectMediaRequest for prim {0} but this doesn't exist in region {1}", primId, m_scene.RegionInfo.RegionName); return string.Empty; } if (null == part.Shape.Media) return string.Empty; ObjectMediaResponse resp = new ObjectMediaResponse(); resp.PrimID = primId; lock (part.Shape.Media) resp.FaceMedia = part.Shape.Media.ToArray(); resp.Version = part.MediaUrl; string rawResp = OSDParser.SerializeLLSDXmlString(resp.Serialize()); // m_log.DebugFormat("[MOAP]: Got HandleObjectMediaRequestGet raw response is [{0}]", rawResp); return rawResp; }
/// <summary> /// Handle a fetch request for media textures /// </summary> /// <param name="omr"></param> /// <returns></returns> protected string HandleObjectMediaRequest(ObjectMediaRequest omr) { UUID primId = omr.PrimID; ISceneChildEntity part = m_scene.GetSceneObjectPart (primId); if (null == part) { m_log.WarnFormat( "[MOAP]: Received a GET ObjectMediaRequest for prim {0} but this doesn't exist in region {1}", primId, m_scene.RegionInfo.RegionName); return string.Empty; } ObjectMediaResponse resp = new ObjectMediaResponse(); resp.PrimID = primId; resp.FaceMedia = new OpenSim.Framework.PrimitiveBaseShape.MediaList().ToArray(); resp.Version = "x-mv:0000000001/00000000-0000-0000-0000-000000000000"; if (null != part.Shape.Media) { lock (part.Shape.Media) resp.FaceMedia = part.Shape.Media.ToArray(); resp.Version = part.MediaUrl; } string rawResp = OSDParser.SerializeLLSDXmlString(resp.Serialize()); // m_log.DebugFormat("[MOAP]: Got HandleObjectMediaRequestGet raw response is [{0}]", rawResp); return rawResp; }
/// <summary> /// Handle a fetch request for media textures /// </summary> /// <param name = "omr"></param> /// <returns></returns> protected byte[] HandleObjectMediaRequest(ObjectMediaRequest omr) { UUID primId = omr.PrimID; ISceneChildEntity part = m_scene.GetSceneObjectPart(primId); if (null == part) { MainConsole.Instance.WarnFormat( "[MOAP]: Received a GET ObjectMediaRequest for prim {0} but this doesn't exist in region {1}", primId, m_scene.RegionInfo.RegionName); return MainServer.NoResponse; } ObjectMediaResponse resp = new ObjectMediaResponse { PrimID = primId, FaceMedia = new PrimitiveBaseShape.MediaList().ToArray(), Version = "x-mv:0000000001/00000000-0000-0000-0000-000000000000" }; if (null != part.Shape.Media) { lock (part.Shape.Media) resp.FaceMedia = part.Shape.Media.ToArray(); resp.Version = part.MediaUrl; } return OSDParser.SerializeLLSDXmlBytes(resp.Serialize()); }