Got region module loading working.

Have room creation working. Joining is next.
This commit is contained in:
Robert Adams
2024-11-14 23:48:35 +00:00
parent 3953291fad
commit 854d368849
9 changed files with 102 additions and 34 deletions
+23 -8
View File
@@ -56,18 +56,33 @@ namespace WebRtcVoice
{
JanusMessageResp resp = await SendPluginMsg(new AudioBridgeCreateRoomReq(pRoomId, pSpacial, pRoomDesc));
AudioBridgeResp abResp = new AudioBridgeResp(resp);
if (abResp.ReturnCode == "created")
m_log.DebugFormat("{0} CreateRoom. ReturnCode: {1}", LogHeader, abResp.AudioBridgeReturnCode);
switch (abResp.AudioBridgeReturnCode)
{
ret = new JanusRoom(this, pRoomId);
}
else
{
m_log.ErrorFormat("{0} CreateRoom. Room creation failed: {1}", LogHeader, abResp.ToString());
}
case "created":
ret = new JanusRoom(this, pRoomId);
break;
case "event":
if (abResp.AudioBridgeErrorCode == 486)
{
m_log.ErrorFormat("{0} CreateRoom. Room {1} already exists {2}", LogHeader, pRoomId, abResp.ToString());
// if room already exists, just use it
ret = new JanusRoom(this, pRoomId);
}
else
{
m_log.ErrorFormat("{0} CreateRoom. XX Room creation failed: {1}", LogHeader, abResp.ToString());
}
break;
default:
m_log.ErrorFormat("{0} CreateRoom. YY Room creation failed: {1}", LogHeader, abResp.ToString());
break;
}
}
catch (Exception e)
{
m_log.ErrorFormat("{0} JoinRoom. Exception {1}", LogHeader, e);
m_log.ErrorFormat("{0} CreateRoom. Exception {1}", LogHeader, e);
}
return ret;
}
+53 -7
View File
@@ -59,6 +59,10 @@ namespace WebRtcVoice
{
return m_message.ToString();
}
public override string ToString()
{
return m_message.ToString();
}
}
// ==============================================================
public class JanusMessageReq : JanusMessage
@@ -223,7 +227,7 @@ namespace WebRtcVoice
private OSDMap m_body = new OSDMap();
public PluginMsgReq(OSDMap pBody) : base("message")
{
m_message["body"] = pBody;
m_body = pBody;
}
public void AddString(string pKey, string pValue)
{
@@ -269,19 +273,61 @@ namespace WebRtcVoice
AddString("description", pDesc);
}
}
// A plugin response is formatted like:
// {
// "janus": "success",
// "session_id": 5645225333294848,
// "transaction": "baefcec8-70c5-4e79-b2c1-d653b9617dea",
// "sender": 6969906757968657,
// "plugindata": {
// "plugin": "janus.plugin.audiobridge",
// "data": {
// "audiobridge": "created",
// "room": 10,
// "permanent": false
// }
// }
public class AudioBridgeResp: JanusMessageResp
{
OSDMap m_pluginData;
OSDMap m_data;
public AudioBridgeResp(JanusMessageResp pResp) : base(pResp.RawBody)
{ }
public override string ReturnCode { get {
string ret = String.Empty;
if (m_message is not null && m_message.ContainsKey("audiobridge"))
{
if (m_message is not null && m_message.ContainsKey("plugindata"))
{
ret = m_message["audiobridge"];
m_pluginData = m_message["plugindata"] as OSDMap;
if (m_pluginData.ContainsKey("data"))
{
m_data = m_pluginData["data"] as OSDMap;
m_log.DebugFormat("{0} AudioBridgeResp. Found both plugindata and data: data={1}", LogHeader, m_data.ToString());
}
}
}
// Return the return code if it is in the response or empty string if not
public string AudioBridgeReturnCode { get
{
string ret = String.Empty;
if (m_data is not null && m_data.ContainsKey("audiobridge"))
{
ret = m_data["audiobridge"];
}
return ret;
} }
public string RoomId { get { return m_message.ContainsKey("room") ? m_message["room"] : String.Empty; }}
// Return the error code if it is in the response or zero if not
public int AudioBridgeErrorCode { get
{
int ret = 0;
if (m_data is not null && m_data.ContainsKey("error_code"))
{
ret = (int)m_data["error_code"].AsLong();
}
return ret;
} }
// Return the room ID if it is in the response or zero if not
public int RoomId { get
{
return m_data.ContainsKey("room") ? (int)m_data["room"].AsLong() : 0;
} }
}
// ==============================================================
public class AudioBridgeDestroyRoomReq : PluginMsgReq
+9 -9
View File
@@ -36,10 +36,10 @@ namespace WebRtcVoice
private JanusSession _JanusSession;
public string PluginName { get; private set; }
public string HandleId { get; private set; }
public string HandleUri { get ; private set ; }
public string PluginId { get; private set; }
public string PluginUri { get ; private set ; }
public bool IsConnected => !String.IsNullOrEmpty(HandleId);
public bool IsConnected => !String.IsNullOrEmpty(PluginId);
// Wrapper around the session connection to Janus-gateway
public JanusPlugin(JanusSession pSession, string pPluginName)
@@ -60,11 +60,11 @@ namespace WebRtcVoice
public Task<JanusMessageResp> SendPluginMsg(OSDMap pParams)
{
return _JanusSession.PostToSession(new PluginMsgReq(pParams));
return _JanusSession.PostToJanus(new PluginMsgReq(pParams), PluginUri);
}
public Task<JanusMessageResp> SendPluginMsg(JanusMessageReq pJMsg)
public Task<JanusMessageResp> SendPluginMsg(PluginMsgReq pJMsg)
{
return _JanusSession.PostToSession(new PluginMsgReq(pJMsg.RawBody));
return _JanusSession.PostToJanus(pJMsg, PluginUri);
}
/// <summary>
@@ -82,9 +82,9 @@ namespace WebRtcVoice
if (resp is not null && resp.isSuccess)
{
var handleResp = new AttachPluginResp(resp);
HandleId = handleResp.pluginId;
HandleUri = _JanusSession.SessionUri + "/" + HandleId;
m_log.DebugFormat("{0} Activate. Created. ID={1}, URL={2}", LogHeader, HandleId, HandleUri);
PluginId = handleResp.pluginId;
PluginUri = _JanusSession.SessionUri + "/" + PluginId;
m_log.DebugFormat("{0} Activate. Created. ID={1}, URL={2}", LogHeader, PluginId, PluginUri);
ret = true;
}
else
+1 -1
View File
@@ -52,7 +52,7 @@ namespace WebRtcVoice
public Task<bool> JoinRoom(string pSdp)
{
// TODO:
return Task.FromResult(true);
return Task.FromResult(false);
}
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ namespace WebRtcVoice
return await PostToJanus(pReq, _JanusServerURI);
}
private async Task<JanusMessageResp> PostToJanus(JanusMessageReq pReq, string pURI)
public async Task<JanusMessageResp> PostToJanus(JanusMessageReq pReq, string pURI)
{
if (!String.IsNullOrEmpty(_JanusAPIToken))
{
@@ -32,6 +32,9 @@ using OSDMap = OpenMetaverse.StructuredData.OSDMap;
using log4net;
using Nini.Config;
[assembly: Addin("WebRtcVoiceRegionModule", "1.0")]
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
namespace WebRtcVoice
{
/// <summary>
@@ -46,11 +49,11 @@ namespace WebRtcVoice
/// The capabilities then pass the user request information to the IWebRtcVoiceService interface
/// that has been registered for the reqion.
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WebRtcVoiceModule")]
public class WebRtcVoiceModule : ISharedRegionModule
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionVoiceModule")]
public class WebRtcVoiceRegionModule : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly string logHeader = "[WEBRTC VOICE]";
private static readonly string logHeader = "[REGION WEBRTC VOICE]";
// Control info
private static bool m_Enabled = false;
@@ -62,6 +65,7 @@ namespace WebRtcVoice
public void Initialise(IConfigSource config)
{
m_log.Info($"{logHeader}: RegionVoiceModule initializing");
m_Config = config.Configs["WebRtcVoice"];
if (m_Config is null) return;
@@ -118,7 +122,7 @@ namespace WebRtcVoice
public string Name
{
get { return "WebRtcVoiceModule"; }
get { return "RegionVoiceModule"; }
}
public Type ReplaceableInterface
@@ -6,7 +6,7 @@
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ImplicitUsings>disable</ImplicitUsings>
<AssemblyName>WebRtcVoiceModule</AssemblyName>
<AssemblyName>WebRtcVoiceRegionModule</AssemblyName>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<GenerateDependencyFile>false</GenerateDependencyFile>
@@ -106,7 +106,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="WebRtcVoiceModule.cs">
<Compile Include="WebRtcVoiceRegionModule.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
@@ -22,6 +22,9 @@ using Mono.Addins;
using log4net;
using Nini.Config;
[assembly: Addin("WebRtcVoiceServiceModule", "1.0")]
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
namespace WebRtcVoice
{
/// <summary>
@@ -1,6 +1,6 @@
<Project
name="WebRtcVoiceModule"
path="addon-modules/os-webrtc-janus/WebRtcVoiceModule"
name="WebRtcVoiceRegionModule"
path="addon-modules/os-webrtc-janus/WebRtcVoiceRegionModule"
type="Library">
<Configuration name="Debug">