public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();
            var type = values["type"];

            if (type == "candidate")
            {
                RTCICECandidate candidate = new RTCICECandidate(values["id"], nint.Parse(values["label"]), values["candidate"]);
                message = new ARDICECandidateMessage(candidate);
            }
            else if (type == "offer" || type == "answer")
            {
                RTCSessionDescription description = new RTCSessionDescription(type, values["sdp"]);
                message = new ARDSessionDescriptionMessage(description);
            }
            else if (type == "bye")
            {
                message = new ARDByeMessage();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"Unexpected type: {type}");
            }
            return(message);
        }
Exemplo n.º 2
0
        void ProcessSignalingMessage(ARDSignalingMessage message)
        {
            switch (message.Type)
            {
            case ARDSignalingMessageType.Offer:
            case ARDSignalingMessageType.Answer:
                ARDSessionDescriptionMessage sdpMessage = message as ARDSessionDescriptionMessage;
                _peerConnection.SetRemoteDescriptionWithDelegate(this, sdpMessage.Description);
                break;

            case ARDSignalingMessageType.Candidate:
                ARDICECandidateMessage candidateMessage = message as ARDICECandidateMessage;
                _peerConnection.AddICECandidate(candidateMessage.Candidate);
                break;

            case ARDSignalingMessageType.Bye:
                // Other client disconnected.
                // TODO(tkchin): support waiting in room for next client. For now just
                Disconnect();
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();
            var type = values["type"];

            switch (type)
            {
            case "candidate":
                nint.TryParse(values["label"], out nint label);
                RTCICECandidate candidate = new RTCICECandidate(values["id"], label, values["candidate"]);
                message = new ARDICECandidateMessage(candidate);
                break;

            case "offer":
            case "answer":
                RTCSessionDescription description = new RTCSessionDescription(type, values["sdp"]);
                message = new ARDSessionDescriptionMessage(description);
                break;

            case "bye":
                message = new ARDByeMessage();
                break;

            default:
                System.Diagnostics.Debug.WriteLine($"Unexpected type: {type}");
                break;
            }

            return(message);
        }
 public void DidGenerateIceCandidate(RTCPeerConnection peerConnection, RTCIceCandidate candidate)
 {
     DispatchForPeerConnectionAsync(() =>
     {
         var message = new ARDICECandidateMessage(candidate);
         SendSignalingMessage(message);
     });
 }
Exemplo n.º 5
0
        public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();

            if (values.ContainsKey("type"))
            {
                var type = values["type"] ?? "";
                switch (type)
                {
                case "candidate":
                    int.TryParse(values["label"], out int label);
                    RTCIceCandidate candidate = new RTCIceCandidate(values["id"], label, values["candidate"]);
                    message = new ARDICECandidateMessage(candidate);
                    break;

                case "offer":
                    RTCSessionDescription description = new RTCSessionDescription(RTCSdpType.Offer, values["sdp"]);
                    message = new ARDSessionDescriptionMessage(description);
                    break;

                case "answer":
                    description = new RTCSessionDescription(RTCSdpType.Answer, values["sdp"]);
                    message     = new ARDSessionDescriptionMessage(description);
                    break;

                case "bye":
                    message = new ARDByeMessage();
                    break;

                default:
                    System.Diagnostics.Debug.WriteLine($"ARDSignalingMessage unexpected type: {type}");
                    break;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"ARDSignalingMessage invalid json: {json}");
            }

            return(message);
        }
Exemplo n.º 6
0
        public void PeerConnection(RTCPeerConnection peerConnection, RTCICECandidate candidate)
        {
            ARDICECandidateMessage message = new ARDICECandidateMessage(candidate);

            SendSignalingMessage(message).Wait();
        }