mirror of
https://github.com/opensim/opensim.git
synced 2026-05-13 01:46:07 +08:00
cosmetics on janusmessages
This commit is contained in:
@@ -52,6 +52,7 @@ namespace osWebRtcVoice
|
||||
public JanusMessage()
|
||||
{
|
||||
}
|
||||
|
||||
// A basic Janus message is:
|
||||
// {
|
||||
// "janus": "operation",
|
||||
@@ -66,6 +67,7 @@ namespace osWebRtcVoice
|
||||
m_message["janus"] = pType;
|
||||
m_message["transaction"] = UUID.Random().ToString();
|
||||
}
|
||||
|
||||
public OSDMap RawBody => m_message;
|
||||
|
||||
public string TransactionId
|
||||
@@ -73,16 +75,19 @@ namespace osWebRtcVoice
|
||||
get { return m_message.TryGetString("transaction", out string tid) ? tid : null; }
|
||||
set { m_message["transaction"] = value; }
|
||||
}
|
||||
|
||||
public string Sender
|
||||
{
|
||||
get { return m_message.TryGetString("sender", out string tid) ? tid : null; }
|
||||
set { m_message["sender"] = value; }
|
||||
}
|
||||
|
||||
public OSDMap Jsep
|
||||
{
|
||||
get { return m_message.TryGetOSDMap("jsep", out OSDMap jsep) ? jsep : null; }
|
||||
set { m_message["jsep"] = value; }
|
||||
}
|
||||
|
||||
public void SetJsep(string pOffer, string pSdp)
|
||||
{
|
||||
m_message["jsep"] = new OSDMap()
|
||||
@@ -96,32 +101,41 @@ namespace osWebRtcVoice
|
||||
{
|
||||
m_message["apisecret"] = pToken;
|
||||
}
|
||||
|
||||
// Note that the session_id is a long number in the JSON so we convert the string.
|
||||
public string sessionId
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_message.TryGetValue("session_id", out OSD tmposd) ?
|
||||
OSDToLong(tmposd).ToString() : string.Empty;
|
||||
tmposd.AsLong().ToString() : string.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_message["session_id"] = long.Parse(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool hasSessionId
|
||||
{
|
||||
get { return m_message.ContainsKey("session_id"); }
|
||||
}
|
||||
|
||||
public void AddSessionId(string pToken)
|
||||
{
|
||||
AddSessionId(long.Parse(pToken));
|
||||
}
|
||||
|
||||
public void AddSessionId(long pToken)
|
||||
{
|
||||
m_message["session_id"] = pToken;
|
||||
}
|
||||
public bool hasHandleId { get { return m_message.ContainsKey("handle_id"); } }
|
||||
|
||||
public bool hasHandleId
|
||||
{
|
||||
get { return m_message.ContainsKey("handle_id"); }
|
||||
}
|
||||
|
||||
public void AddHandleId(string pToken)
|
||||
{
|
||||
m_message["handle_id"] = long.Parse(pToken);
|
||||
@@ -135,16 +149,13 @@ namespace osWebRtcVoice
|
||||
{
|
||||
return m_message.ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return m_message.ToString();
|
||||
}
|
||||
|
||||
public static long OSDToLong(OSD pIn)
|
||||
{
|
||||
return pIn.AsLong();
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
// A Janus request message is a basic Janus message with an API token
|
||||
public class JanusMessageReq : JanusMessage
|
||||
@@ -192,8 +203,11 @@ namespace osWebRtcVoice
|
||||
|
||||
// Check if a successful response code is in the response
|
||||
public virtual bool isSuccess { get { return CheckReturnCode("success"); } }
|
||||
|
||||
public virtual bool isEvent { get { return CheckReturnCode("event"); } }
|
||||
|
||||
public virtual bool isError { get { return CheckReturnCode("error"); } }
|
||||
|
||||
public virtual bool CheckReturnCode(string pCode)
|
||||
{
|
||||
return ReturnCode == pCode;
|
||||
@@ -244,7 +258,7 @@ namespace osWebRtcVoice
|
||||
get
|
||||
{
|
||||
return m_message.TryGetOSDMap("error", out OSDMap errMap) ?
|
||||
(int)OSDToLong(errMap["code"]) : 0;
|
||||
(int)errMap["code"].AsLong() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +272,7 @@ namespace osWebRtcVoice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
// Create session request and response
|
||||
public class CreateSessionReq : JanusMessageReq
|
||||
@@ -266,18 +281,24 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateSessionResp : JanusMessageResp
|
||||
{
|
||||
public CreateSessionResp(JanusMessageResp pResp) : base(pResp.RawBody)
|
||||
{ }
|
||||
public string returnedId { get {
|
||||
// The JSON response gives a long number (not a string)
|
||||
// and the ODMap conversion interprets it as a long (OSDLong).
|
||||
// If one just does a "ToString()" on the OSD object, you
|
||||
// get an interpretation of the binary value.
|
||||
return dataSection.ContainsKey("id") ? OSDToLong(dataSection["id"]).ToString() : String.Empty;
|
||||
}}
|
||||
public string returnedId
|
||||
{
|
||||
get
|
||||
{
|
||||
// The JSON response gives a long number (not a string)
|
||||
// and the ODMap conversion interprets it as a long (OSDLong).
|
||||
// If one just does a "ToString()" on the OSD object, you
|
||||
// get an interpretation of the binary value.
|
||||
return dataSection.TryGetValue("id", out OSD oid) ? oid.AsLong().ToString() : string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class DestroySessionReq : JanusMessageReq
|
||||
{
|
||||
@@ -286,6 +307,7 @@ namespace osWebRtcVoice
|
||||
// Doesn't include the session ID because it is the URI
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class TrickleReq : JanusMessageReq
|
||||
{
|
||||
@@ -307,6 +329,7 @@ namespace osWebRtcVoice
|
||||
m_message["candidate"] = pCandidates;
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AttachPluginReq : JanusMessageReq
|
||||
{
|
||||
@@ -315,6 +338,7 @@ namespace osWebRtcVoice
|
||||
m_message["plugin"] = pPlugin;
|
||||
}
|
||||
}
|
||||
|
||||
public class AttachPluginResp : JanusMessageResp
|
||||
{
|
||||
public AttachPluginResp(JanusMessageResp pResp) : base(pResp.RawBody)
|
||||
@@ -323,7 +347,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
get
|
||||
{
|
||||
return dataSection.ContainsKey("id") ? OSDToLong(dataSection["id"]).ToString() : string.Empty;
|
||||
return dataSection.TryGetValue("id", out OSD oid) ? oid.AsLong().ToString() : string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,6 +360,7 @@ namespace osWebRtcVoice
|
||||
// Doesn't include the session ID or plugin ID because it is the URI
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class HangupReq : JanusMessageReq
|
||||
{
|
||||
@@ -344,6 +369,7 @@ namespace osWebRtcVoice
|
||||
// Doesn't include the session ID or plugin ID because it is the URI
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
// Plugin messages are defined here as wrappers around OSDMap.
|
||||
// The ToJson() method is overridden to put the OSDMap into the
|
||||
@@ -366,18 +392,22 @@ namespace osWebRtcVoice
|
||||
{
|
||||
m_body = pBody;
|
||||
}
|
||||
|
||||
public void AddStringToBody(string pKey, string pValue)
|
||||
{
|
||||
m_body[pKey] = pValue;
|
||||
}
|
||||
|
||||
public void AddIntToBody(string pKey, int pValue)
|
||||
{
|
||||
m_body[pKey] = pValue;
|
||||
}
|
||||
|
||||
public void AddBoolToBody(string pKey, bool pValue)
|
||||
{
|
||||
m_body[pKey] = pValue;
|
||||
}
|
||||
|
||||
public void AddOSDToBody(string pKey, OSD pValue)
|
||||
{
|
||||
m_body[pKey] = pValue;
|
||||
@@ -389,6 +419,7 @@ namespace osWebRtcVoice
|
||||
return base.ToJson();
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin response is formatted like:
|
||||
// {
|
||||
// "janus": "success",
|
||||
@@ -430,16 +461,18 @@ namespace osWebRtcVoice
|
||||
{
|
||||
if (m_data is null)
|
||||
return 0;
|
||||
return m_data.ContainsKey(pKey) ? (int)OSDToLong(m_data[pKey]) : 0;
|
||||
return m_data.TryGetValue(pKey, out OSD okey) ? (int)okey.AsLong(): 0;
|
||||
}
|
||||
|
||||
// Get a string value for a key in the response data or empty string if not there
|
||||
public string PluginRespDataString(string pKey)
|
||||
{
|
||||
if (m_data is null)
|
||||
return String.Empty;
|
||||
return m_data.ContainsKey(pKey) ? m_data[pKey].AsString() : String.Empty;
|
||||
return string.Empty;
|
||||
return m_data.TryGetValue(pKey, out OSD okey) ? okey.AsString() : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
// Plugin messages for the audio bridge.
|
||||
// Audiobridge responses are formatted like:
|
||||
@@ -469,12 +502,14 @@ namespace osWebRtcVoice
|
||||
// Return the room ID if it is in the response or zero if not
|
||||
public int RoomId { get { return PluginRespDataInt("room"); } }
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeCreateRoomReq : PluginMsgReq
|
||||
{
|
||||
public AudioBridgeCreateRoomReq(int pRoomId) : this(pRoomId, false, null)
|
||||
{
|
||||
}
|
||||
|
||||
public AudioBridgeCreateRoomReq(int pRoomId, bool pSpatial, string pDesc) : base(new OSDMap() {
|
||||
{ "room", pRoomId },
|
||||
{ "request", "create" },
|
||||
@@ -490,6 +525,7 @@ namespace osWebRtcVoice
|
||||
AddStringToBody("description", pDesc);
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeDestroyRoomReq : PluginMsgReq
|
||||
{
|
||||
@@ -501,6 +537,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeJoinRoomReq : PluginMsgReq
|
||||
{
|
||||
@@ -512,14 +549,17 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// A successful response contains the participant ID and the SDP
|
||||
public class AudioBridgeJoinRoomResp : AudioBridgeResp
|
||||
{
|
||||
public AudioBridgeJoinRoomResp(JanusMessageResp pResp) : base(pResp)
|
||||
{
|
||||
}
|
||||
|
||||
public int ParticipantId { get { return PluginRespDataInt("id"); } }
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeConfigRoomReq : PluginMsgReq
|
||||
{
|
||||
@@ -530,6 +570,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class AudioBridgeConfigRoomResp : AudioBridgeResp
|
||||
{
|
||||
// TODO:
|
||||
@@ -537,6 +578,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeLeaveRoomReq : PluginMsgReq
|
||||
{
|
||||
@@ -548,6 +590,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeListRoomsReq : PluginMsgReq
|
||||
{
|
||||
@@ -557,6 +600,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeListParticipantsReq : PluginMsgReq
|
||||
{
|
||||
@@ -567,6 +611,7 @@ namespace osWebRtcVoice
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
public class AudioBridgeEvent : AudioBridgeResp
|
||||
{
|
||||
@@ -601,6 +646,7 @@ namespace osWebRtcVoice
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
|
||||
public class EventResp : JanusMessageResp
|
||||
{
|
||||
public EventResp() : base()
|
||||
|
||||
Reference in New Issue
Block a user