Exemple #1
0
        public void SendLocalIceCandidateRemovals(IceCandidate[] candidates)
        {
            _executor.Execute(() =>
            {
                var json = ARDSignalingMessage.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 = ARDSignalingMessage.MessageFromJSONString(message);

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

            case ARDSignalingMessageType.CandidateRemoval:
                var candidates = (ARDICECandidateRemovalMessage)msg;
                _signalingEvents.OnRemoteIceCandidatesRemoved(candidates.Candidates);
                break;

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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 CandidateType:
                    int.TryParse(values["label"], out int label);
                    var candidate = new IceCandidate(values["candidate"], values["id"], label);
                    message = new ARDICECandidateMessage(candidate);
                    break;

                case CandidateRemovalType:

                    break;

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

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

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

                case ByeType:
                    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);
        }
Exemple #4
0
        public void SendAnswerSdp(SessionDescription sdp)
        {
            _executor.Execute(() =>
            {
                if (_connectionParameters.IsLoopback)
                {
                    _logger.Error(TAG, "Sending answer in loopback mode.");
                    return;
                }

                var json = ARDSignalingMessage.CreateJson(sdp);


                _wsClient.Send(json);
            });
        }
Exemple #5
0
        public void SendLocalIceCandidate(IceCandidate candidate)
        {
            _executor.Execute(() =>
            {
                var json = ARDSignalingMessage.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 = ARDSignalingMessage.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(ARDSignalingMessage.CreateByeJson());
     SendWSSMessage(MethodType.Delete, "");
 }