Browse Source

add common and remove litejson from server

arthur.wu 2 years ago
parent
commit
b4c15ad94b

+ 7 - 0
VRTC/VRTC.Common/Class1.cs

@@ -0,0 +1,7 @@
+namespace VRTC.Common
+{
+    public class Class1
+    {
+
+    }
+}

+ 9 - 0
VRTC/VRTC.Common/VRTC.Common.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>

+ 51 - 0
VRTC/VRTC.Common/WebSocketClientMessage.cs

@@ -0,0 +1,51 @@
+using System.Text.Json.Serialization;
+
+namespace VRTC
+{
+    public class WebSocketClientMessage
+    {
+        /// <summary>
+        /// The commad from client
+        /// </summary>
+        [JsonPropertyName("command")]
+        public string Command { get; set; }
+        /// <summary>
+        /// The rtc room ID
+        /// </summary>
+        [JsonPropertyName("roomId")]
+        public uint RoomId { get; set; }
+        /// <summary>
+        /// The client ID
+        /// </summary>
+        [JsonPropertyName("clientId")]
+        public string ClientId { get; set; }               
+    }
+
+    public class WebSocketClientSdpMessage :WebSocketClientMessage
+    {                            
+        /// <summary>
+        /// The Web rtc protocol
+        /// </summary>
+        [JsonPropertyName("sdp")]
+        public string Sdp { get; set; }
+    }
+
+    public class WebSocketClientCandidateMessage : WebSocketClientMessage
+    {
+        /// <summary>
+        /// If present, this is the value of the "a=mid" attribute of the candidate's
+        /// </summary>
+        [JsonPropertyName("sdpMid")]
+        public string SdpMid { get; set; }
+        /// <summary>
+        /// This indicates the index (starting at zero) of m= section this candidate is associated with. Needed when an endpoint doesn't support MIDs.
+        /// </summary>
+        [JsonPropertyName("sdpMLineIndex")]
+        public int SdpMlineIndex { get; set; }
+        /// <summary>
+        /// The Web rtc protocol
+        /// </summary>
+        [JsonPropertyName("candidate")]
+        public string Candidate { get; set; }
+    }
+}

+ 65 - 0
VRTC/VRTC.Common/WebSocketServerMessage.cs

@@ -0,0 +1,65 @@
+using System.Text.Json.Serialization;
+
+namespace VRTC
+{
+    public enum JoinState
+    {
+        RoomOpened,
+        RoomJoined
+    }
+    public abstract class WebSocketServerMessageBase
+    {
+        /// <summary>
+        /// The commad from client
+        /// </summary>
+        [JsonPropertyName("command")]
+        public string Command { get; set; }
+        /// <summary>
+        /// The rtc room ID
+        /// </summary>
+        [JsonPropertyName("roomId")]
+        public uint RoomId { get; set; }
+        /// <summary>
+        /// The client ID
+        /// </summary>
+        [JsonPropertyName("clientId")]
+        public string ClientId { get; set; }
+    }
+
+    public class WebSocketServerMessage : WebSocketClientMessage
+    {
+        /// <summary>
+        /// The Web rtc protocol
+        /// </summary>
+        [JsonPropertyName("state")]
+        public JoinState State { get; set; }
+    }
+
+    public class WebSocketServerSdpMessage : WebSocketClientMessage
+    {
+        /// <summary>
+        /// The Web rtc protocol
+        /// </summary>
+        [JsonPropertyName("sdp")]
+        public string Sdp { get; set; }
+    }
+
+    public class WebSocketServerCandidateMessage : WebSocketClientMessage
+    {
+        /// <summary>
+        /// If present, this is the value of the "a=mid" attribute of the candidate's
+        /// </summary>
+        [JsonPropertyName("sdpMid")]
+        public string SdpMid { get; set; }
+        /// <summary>
+        /// This indicates the index (starting at zero) of m= section this candidate is associated with. Needed when an endpoint doesn't support MIDs.
+        /// </summary>
+        [JsonPropertyName("sdpMLineIndex")]
+        public int SdpMlineIndex { get; set; }
+        /// <summary>
+        /// The Web rtc protocol
+        /// </summary>
+        [JsonPropertyName("candidate")]
+        public string Candidate { get; set; }
+    }
+}

+ 1 - 1
VRTC/VRTC.Web/PeerConnectionClient.js

@@ -279,7 +279,7 @@ PeerConnectionClient.prototype.addIceCandidate = function (candidate, successCal
         
         var c = new RTCIceCandidate({
             sdpMLineIndex: candidate.sdpMLineIndex,
-            candidate: candidate.sdp
+            candidate: candidate.candidate
         });
         this.remoteIce.push(c);
 

+ 4 - 4
VRTC/VRTC.Web/multi-rtc-demo.js

@@ -90,7 +90,7 @@ function startStream(clientId) {
         var obj = JSON.stringify({
             "command": "offer",
             "sdp": desc.sdp,
-            "roomId": roomId,
+            "roomId": parseInt(roomId),
             "clientId": clientId
         });
         send(obj);
@@ -151,7 +151,7 @@ function connect() {
                         var obj = JSON.stringify({
                             "command": "OnSuccessAnswer",
                             "sdp": desc.sdp,
-                            "roomId": roomId,
+                            "roomId": parseInt(roomId),
                             "clientId": clientId
                         });
                         send(obj);
@@ -200,7 +200,7 @@ function connect() {
             var userId = document.getElementById("userId").value;
             var obj = JSON.stringify({
                 "command": "Join",
-                "roomId": roomId,
+                "roomId": parseInt(roomId),
                 "clientId": userId
             });
             send(obj);
@@ -304,7 +304,7 @@ function getPeerConnection(clientId) {
                 "sdpMid": candidate.sdpMid,
                 "sdpMLineIndex": candidate.sdpMLineIndex,
                 "candidate": candidate.candidate,
-                "roomId": roomId,
+                "roomId": parseInt(roomId),
                 "clientId": connection.clientId
             });
             send(obj);

+ 3 - 2
VRTC/VRTC.WpfClient/VRTCClient.cs

@@ -126,8 +126,9 @@ namespace VRTC.WpfClient
 
                 case onicecandidate:
                     var sdpMLineIndex = (int)msgJson["sdpMLineIndex"];
-                    var sdpMid = msgJson["sdpMid"].ToString();                    
-                    _peerConnectionManager.AddIceCandidate(clientId, sdpMid, sdpMLineIndex, sdp);            
+                    var sdpMid = msgJson["sdpMid"].ToString();       
+                    var candidate = msgJson["candidate"].ToString(); 
+                    _peerConnectionManager.AddIceCandidate(clientId, sdpMid, sdpMLineIndex, candidate);            
                 break;
             }
     

+ 16 - 2
VRTC/VRTC.sln

@@ -18,9 +18,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VRTC.WpfClient", "VRTC.WpfC
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebRtc.NET", "WebRtc.NET\WebRtc.NET.vcxproj", "{A07E6CB4-0132-4EB1-9A38-C8C057884DC2}"
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RtcUtil.x64", "RtcUtil.x64\RtcUtil.x64.vcxproj", "{7517CD46-4A5E-4A97-894E-6C6991517B96}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RtcUtil.Native.x64", "RtcUtil.x64\RtcUtil.x64.vcxproj", "{7517CD46-4A5E-4A97-894E-6C6991517B96}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RtcUtil", "RtcUtil\RtcUtil.csproj", "{A8BF94B2-26F0-4987-8DDC-F94A14FC4742}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RtcUtil", "RtcUtil\RtcUtil.csproj", "{A8BF94B2-26F0-4987-8DDC-F94A14FC4742}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VRTC.Common", "VRTC.Common\VRTC.Common.csproj", "{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -92,6 +94,18 @@ Global
 		{A8BF94B2-26F0-4987-8DDC-F94A14FC4742}.Release|x64.Build.0 = Release|Any CPU
 		{A8BF94B2-26F0-4987-8DDC-F94A14FC4742}.Release|x86.ActiveCfg = Release|Any CPU
 		{A8BF94B2-26F0-4987-8DDC-F94A14FC4742}.Release|x86.Build.0 = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|x64.Build.0 = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Debug|x86.Build.0 = Debug|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|x64.ActiveCfg = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|x64.Build.0 = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|x86.ActiveCfg = Release|Any CPU
+		{79F436BF-EDA1-4B3C-A52D-DE605F8280DD}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 2
VRTC/VRTC/Program.cs

@@ -1,7 +1,6 @@
 // See https://aka.ms/new-console-template for more information
 using System.Diagnostics;
 using VRTC;
-using WebRtc.NET;
 
 Console.WriteLine("Hello, World!");
 try 
@@ -11,7 +10,7 @@ try
     Task.Factory.StartNew(delegate ()
     {
         //return;
-        using (var mc = new ManagedConductor())
+         //using (var mc = new ManagedConductor())
         {
             var text = "192.168.6.175";//TODO should from settings
             //var ok = mc.RunStunServer("192.168.6.175:3478");

+ 1 - 7
VRTC/VRTC/VRTC.csproj

@@ -10,16 +10,10 @@
 
   <ItemGroup>
     <PackageReference Include="Fleck" Version="1.2.0" />
-    <PackageReference Include="LitJson" Version="0.18.0" />
   </ItemGroup>
 
   <ItemGroup>
-    <Reference Include="WebRtc.NET">
-      <HintPath>..\..\..\..\2023\WebRtc.NET-master\WebRtc.NET\Debug_x64\WebRtc.NET.dll</HintPath>
-    </Reference>
-    <Reference Include="WebRtc.NET.Utils">
-      <HintPath>..\..\..\..\2023\WebRtc.NET-master\WebRtc.NET\Debug_x64\WebRtc.NET.Utils.dll</HintPath>
-    </Reference>
+    <ProjectReference Include="..\VRTC.Common\VRTC.Common.csproj" />
   </ItemGroup>
 
 </Project>

+ 1 - 28
VRTC/VRTC/WebRtcRoom.cs

@@ -1,8 +1,5 @@
 using Fleck;
-using LitJson;
 using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Diagnostics;
 using System.Text.Json;
 
 namespace VRTC
@@ -33,31 +30,7 @@ namespace VRTC
             Id = id;
             IntiatorId = intiatorId;
         }
-
-        /// <summary>
-        /// Register client info to room
-        /// </summary>
-        /// <param name="clientId"></param>
-        /// <param name="webSocketConnection"></param>
-        public void Register(string clientId, IWebSocketConnection webSocketConnection, string sdp)
-        {
-            var client = _clients.AddOrUpdate(clientId, (id) => {
-                return new WebRtcClient(id, webSocketConnection);
-            }, (id, exist) => {
-                exist.WebSocketConnection = webSocketConnection;
-                return exist;
-            });
-
-            JsonData jsonData = new JsonData();
-            jsonData["command"] = "OnOffer";
-            jsonData["clientId"] = client.Id;
-            jsonData["sdp"] = sdp;
-            if (_clients.Count > 1)
-            {
-                BroadcastToOthers(clientId, jsonData.ToJson());
-            }
-        }
-
+       
         internal void Clear()
         {
             var clients = _clients.Values.ToList();

+ 53 - 41
VRTC/VRTC/WebRtcRoomManager.cs

@@ -1,8 +1,6 @@
-
-using System;
-using Fleck;
+using Fleck;
 using System.Collections.Concurrent;
-using LitJson;
+using System.Text.Json;
 
 namespace VRTC
 {
@@ -47,7 +45,7 @@ namespace VRTC
         /// <returns>TODO reactor later</returns>
         /// <exception cref="NotSupportedException">should be larger than 0</exception>
         /// <exception cref="ArgumentNullException"></exception>
-        string Join(uint roomId, string clientId, IWebSocketConnection webSocketConnection);
+        void Join(uint roomId, string clientId, IWebSocketConnection webSocketConnection);
         
         /// <summary>
         /// Exit from room when socket disconnected
@@ -94,13 +92,20 @@ namespace VRTC
         {           
             if(_connectionClients.ContainsKey(clientConnectionId))
             {
-                JsonData data = new JsonData();
-                data["command"] = "OnSuccessAnswer";
-                data["sdp"] = sdp;
                 var clientId = _connectionClients[clientConnectionId];
-                data["clientId"] = clientId;
-                ForwardToOther(roomId, data.ToJson(), targetClientId);
-            }            
+                string msg = CreateSdpMessage("OnSuccessAnswer", clientId, sdp);
+                ForwardToOther(roomId, msg, targetClientId);
+            }
+        }
+
+        private string CreateSdpMessage(string command, string clientId, string sdp)
+        {
+            var data = new WebSocketServerSdpMessage();
+            data.Command = command;
+            data.Sdp = sdp;            
+            data.ClientId = clientId;
+            var msg = JsonSerializer.Serialize(data);
+            return msg;
         }
 
         /// <summary>
@@ -122,32 +127,41 @@ namespace VRTC
             }
 
             if (_connectionClients.ContainsKey(clientConnectionId))
-            {
-                JsonData jsonData = new JsonData();
-                jsonData["command"] = "OnOffer";
+            {               
                 var clientId = _connectionClients[clientConnectionId];
-                jsonData["clientId"] = clientId;
-                jsonData["sdp"] = sdp;
-                ForwardToOther(roomId, jsonData.ToJson(), targetClientId);
+                string msg = CreateSdpMessage("OnOffer", clientId, sdp);
+                ForwardToOther(roomId, msg, targetClientId);
             }                       
         }
 
         public void ForwardCandidate(uint roomId, Guid clientConnectionId, string candidate, string sdpMid, int sdpMLineIndex, string targetClientId)
         {
             if (_connectionClients.ContainsKey(clientConnectionId))
-            {
-                JsonData data = new JsonData();
-                data["command"] = "OnIceCandidate";
-                data["sdpMid"] = sdpMid;
-                data["sdpMLineIndex"] = sdpMLineIndex;
-                data["sdp"] = candidate;
+            {                                
                 var clientId = _connectionClients[clientConnectionId];
-                data["clientId"] = clientId;
-                ForwardToOther(roomId, data.ToJson(), targetClientId);
+                var data = new WebSocketServerCandidateMessage();
+                data.Command = "OnIceCandidate";
+                data.SdpMid = sdpMid;
+                data.SdpMlineIndex = sdpMLineIndex;
+                data.Candidate = candidate;
+                data.ClientId = clientId;
+
+                var msg = JsonSerializer.Serialize(data);
+                ForwardToOther(roomId, msg, targetClientId);
             }
             
         }
 
+        private string CreateMessage(string command, string clientId, JoinState state)
+        {
+            var data = new WebSocketServerMessage();
+            data.Command = command;
+            data.State = state;
+            data.ClientId = clientId;
+            var msg = JsonSerializer.Serialize(data);
+            return msg;
+        }
+
         /// <summary>
         ///Join a room, create a new room of not exist
         /// </summary>
@@ -156,7 +170,7 @@ namespace VRTC
         /// <returns>TODO reactor later</returns>
         /// <exception cref="NotSupportedException">should be larger than 0</exception>
         /// <exception cref="ArgumentNullException"></exception>
-        public string Join(uint roomId, string clientId, IWebSocketConnection webSocketConnection)
+        public void Join(uint roomId, string clientId, IWebSocketConnection webSocketConnection)
         {
             if (roomId <= 0)
             {
@@ -166,34 +180,32 @@ namespace VRTC
             {
                 throw new ArgumentNullException($"Client ID is empty!");
             }
-            JsonData jsonData = new JsonData();
-            jsonData["command"] = "JoinResult";
+            
+            var command = "JoinResult";
                        
             var room = _rooms.AddOrUpdate(roomId, (id) => {
                 var room = new WebRtcRoom(id, clientId);
                 room.Closed += OnRoomClosed;
                 room.Join(clientId, webSocketConnection);
-                jsonData["state"] = "RoomOpened";
-                webSocketConnection.Send(jsonData.ToJson());
+                
+                var jsonData = CreateMessage(command, clientId, JoinState.RoomOpened);
+                webSocketConnection.Send(jsonData);
                 return room;
             }, (id, exist) => {                       
-                jsonData["state"] = "RoomJoined";                
+                        
                 exist.Join(clientId, webSocketConnection);
-                webSocketConnection.Send(jsonData.ToJson());
+                var jsonData = CreateMessage(command, clientId, JoinState.RoomJoined);
+                webSocketConnection.Send(jsonData);
 
-                JsonData jsonDataForward = new JsonData();
-                jsonDataForward["command"] = "OnJoin";
-                jsonDataForward["clientId"] = clientId;
-
-                exist.BroadcastToOthers(clientId, jsonDataForward.ToJson());
+                var jsonDataForward = CreateMessage("OnJoin", clientId, JoinState.RoomJoined);
+                
+                exist.BroadcastToOthers(clientId, jsonDataForward);
 
                 return exist;
             });
 
-            Console.WriteLine($"{clientId} {jsonData["command"]} {roomId}");
-            _connectionClients[webSocketConnection.ConnectionInfo.Id] = clientId;
-
-            return jsonData.ToJson();
+            
+            _connectionClients[webSocketConnection.ConnectionInfo.Id] = clientId;            
         }
 
         private void OnRoomClosed(object? sender, EventArgs e)

+ 59 - 53
VRTC/VRTC/WebRtcServer.cs

@@ -8,8 +8,6 @@ namespace VRTC
     using System.Threading;
     using System.Threading.Tasks;
     using Fleck;
-    using LitJson;
-    using WebRtc.NET;
 
     partial class WebRtcServer : IDisposable
     {
@@ -143,34 +141,42 @@ namespace VRTC
         private async void HandleReceiveAsync(IWebSocketConnection context, string msg)
         {           
             try
-            {                               
-                //WebSocketServerMessage message = JsonSerializer.Deserialize<WebSocketServerMessage>(msg);
-                //string command = message.Command;
-                JsonData jsonMsg = JsonMapper.ToObject(msg);
-                var command = jsonMsg["command"].ToString();
-               
-                switch (command)
+            {                                               
+                var msgCmd = JsonSerializer.Deserialize<WebSocketClientMessage>(msg);
+                if (msgCmd != null)
                 {
-                    case "Exit":
-                        await HandleExitAsync(context, jsonMsg);
-                        break;
-                    case "Join":
-                        await HandleJoinAsync(context, jsonMsg);
-                        break;
-                    case offer:
-                        await HandleOfferAsync(context, jsonMsg);
-                        break;
-                    case "OnSuccessAnswer":
-                        {
-                            HandleOnSuccessAnswer(context, jsonMsg);
-                        }
-                        break;
-
-                    case onicecandidate:
-                        await HandleCandidate(context, jsonMsg);
-                        break;
-                }
-                
+                    var command = msgCmd.Command;
+                    switch (command)
+                    {
+                        case "Exit":
+                            await HandleExitAsync(context, msgCmd);
+                            break;
+                        case "Join":
+                            await HandleJoinAsync(context, msgCmd);
+                            break;
+                        case offer:
+                            var offerMessage = JsonSerializer.Deserialize<WebSocketClientSdpMessage>(msg);
+                            if (offerMessage != null)
+                            {
+                                await HandleOfferAsync(context, offerMessage);
+                            }
+                            break;
+                        case "OnSuccessAnswer":
+                            var answerMessage = JsonSerializer.Deserialize<WebSocketClientSdpMessage>(msg);
+                            if (answerMessage != null) 
+                            { 
+                                await HandleOnSuccessAnswer(context, answerMessage);
+                            }
+                            break;
+                        case onicecandidate:
+                            var msgCandidate = JsonSerializer.Deserialize<WebSocketClientCandidateMessage>(msg);
+                            if (msgCandidate != null)
+                            {
+                                await HandleCandidate(context, msgCandidate);                                
+                            }
+                            break;
+                    }
+                }                         
             }
             catch(Exception e)
             {
@@ -178,50 +184,50 @@ namespace VRTC
             }
         }
 
-        private async Task HandleExitAsync(IWebSocketConnection context, JsonData jsonMsg)
+        private async Task HandleExitAsync(IWebSocketConnection context, WebSocketClientMessage clientMessage)
         {
-            var roomId = uint.Parse(jsonMsg["roomId"].ToString());
-            var clientId = jsonMsg["clientId"].ToString();
+            var roomId = clientMessage.RoomId;
+            var clientId = clientMessage.ClientId;
         }
 
-        private async Task HandleJoinAsync(IWebSocketConnection context, JsonData jsonMsg)
+        private async Task HandleJoinAsync(IWebSocketConnection context, WebSocketClientMessage clientMessage)
         {
-            var roomId = uint.Parse(jsonMsg["roomId"].ToString());
-            var clientId = jsonMsg["clientId"].ToString();
+            var roomId = clientMessage.RoomId;
+            var clientId = clientMessage.ClientId;
             _roomManager.Join(roomId, clientId, context);                       
         }
 
-        private void HandleOnSuccessAnswer(IWebSocketConnection context, JsonData jsonMsg)
+        private async Task HandleOnSuccessAnswer(IWebSocketConnection context, WebSocketClientSdpMessage clientMessage)
         {
-            var roomId = uint.Parse(jsonMsg["roomId"].ToString());               
-            var sdp = jsonMsg["sdp"].ToString();
-            var targetClientId = jsonMsg["clientId"].ToString();
-
-            _roomManager.ForwardAnswer(roomId, context.ConnectionInfo.Id, sdp, targetClientId);
+            var roomId = clientMessage.RoomId;
+            var clientId = clientMessage.ClientId;
+            var sdp = clientMessage.Sdp;
+            
+            _roomManager.ForwardAnswer(roomId, context.ConnectionInfo.Id, sdp, clientId);
         }
 
-        private async Task HandleCandidate(IWebSocketConnection context, JsonData jsonMsg)
+        private async Task HandleCandidate(IWebSocketConnection context, WebSocketClientCandidateMessage clientMessage)
         {
-            var roomId = uint.Parse(jsonMsg["roomId"].ToString());            
-            var sdpMLineIndex = (int)jsonMsg["sdpMLineIndex"];
-            var sdpMid = jsonMsg["sdpMid"].ToString();
-            var candidate = jsonMsg["candidate"].ToString();
-            var targetClientId = jsonMsg["clientId"].ToString();
+            var roomId = clientMessage.RoomId;
+            var clientId = clientMessage.ClientId;
+            var sdpMLineIndex = clientMessage.SdpMlineIndex;
+            var sdpMid = clientMessage.SdpMid;
+            var candidate = clientMessage.Candidate;            
 
-            _roomManager.ForwardCandidate(roomId, context.ConnectionInfo.Id, candidate, sdpMid, sdpMLineIndex, targetClientId);
+            _roomManager.ForwardCandidate(roomId, context.ConnectionInfo.Id, candidate, sdpMid, sdpMLineIndex, clientId);
         }
 
-        private async Task HandleOfferAsync(IWebSocketConnection context, JsonData jsonMsg)
+        private async Task HandleOfferAsync(IWebSocketConnection context, WebSocketClientSdpMessage clientMessage)
         {
-            var roomId = uint.Parse(jsonMsg["roomId"].ToString());
-            var targetClientId = jsonMsg["clientId"].ToString();            
-            var sdp = jsonMsg["sdp"].ToString();
+            var roomId = clientMessage.RoomId;
+            var clientId = clientMessage.ClientId;
+            var sdp = clientMessage.Sdp;
             var index = sdp.IndexOf("a=extmap-allow-mixed");
             if (index != -1)
             {
                 sdp = sdp.Remove(index, 22);
             }
-            _roomManager.ForwardOffer(roomId, context.ConnectionInfo.Id, sdp, targetClientId);            
+            _roomManager.ForwardOffer(roomId, context.ConnectionInfo.Id, sdp, clientId);            
         }
 
         public void Dispose()

BIN
VRTC/VRTC/WebRtcSession.cs


BIN
VRTC/VRTC/WebSocketServerMessage.cs