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);
        }
        public void DidCreateSessionDescription(RTCPeerConnection peerConnection, RTCSessionDescription sdp, NSError error)
        {
            DispatchForPeerConnectionAsync(() =>
            {
                if (error != null)
                {
                    Console.WriteLine("Failed to create session description. Error: {0}", error);
                    Disconnect();

                    Console.WriteLine("Failed to create session description. Error:{0}", error);
                    Delegate?.DidError(new ARDAppException("Failed to create session description.", kARDAppClientErrorDomain, ARDAppErrorCode.CreateSDP));
                    return;
                }

                _peerConnection.SetLocalDescription(sdp, (err) =>
                {
                    DidSetSessionDescriptionWithError(peerConnection, err);
                });

                var message = new ARDSessionDescriptionMessage(sdp);

                SendSignalingMessage(message);
                SetMaxBitrateForPeerConnectionVideoSender();
            });
        }
        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;
            }
        }
Esempio n. 4
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);
        }
Esempio 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);
        }
        public void DidCreateSessionDescription(RTCPeerConnection peerConnection, RTCSessionDescription sdp, NSError error)
        {
            // dispatch_async(dispatch_get_main_queue(),
            if (error != null)
            {
                System.Diagnostics.Debug.WriteLine($"Failed to create session description. Error: {error}");
                Disconnect();
                //    NSDictionary *userInfo = @{
                //      NSLocalizedDescriptionKey: @"Failed to create session description.",
                //    };
                //    NSError *sdpError =
                //        [[NSError alloc] initWithDomain:kARDAppClientErrorDomain
                //                                   code:kARDAppClientErrorCreateSDP
                //                               userInfo:userInfo];
                _delegate.DidError(this, error);
                return;
            }
            _peerConnection.SetLocalDescriptionWithDelegate(this, sdp);
            ARDSessionDescriptionMessage message = new ARDSessionDescriptionMessage(sdp);

            SendSignalingMessage(message).Wait();
        }