diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/BHasher.cs b/OpenSim/Addons/os-webrtc-janus/Janus/BHasher.cs index 23b27f54e6..6d8524eff7 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/BHasher.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/BHasher.cs @@ -26,8 +26,6 @@ */ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; using System.Security.Cryptography; diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusAudioBridge.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusAudioBridge.cs index bf14cd208d..c2448e92ee 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusAudioBridge.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusAudioBridge.cs @@ -180,6 +180,7 @@ namespace osWebRtcVoice int roomNumber = Math.Abs(hashed.GetHashCode()); return roomNumber; } + public async Task SelectRoom(string pRegionId, string pChannelType, bool pSpatial, int pParcelLocalID, string pChannelID) { int roomNumber = CalcRoomNumber(pRegionId, pChannelType, pParcelLocalID, pChannelID); diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs index c45d6d06b0..e2f3a0dc3e 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs @@ -565,8 +565,7 @@ namespace osWebRtcVoice { } - public int ParticipantId { get { return PluginRespDataInt("id"); } } -// public long ParticipantId { get { return PluginRespDataLong("id"); } } + public long ParticipantId { get { return PluginRespDataLong("id"); } } } // ============================================================== @@ -591,7 +590,7 @@ namespace osWebRtcVoice // ============================================================== public class AudioBridgeLeaveRoomReq : PluginMsgReq { - public AudioBridgeLeaveRoomReq(int pRoomId, int pAttendeeId) : base(new OSDMap() { + public AudioBridgeLeaveRoomReq(int pRoomId, long pAttendeeId) : base(new OSDMap() { { "request", "leave" }, { "room", pRoomId }, { "id", pAttendeeId } @@ -628,6 +627,7 @@ namespace osWebRtcVoice { } } + // ============================================================== // The LongPoll request returns events from the plugins. These are formatted // like the other responses but are not responses to requests. diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusRoom.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusRoom.cs index 32bd745430..f0eea7b01e 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusRoom.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusRoom.cs @@ -75,8 +75,7 @@ namespace osWebRtcVoice JanusMessageResp resp = await _AudioBridge.SendPluginMsg(joinReq); AudioBridgeJoinRoomResp joinResp = new(resp); -// if (joinResp is not null && joinResp.AudioBridgeReturnCode == "joined" && joinResp.ParticipantId > 0) - if (joinResp is not null && joinResp.AudioBridgeReturnCode == "joined") + if (joinResp is not null && joinResp.AudioBridgeReturnCode == "joined" && joinResp.ParticipantId > 0) { pVSession.ParticipantId = joinResp.ParticipantId; pVSession.Answer = joinResp.Jsep; @@ -95,8 +94,7 @@ namespace osWebRtcVoice JanusMessageResp retryResp = await _AudioBridge.SendPluginMsg(retryJoinReq); AudioBridgeJoinRoomResp retryJoinResp = new(retryResp); -// if (retryJoinResp is not null && retryJoinResp.AudioBridgeReturnCode == "joined" && retryJoinResp.ParticipantId > 0) - if (retryJoinResp is not null && retryJoinResp.AudioBridgeReturnCode == "joined") + if (retryJoinResp is not null && retryJoinResp.AudioBridgeReturnCode == "joined" && retryJoinResp.ParticipantId > 0) { pVSession.ParticipantId = retryJoinResp.ParticipantId; pVSession.Answer = retryJoinResp.Jsep; @@ -115,7 +113,6 @@ namespace osWebRtcVoice } else { -/* if (joinResp is not null && joinResp.AudioBridgeReturnCode == "joined" && joinResp.ParticipantId <= 0) { m_log.ErrorFormat("{0} JoinRoom. Joined response contains invalid participant id {1} for room {2}", @@ -123,7 +120,7 @@ namespace osWebRtcVoice if (m_log.IsDebugEnabled) m_log.DebugFormat("{0} JoinRoom. Invalid participant detail: {1}", LogHeader, joinResp.ToString()); } -*/ + m_log.ErrorFormat("{0} JoinRoom. Failed to join room {1}", LogHeader, RoomId); if (m_log.IsDebugEnabled) m_log.DebugFormat("{0} JoinRoom. Failure detail: {1}", LogHeader, joinResp?.ToString() ?? "null"); @@ -176,10 +173,9 @@ namespace osWebRtcVoice if (!string.Equals(display, pDisplay, StringComparison.Ordinal)) continue; -// long participantId = participant.TryGetValue("id", out OSD idNode) ? idNode.AsLong() : 0L; -// if (participantId <= 0) -// continue; - int participantId = participant.TryGetValue("id", out OSD idNode) ? (int)idNode.AsLong() : 0; + long participantId = participant.TryGetValue("id", out OSD idNode) ? idNode.AsLong() : 0L; + if (participantId <= 0) + continue; JanusMessageResp leaveRespRaw = await _AudioBridge.SendPluginMsg(new AudioBridgeLeaveRoomReq(roomId, participantId)); AudioBridgeResp leaveResp = new(leaveRespRaw); diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusSession.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusSession.cs index 39f010fef3..ab2c1fa169 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusSession.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusSession.cs @@ -66,7 +66,7 @@ namespace osWebRtcVoice public string PluginId { get; set; } - private CancellationTokenSource _CancelTokenSource = new CancellationTokenSource(); +// private CancellationTokenSource _CancelTokenSource = new(); public bool IsConnected { get; set; } @@ -173,7 +173,7 @@ namespace osWebRtcVoice m_log.Error($"{LogHeader} DestroySession: exception ", e); } IsConnected = false; - _CancelTokenSource.Cancel(); +// _CancelTokenSource.Cancel(); return ret; } @@ -265,8 +265,7 @@ namespace osWebRtcVoice public async Task SendToJanus(JanusMessageReq pReq, string pURI, bool admin = false) { AddJanusHeaders(pReq, admin); - // m_log.DebugFormat("{0} SendToJanus", LogHeader); - if (_MessageDetails) m_log.DebugFormat("{0} SendToJanus. URI={1}, req={2}", LogHeader, pURI, pReq.ToJson()); + if (_MessageDetails) m_log.DebugFormat($"{LogHeader} SendToJanus. URI={pURI}, req={pReq.ToJson}"); // if (_MessageDetails) DebugLog("{0} SendToJanus. URI={1}, req={2}", LogHeader, pURI, pReq.ToJson()); JanusMessageResp ret = null; @@ -286,7 +285,8 @@ namespace osWebRtcVoice HttpRequestMessage reqMsg = new(HttpMethod.Post, pURI); reqMsg.Content = new StringContent(reqStr, System.Text.Encoding.UTF8, MediaTypeNames.Application.Json); reqMsg.Headers.TryAddWithoutValidation("Accept", "application/json"); - HttpResponseMessage response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token); +// HttpResponseMessage response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token); + HttpResponseMessage response = await httpClient.SendAsync(reqMsg); if (response.IsSuccessStatusCode) { @@ -295,7 +295,7 @@ namespace osWebRtcVoice if (ret.CheckReturnCode("ack")) { // Some messages are asynchronous and completed with an event - if (_MessageDetails) m_log.DebugFormat("{0} SendToJanus: ack response {1}", LogHeader, respStr); + if (_MessageDetails) m_log.Debug($"{LogHeader} SendToJanus: ack response {respStr}"); // if (_MessageDetails) DebugLog("{0} SendToJanus: ack response {1}", LogHeader, respStr); /* if (_OutstandingRequests.TryGetValue(pReq.TransactionId, out OutstandingRequest outstandingRequest)) @@ -314,14 +314,14 @@ namespace osWebRtcVoice { // If the response is not an ack, that means a synchronous request/response so return the response _= _OutstandingRequests.TryRemove(pReq.TransactionId, out _); - if (_MessageDetails) m_log.DebugFormat("{0} SendToJanus: response {1}", LogHeader, respStr); + if (_MessageDetails) m_log.Debug($"{LogHeader} SendToJanus: response {respStr}"); // if (_MessageDetails) DebugLog("{0} SendToJanus: response {1}", LogHeader, respStr); } } else { - m_log.ErrorFormat("{0} SendToJanus: response not successful {1}", LogHeader, response); + m_log.Error("{LogHeader} SendToJanus: response not successful {response}"); _= _OutstandingRequests.TryRemove(pReq.TransactionId, out _); } } @@ -362,7 +362,7 @@ namespace osWebRtcVoice } catch (Exception e) { - m_log.ErrorFormat("{0} SendToJanusNoWait: exception {1}", LogHeader, e.Message); + m_log.Error($"{LogHeader} SendToJanusNoWait: exception {e.Message}"); } return ret; @@ -399,12 +399,12 @@ namespace osWebRtcVoice // The following two are required for the WebSocket interface. They are optional for the // HTTP interface since the session and plugin handle are in the URL. // SessionId is added to the message if not already there - if (!pReq.hasSessionId && !String.IsNullOrEmpty(SessionId)) + if (!pReq.hasSessionId && !string.IsNullOrEmpty(SessionId)) { pReq.AddSessionId(SessionId); } // HandleId connects to the plugin - if (!pReq.hasHandleId && !String.IsNullOrEmpty(PluginId)) + if (!pReq.hasHandleId && !string.IsNullOrEmpty(PluginId)) { pReq.AddHandleId(PluginId); } @@ -458,16 +458,18 @@ namespace osWebRtcVoice HttpResponseMessage response = null; try { - response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token); +// response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token); + response = await httpClient.SendAsync(reqMsg).ConfigureAwait(false); + if (response is not null && response.IsSuccessStatusCode) { - string respStr = await response.Content.ReadAsStringAsync(); + string respStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false); ret = JanusMessageResp.FromJson(respStr); // m_log.DebugFormat("{0} GetFromJanus: response {1}", LogHeader, respStr); } else { - m_log.ErrorFormat("{0} GetFromJanus: response not successful {1}", LogHeader, response); + m_log.Error($"{LogHeader} GetFromJanus: response not successful {response}"); // m_log.ErrorFormat("{0} GetFromJanus: response not successful", LogHeader); // if (m_log.IsDebugEnabled) // m_log.DebugFormat("{0} GetFromJanus: response detail {1}", LogHeader, response); @@ -576,20 +578,21 @@ namespace osWebRtcVoice break; case "server_info": // Just info on the Janus instance - m_log.DebugFormat("{0} EventLongPoll: server_info {1}", LogHeader, resp.ToString()); + m_log.Debug($"{LogHeader} EventLongPoll: server_info {resp}"); break; case "ack": // 'ack' says the request was received and an event will follow - if (_MessageDetails) m_log.DebugFormat("{0} EventLongPoll: ack {1}", LogHeader, resp.ToString()); + if (_MessageDetails) m_log.Debug($"{LogHeader} EventLongPoll: ack {resp}"); break; case "success": // success is a sync response that says the request was completed - if (_MessageDetails) m_log.DebugFormat("{0} EventLongPoll: success {1}", LogHeader, resp.ToString()); + if (_MessageDetails) m_log.Debug($"{LogHeader} EventLongPoll: success {resp}"); break; case "trickle": // got a trickle ICE candidate from Janus // this is for reverse communication from Janus to the client and we don't do that - if (_MessageDetails) m_log.DebugFormat("{0} EventLongPoll: trickle {1}", LogHeader, resp.ToString()); + if (_MessageDetails) m_log.Debug($"{LogHeader} EventLongPoll: trickle {resp}"); + OnTrickle?.Invoke(eventResp); break; case "webrtcup": @@ -652,11 +655,11 @@ namespace osWebRtcVoice else { OnError?.Invoke(eventResp); - m_log.ErrorFormat("{0} EventLongPoll: error with no transaction. {1}", LogHeader, resp.ToString()); + m_log.Error($"{LogHeader} EventLongPoll: error with no transaction. {resp}"); } break; case "event": - if (_MessageDetails) m_log.DebugFormat("{0} EventLongPoll: event {1}", LogHeader, resp.ToString()); + if (_MessageDetails) m_log.Debug($"{LogHeader} EventLongPoll: event {resp}"); if (TryGetOutstandingRequest(resp.TransactionId, out OutstandingRequest outstandingRequest2)) { // Someone is waiting for this event diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusViewerSession.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusViewerSession.cs index e1c096487c..f8834111f6 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusViewerSession.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusViewerSession.cs @@ -54,8 +54,8 @@ namespace osWebRtcVoice public OMV.UUID AgentId { get; set; } // Janus keeps track of the user by this ID - public int ParticipantId { get; set; } -// public long ParticipantId { get; set; } +// public int ParticipantId { get; set; } + public long ParticipantId { get; set; } // Connections to the Janus server public JanusSession Session { get; set; } diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs b/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs index 0dac600dbc..cd870c9626 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs @@ -333,7 +333,7 @@ namespace osWebRtcVoice if (pRequest.TryGetOSDMap("jsep", out OSDMap jsep)) { - await viewerSession.ProvisionLock.WaitAsync().ConfigureAwait(false); + await viewerSession.ProvisionLock.WaitAsync(); try { diff --git a/OpenSim/Addons/os-webrtc-janus/WebRtcVoice/WebRtcVoiceServiceConnector.cs b/OpenSim/Addons/os-webrtc-janus/WebRtcVoice/WebRtcVoiceServiceConnector.cs index 89726de0a9..803291bb19 100644 --- a/OpenSim/Addons/os-webrtc-janus/WebRtcVoice/WebRtcVoiceServiceConnector.cs +++ b/OpenSim/Addons/os-webrtc-janus/WebRtcVoice/WebRtcVoiceServiceConnector.cs @@ -148,7 +148,7 @@ namespace osWebRtcVoice { "params", pParams } }; - OSDMap outerResponse = null; + OSDMap outerResponse; try { if (m_MessageDetails) m_log.Debug($"{LogHeader}: request: {request}");