Exemple #1
0
        public void SendLocalIceCandidateRemovals(IceCandidate[] candidates)
        {
            _executor.Execute(() =>
            {
                var json = SignalingMessage.CreateJson(candidates);

                if (_initiator)
                {
                    if (State != ConnectionState.Connected)
                    {
                        ReportError("Sending ICE candidate removals in non connected state.");
                        return;
                    }

                    SendPostMessage(MessageType.Message, _messageUrl, json);
                    if (_connectionParameters.IsLoopback)
                    {
                        _signalingEvents.OnRemoteIceCandidatesRemoved(candidates);
                    }
                }
                else
                {
                    _wsClient.Send(json);
                }
            });
        }
Exemple #2
0
        public void OnWebSocketMessage(string message)
        {
            if (_wsClient.State != WebSocketConnectionState.Registered)
            {
                _logger.Error(TAG, "Got WebSocket message in non registered state.");
                return;
            }

            var msg = SignalingMessage.MessageFromJSONString(message);

            switch (msg.Type)
            {
            case SignalingMessageType.Candidate:
                var candidate = (ICECandidateMessage)msg;
                _signalingEvents.OnRemoteIceCandidate(candidate.Candidate);
                break;

            case SignalingMessageType.CandidateRemoval:
                var candidates = (ICECandidateRemovalMessage)msg;
                _signalingEvents.OnRemoteIceCandidatesRemoved(candidates.Candidates);
                break;

            case SignalingMessageType.Offer:
                if (!_initiator)
                {
                    var sdp = (SessionDescriptionMessage)msg;
                    _signalingEvents.OnRemoteDescription(sdp.Description);
                }
                else
                {
                    ReportError($"Received offer for call receiver : {message}");
                }
                break;

            case SignalingMessageType.Answer:
                if (_initiator)
                {
                    var sdp = (SessionDescriptionMessage)msg;
                    _signalingEvents.OnRemoteDescription(sdp.Description);
                }
                else
                {
                    ReportError($"Received answer for call initiator: {message}");
                }
                break;

            case SignalingMessageType.Bye:
                _signalingEvents.OnChannelClose();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static SignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            SignalingMessage message = new SignalingMessage();

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

                case CandidateRemovalType:

                    break;

                case OfferType:
                    var description = new SessionDescription(SdpType.Offer, values["sdp"]);
                    message = new SessionDescriptionMessage(description);
                    break;

                case AnswerType:
                    description = new SessionDescription(SdpType.Answer, values["sdp"]);
                    message     = new SessionDescriptionMessage(description);
                    break;

                case PrAnswerType:
                    description = new SessionDescription(SdpType.PrAnswer, values["sdp"]);
                    message     = new SessionDescriptionMessage(description);
                    break;

                case ByeType:
                    message = new ByeMessage();
                    break;

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

            return(message);
        }
Exemple #4
0
        public void SendAnswerSdp(SessionDescription sdp)
        {
            _executor.Execute(() =>
            {
                if (_connectionParameters.IsLoopback)
                {
                    _logger.Error(TAG, "Sending answer in loopback mode.");
                    return;
                }

                var json = SignalingMessage.CreateJson(sdp);


                _wsClient.Send(json);
            });
        }
Exemple #5
0
        public void SendLocalIceCandidate(IceCandidate candidate)
        {
            _executor.Execute(() =>
            {
                var json = SignalingMessage.CreateJson(candidate);
                if (_initiator)
                {
                    if (State != ConnectionState.Connected)
                    {
                        ReportError("Sending ICE candidate in non connected state.");
                        return;
                    }

                    SendPostMessage(MessageType.Message, _messageUrl, json);
                }
                else
                {
                    _wsClient.Send(json);
                }
            });
        }
Exemple #6
0
        public void SendOfferSdp(SessionDescription sdp)
        {
            _executor.Execute(() =>
            {
                if (State != ConnectionState.Connected)
                {
                    ReportError("Sending offer SDP in non connected state.");
                    return;
                }

                var json = SignalingMessage.CreateJson(sdp);

                SendPostMessage(MessageType.Message, _messageUrl, json);

                if (_connectionParameters.IsLoopback)
                {
                    // In loopback mode rename this offer to answer and route it back.
                    var sdpAnswer = new SessionDescription(SdpType.Answer, sdp.Sdp);
                    _signalingEvents.OnRemoteDescription(sdpAnswer);
                }
            });
        }
 protected override void SendByeMessage()
 {
     Send(SignalingMessage.CreateByeJson());
     SendWSSMessage(MethodType.Delete, "");
 }