Beispiel #1
0
    private void Start()
    {
        callButton.interactable   = true;
        hangupButton.interactable = false;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(pc2, candidate); };
        onDataChannel            = channel =>
        {
            remoteDataChannel           = channel;
            remoteDataChannel.OnMessage = onDataChannelMessage;
        };
        onDataChannelMessage = bytes => { textReceive.text = System.Text.Encoding.UTF8.GetString(bytes); };
        onDataChannelOpen    = () =>
        {
            sendButton.interactable   = true;
            hangupButton.interactable = true;
        };
        onDataChannelClose = () =>
        {
            sendButton.interactable   = false;
            hangupButton.interactable = false;
        };
    }
Beispiel #2
0
    private void Start()
    {
        callButton.interactable = true;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(pc1, candidate); };

        onDataChannel = channel =>
        {
            remoteDataChannel           = channel;
            remoteDataChannel.OnMessage = onDataChannelMessage;
        };
        onDataChannelOpen  = () => { };
        onDataChannelClose = () => { };

        StartCoroutine(LoopGetStats());
    }
Beispiel #3
0
    private void Start()
    {
        connectButton.interactable = true;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(pc1, candidate); };
        onDataChannel            = channel =>
        {
            remoteDataChannel           = channel;
            remoteDataChannel.OnMessage = onDataChannelMessage;
        };
        onDataChannelMessage = bytes => {
            Decode(bytes);
        };
        onDataChannelOpen  = () => { voiceButton.interactable = true; };
        onDataChannelClose = () => { voiceButton.interactable = false; };
    }
    private async void Start()
    {
        websocket = new WebSocket("ws://localhost:8000/socket");

        Debug.Log("GetSelectedSdpSemantics");
        var configuration = GetSelectedSdpSemantics();

        pc2 = new RTCPeerConnection(ref configuration);
        Debug.Log("Created remote peer connection object pc2");

        pc2.OnIceCandidate        = pc2OnIceCandidate;
        pc2.OnIceConnectionChange = pc2OnIceConnectionChange;
        pc2.OnDataChannel         = onDataChannel;

        RTCDataChannelInit conf = new RTCDataChannelInit();

        dataChannel        = pc2.CreateDataChannel("data", conf);
        dataChannel.OnOpen = onDataChannelOpen;

        //dataChannel.Send("3TEST");

        pc2OnIceConnectionChange = state => { OnIceConnectionChange(pc2, state); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(pc2, candidate); };

        textReceive.text += "0TEST";

        onDataChannel = channel =>
        {
            Debug.Log("Data Channel works!");
            textReceive.text     += "2TEST";
            dataChannel           = channel;
            dataChannel.OnMessage = onDataChannelMessage;
        };
        onDataChannelMessage = bytes =>
        {
            textReceive.text = System.Text.Encoding.UTF8.GetString(bytes);

            //         var epoint = new Uint8Array(event.data, 92);

            //   if (epoint.byteLength > 93) {

            //var dpoint = MessagePack.decode(epoint);
            //         console.log("Decoded pointarray:", dpoint);

            //var pointbuff = new Int8Array(dpoint);
            //         colate(pointbuff);
        };
        onDataChannelOpen  = () => { textReceive.text += "1TEST"; };
        onDataChannelClose = () => { sendButton.interactable = false; };

        websocket.OnOpen += () =>
        {
            Debug.Log("Connection open!");
        };

        websocket.OnError += (e) =>
        {
            Debug.Log("Error! " + e);
        };

        websocket.OnClose += (e) =>
        {
            Debug.Log("Connection closed!");
        };

        websocket.OnMessage += (bytes) =>
        {
            Debug.Log("Message: " + System.Text.Encoding.UTF8.GetString(bytes));

            Message message = JsonConvert.DeserializeObject <Message>(System.Text.Encoding.UTF8.GetString(bytes));
            Debug.Log("New message: " + message.type);

            switch (message.type)
            {
            case "offer":

                var remoteDesc = new RTCSessionDescription();
                remoteDesc.type = 0;
                remoteDesc.sdp  = message.sdp;
                pc2.SetRemoteDescription(ref remoteDesc);

                var answer = pc2.CreateAnswer(ref AnswerOptions);
                Debug.Log("Answer: " + answer.Desc.sdp);
                Debug.Log("Answer Desc: " + answer.Desc.type);

                var localDesc = new RTCSessionDescription();
                localDesc.type = answer.Desc.type;
                localDesc.sdp  = message.sdp;
                pc2.SetLocalDescription(ref localDesc);

                Message newMessage = new Message();

                newMessage.type = "answer";
                newMessage.sdp  = answer.Desc.sdp;

                string output = JsonConvert.SerializeObject(newMessage);

                websocket.SendText(output);

                break;

            case "candidate":
                RTCIceCandidateInit candidateMessage = new RTCIceCandidateInit();
                candidateMessage.candidate     = message.sdp;
                candidateMessage.sdpMLineIndex = 0;
                candidateMessage.sdpMid        = "";

                RTCIceCandidate candidate = new RTCIceCandidate(candidateMessage);

                pc2.AddIceCandidate(candidate);
                break;

            default:
                Debug.Log("P2: We got something from the signaling server but we don't know what it is!");
                Debug.Log("Take a look for yourself: " + message.type);
                Debug.Log("Take a look for yourself: " + message.sdp);
                break;
            }
        };

        await websocket.Connect();
    }
Beispiel #5
0
 public static extern void DataChannelRegisterOnClose(IntPtr ptr, DelegateOnClose callback);