change voice modules handlers

master
UbitUmarov 2020-04-27 21:42:35 +01:00
parent 5929e43c2c
commit bfcbdc8a93
2 changed files with 124 additions and 93 deletions

View File

@ -63,8 +63,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// Capability string prefixes // Capability string prefixes
private static readonly string m_parcelVoiceInfoRequestPath = "0207/";
private static readonly string m_provisionVoiceAccountRequestPath = "0208/";
//private static readonly string m_chatSessionRequestPath = "0209/"; //private static readonly string m_chatSessionRequestPath = "0209/";
// Control info // Control info
@ -283,26 +281,17 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"[FreeSwitchVoice]: OnRegisterCaps() called with agentID {0} caps {1} in scene {2}", "[FreeSwitchVoice]: OnRegisterCaps() called with agentID {0} caps {1} in scene {2}",
agentID, caps, scene.RegionInfo.RegionName); agentID, caps, scene.RegionInfo.RegionName);
string capsBase = "/CAPS/" + caps.CapsObjectPath; caps.RegisterSimpleHandler("ProvisionVoiceAccountRequest",
caps.RegisterHandler( new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
"ProvisionVoiceAccountRequest", {
new RestStreamHandler( ProvisionVoiceAccountRequest(httpRequest, httpResponse, agentID, scene);
"POST", }));
capsBase + m_provisionVoiceAccountRequestPath,
(request, path, param, httpRequest, httpResponse)
=> ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps),
"ProvisionVoiceAccountRequest",
agentID.ToString()));
caps.RegisterHandler( caps.RegisterSimpleHandler("ParcelVoiceInfoRequest",
"ParcelVoiceInfoRequest", new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
new RestStreamHandler( {
"POST", ParcelVoiceInfoRequest(httpRequest, httpResponse, agentID, scene);
capsBase + m_parcelVoiceInfoRequestPath, }));
(request, path, param, httpRequest, httpResponse)
=> ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps),
"ParcelVoiceInfoRequest",
agentID.ToString()));
//caps.RegisterHandler( //caps.RegisterHandler(
// "ChatSessionRequest", // "ChatSessionRequest",
@ -325,11 +314,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="caps"></param> /// <param name="caps"></param>
/// <returns></returns> /// <returns></returns>
public string ProvisionVoiceAccountRequest(Scene scene, string request, string path, string param, public void ProvisionVoiceAccountRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
UUID agentID, Caps caps)
{ {
if(request.HttpMethod != "POST")
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
m_log.DebugFormat( m_log.DebugFormat(
"[FreeSwitchVoice][PROVISIONVOICE]: ProvisionVoiceAccountRequest() request: {0}, path: {1}, param: {2}", request, path, param); "[FreeSwitchVoice][PROVISIONVOICE]: ProvisionVoiceAccountRequest() request for {0}", agentID.ToString());
response.StatusCode = (int)HttpStatusCode.OK;
ScenePresence avatar = scene.GetScenePresence(agentID); ScenePresence avatar = scene.GetScenePresence(agentID);
if (avatar == null) if (avatar == null)
@ -338,7 +334,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
avatar = scene.GetScenePresence(agentID); avatar = scene.GetScenePresence(agentID);
if (avatar == null) if (avatar == null)
return "<llsd>undef</llsd>"; {
response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
return;
}
} }
string avatarName = avatar.Name; string avatarName = avatar.Name;
@ -375,14 +374,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
LLSDxmlEncode.AddElem("voice_sip_uri_hostname", m_freeSwitchRealm, lsl); LLSDxmlEncode.AddElem("voice_sip_uri_hostname", m_freeSwitchRealm, lsl);
LLSDxmlEncode.AddElem("voice_account_server_name", accounturl, lsl); LLSDxmlEncode.AddElem("voice_account_server_name", accounturl, lsl);
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
return LLSDxmlEncode.End(lsl); response.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1}, retry later", avatarName, e.Message); m_log.ErrorFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1}, retry later", avatarName, e.Message);
m_log.DebugFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1} failed", avatarName, e.ToString()); m_log.DebugFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1} failed", avatarName, e.ToString());
return "<llsd>undef</llsd>"; response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
} }
} }
@ -396,14 +395,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="caps"></param> /// <param name="caps"></param>
/// <returns></returns> /// <returns></returns>
public string ParcelVoiceInfoRequest(Scene scene, string request, string path, string param, public void ParcelVoiceInfoRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
UUID agentID, Caps caps)
{ {
if (request.HttpMethod != "POST")
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
response.StatusCode = (int)HttpStatusCode.OK;
m_log.DebugFormat( m_log.DebugFormat(
"[FreeSwitchVoice][PARCELVOICE]: ParcelVoiceInfoRequest() on {0} for {1}", "[FreeSwitchVoice][PARCELVOICE]: ParcelVoiceInfoRequest() on {0} for {1}",
scene.RegionInfo.RegionName, agentID); scene.RegionInfo.RegionName, agentID);
ScenePresence avatar = scene.GetScenePresence(agentID); ScenePresence avatar = scene.GetScenePresence(agentID);
if(avatar == null)
{
response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
return;
}
string avatarName = avatar.Name; string avatarName = avatar.Name;
// - check whether we have a region channel in our cache // - check whether we have a region channel in our cache
@ -416,8 +428,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
string channelUri; string channelUri;
if (null == scene.LandChannel) if (null == scene.LandChannel)
throw new Exception(String.Format("region \"{0}\": avatar \"{1}\": land data not yet available", {
scene.RegionInfo.RegionName, avatarName)); m_log.ErrorFormat("region \"{0}\": avatar \"{1}\": land data not yet available",
scene.RegionInfo.RegionName, avatarName);
response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
return;
}
// get channel_uri: check first whether estate // get channel_uri: check first whether estate
// settings allow voice, then whether parcel allows // settings allow voice, then whether parcel allows
@ -459,7 +475,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
return LLSDxmlEncode.End(lsl); response.RawBuffer= Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
} }
catch (Exception e) catch (Exception e)
{ {
@ -468,7 +484,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2} failed", m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2} failed",
scene.RegionInfo.RegionName, avatarName, e.ToString()); scene.RegionInfo.RegionName, avatarName, e.ToString());
return "<llsd>undef</llsd>"; response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
} }
} }

View File

@ -89,11 +89,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly Object vlock = new Object(); private static readonly Object vlock = new Object();
// Capability strings
private static readonly string m_parcelVoiceInfoRequestPath = "0107/";
private static readonly string m_provisionVoiceAccountRequestPath = "0108/";
//private static readonly string m_chatSessionRequestPath = "0109/";
// Control info, e.g. vivox server, admin user, admin password // Control info, e.g. vivox server, admin user, admin password
private static bool m_pluginEnabled = false; private static bool m_pluginEnabled = false;
private static bool m_adminConnected = false; private static bool m_adminConnected = false;
@ -427,37 +422,23 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
{ {
m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
string capsBase = "/CAPS/" + caps.CapsObjectPath; caps.RegisterSimpleHandler("ProvisionVoiceAccountRequest",
new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
ProvisionVoiceAccountRequest(httpRequest, httpResponse, agentID, scene);
}));
caps.RegisterHandler( caps.RegisterSimpleHandler("ParcelVoiceInfoRequest",
"ProvisionVoiceAccountRequest", new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
new RestStreamHandler( {
"POST", ParcelVoiceInfoRequest(httpRequest, httpResponse, agentID, scene);
capsBase + m_provisionVoiceAccountRequestPath, }));
(request, path, param, httpRequest, httpResponse)
=> ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps),
"ProvisionVoiceAccountRequest",
agentID.ToString()));
caps.RegisterHandler( //caps.RegisterSimpleHandler("ChatSessionRequest",
"ParcelVoiceInfoRequest", // new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
new RestStreamHandler( // {
"POST", // ChatSessionRequest(httpRequest, httpResponse, agentID, scene);
capsBase + m_parcelVoiceInfoRequestPath, // }));
(request, path, param, httpRequest, httpResponse)
=> ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps),
"ParcelVoiceInfoRequest",
agentID.ToString()));
//caps.RegisterHandler(
// "ChatSessionRequest",
// new RestStreamHandler(
// "POST",
// capsBase + m_chatSessionRequestPath,
// (request, path, param, httpRequest, httpResponse)
// => ChatSessionRequest(scene, request, path, param, agentID, caps),
// "ChatSessionRequest",
// agentID.ToString()));
} }
/// <summary> /// <summary>
@ -470,16 +451,25 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="caps"></param> /// <param name="caps"></param>
/// <returns></returns> /// <returns></returns>
public string ProvisionVoiceAccountRequest(Scene scene, string request, string path, string param, public void ProvisionVoiceAccountRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
UUID agentID, Caps caps)
{ {
if(request.HttpMethod != "POST")
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
response.StatusCode = (int)HttpStatusCode.OK;
try try
{ {
ScenePresence avatar = null; ScenePresence avatar = null;
string avatarName = null; string avatarName = null;
if (scene == null) if (scene == null)
return "<llsd><undef /></llsd>"; {
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
}
avatar = scene.GetScenePresence(agentID); avatar = scene.GetScenePresence(agentID);
int nretries = 10; int nretries = 10;
@ -490,7 +480,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
} }
if(avatar == null) if(avatar == null)
return "<llsd><undef /></llsd>"; {
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
}
avatarName = avatar.Name; avatarName = avatar.Name;
@ -592,7 +585,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
if (code != "OK") if (code != "OK")
{ {
m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: Get Account Request failed for \"{0}\"", avatarName); m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: Get Account Request failed for \"{0}\"", avatarName);
throw new Exception("Unable to execute request"); response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
} }
// Unconditionally change the password on each request // Unconditionally change the password on each request
@ -607,14 +601,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
LLSDxmlEncode.AddElem("voice_account_server_name", m_vivoxVoiceAccountApi, lsl); LLSDxmlEncode.AddElem("voice_account_server_name", m_vivoxVoiceAccountApi, lsl);
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
return LLSDxmlEncode.End(lsl); response.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
return;
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[VivoxVoice][PROVISIONVOICE]: : {0}, retry later", e.Message);
m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: : {0} failed", e.ToString()); m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: : {0} failed", e.ToString());
return "<llsd><undef /></llsd>";
} }
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
} }
/// <summary> /// <summary>
@ -627,10 +621,23 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="caps"></param> /// <param name="caps"></param>
/// <returns></returns> /// <returns></returns>
public string ParcelVoiceInfoRequest(Scene scene, string request, string path, string param, public void ParcelVoiceInfoRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
UUID agentID, Caps caps)
{ {
if (request.HttpMethod != "POST")
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
response.StatusCode = (int)HttpStatusCode.OK;
ScenePresence avatar = scene.GetScenePresence(agentID); ScenePresence avatar = scene.GetScenePresence(agentID);
if(avatar == null)
{
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
}
string avatarName = avatar.Name; string avatarName = avatar.Name;
// - check whether we have a region channel in our cache // - check whether we have a region channel in our cache
@ -642,9 +649,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
{ {
string channel_uri; string channel_uri;
if (null == scene.LandChannel) if (scene.LandChannel == null)
throw new Exception(String.Format("region \"{0}\": avatar \"{1}\": land data not yet available", {
scene.RegionInfo.RegionName, avatarName)); m_log.ErrorFormat("region \"{0}\": avatar \"{1}\": land data not yet available",
scene.RegionInfo.RegionName, avatarName);
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
}
// get channel_uri: check first whether estate // get channel_uri: check first whether estate
// settings allow voice, then whether parcel allows // settings allow voice, then whether parcel allows
@ -653,7 +664,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
LandData land = scene.GetLandData(avatar.AbsolutePosition); LandData land = scene.GetLandData(avatar.AbsolutePosition);
if (land == null) if (land == null)
{ {
return "<llsd><undef /></llsd>"; response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
return;
} }
// m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}", // m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}",
@ -691,17 +703,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
return LLSDxmlEncode.End(lsl); response.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
return;
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2}, retry later", m_log.ErrorFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2}, retry later",
scene.RegionInfo.RegionName, avatarName, e.Message); scene.RegionInfo.RegionName, avatarName, e.Message);
m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2} failed",
scene.RegionInfo.RegionName, avatarName, e.ToString());
return "<llsd><undef /></llsd>";
} }
response.RawBuffer = Util.UTF8.GetBytes("<llsd><undef /></llsd>");
} }
/// <summary> /// <summary>
@ -714,15 +724,20 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="caps"></param> /// <param name="caps"></param>
/// <returns></returns> /// <returns></returns>
public string ChatSessionRequest(Scene scene, string request, string path, string param, public void ChatSessionRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
UUID agentID, Caps caps)
{ {
if (request.HttpMethod != "POST")
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
// ScenePresence avatar = scene.GetScenePresence(agentID); // ScenePresence avatar = scene.GetScenePresence(agentID);
// string avatarName = avatar.Name; // string avatarName = avatar.Name;
// m_log.DebugFormat("[VivoxVoice][CHATSESSION]: avatar \"{0}\": request: {1}, path: {2}, param: {3}", // m_log.DebugFormat("[VivoxVoice][CHATSESSION]: avatar \"{0}\": request: {1}, path: {2}, param: {3}",
// avatarName, request, path, param); // avatarName, request, path, param);
return "<llsd>true</llsd>"; response.RawBuffer = Util.UTF8.GetBytes("<llsd>true</llsd>");
response.StatusCode = (int)HttpStatusCode.OK;
} }
private string RegionGetOrCreateChannel(Scene scene, LandData land) private string RegionGetOrCreateChannel(Scene scene, LandData land)