private void ProcessMessage(ReceivedMessage message)
        {
            switch (message.Type)
            {
            case "ping":
                SendPongMessage();
                break;

            case "accept":
                if (message.IsExistClient)
                {
                    PeerConnection.StartConnection();
                }
                break;

            case "offer":
                PeerConnection.HandleConnectionMessageAsync(message.ToWebRTCMessage()).ContinueWith(_ =>
                {
                    PeerConnection.Peer.CreateAnswer();
                }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);
                break;

            case "answer":
                _ = PeerConnection.HandleConnectionMessageAsync(message.ToWebRTCMessage());
                break;

            case "candidate":
                PeerConnection.Peer.AddIceCandidate(message.ToIceCandidate());
                break;
            }
        }
Beispiel #2
0
    private async void Peer2_LocalSdpReadytoSend(Microsoft.MixedReality.WebRTC.SdpMessage message)
    {
        await Peer1.HandleConnectionMessageAsync(message);

        _remoteApplied1.Set();
        if (message.Type == Microsoft.MixedReality.WebRTC.SdpMessageType.Offer)
        {
            Peer1.Peer.CreateAnswer();
        }
    }
Beispiel #3
0
    private async void Peer2_LocalSdpReadytoSend(string type, string sdp)
    {
        await Peer1.HandleConnectionMessageAsync(type, sdp);

        _remoteApplied1.Set();
        if (type == "offer")
        {
            Peer1.Peer.CreateAnswer();
        }
    }
Beispiel #4
0
 private void Peer1_LocalSdpReadytoSend(Microsoft.MixedReality.WebRTC.SdpMessage message)
 {
     InvokeOnAppThread(async() =>
     {
         await Peer2.HandleConnectionMessageAsync(message);
         _remoteApplied2.Set();
         if (message.Type == Microsoft.MixedReality.WebRTC.SdpMessageType.Offer)
         {
             Peer2.Peer.CreateAnswer();
         }
     });
 }
Beispiel #5
0
    private void OnMessage(SocketIOEvent ev)
    {
        string from = GetString(ev.data, "from");

        remotePeerId = from;
        string type = GetString(ev.data, "type");
        //Debug.Log($"socket received {type} from {from}");
        JSONObject payload = null;

        if (type != "init")
        {
            payload = ev.data["payload"];
        }

        Debug.Log(ev.data);
        switch (type)
        {
        case "init":
            _ = PeerConnection.StartConnection();
            break;

        case "offer":
            var sdpOffer = new SdpMessage {
                Type = SdpMessageType.Offer, Content = GetString(payload, "sdp").Replace("\\r\\n", "\r\n")
            };
            PeerConnection.HandleConnectionMessageAsync(sdpOffer).ContinueWith(_ =>
            {
                _nativePeer.CreateAnswer();
            }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously);
            break;

        case "answer":
            var sdpAnswer = new SdpMessage {
                Type = SdpMessageType.Answer, Content = GetString(payload, "sdp").Replace("\\r\\n", "\r\n")
            };
            _ = PeerConnection.HandleConnectionMessageAsync(sdpAnswer);
            break;

        case "candidate":
            _nativePeer.AddIceCandidate(new IceCandidate()
            {
                SdpMid        = GetString(payload, "id"),
                SdpMlineIndex = GetInt(payload, "label"),
                Content       = GetString(payload, "candidate")
            });
            break;
        }
    }