Esempio n. 1
0
        private void Start()
        {
            pc1Senders = new List <RTCRtpSender>();
            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); };
            pc2Ontrack = e =>
            {
                if (e.Track is VideoStreamTrack video)
                {
                    video.OnVideoReceived += tex =>
                    {
                        receiveImage.texture = tex;
                    };
                    receiveVideoStream = e.Streams.First();
                    receiveVideoStream.OnRemoveTrack = ev =>
                    {
                        receiveImage.texture = null;
                        ev.Track.Dispose();
                    };
                }

                if (e.Track is AudioStreamTrack audioTrack)
                {
                    receiveAudio.SetTrack(audioTrack);
                    receiveAudio.loop = true;
                    receiveAudio.Play();
                    receiveAudioStream = e.Streams.First();
                    receiveAudioStream.OnRemoveTrack = ev =>
                    {
                        receiveAudio.Stop();
                        receiveAudio.clip = null;
                        ev.Track.Dispose();
                    };
                }
            };
            pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
            StartCoroutine(WebRTC.Update());
        }
Esempio n. 2
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; };
    }
Esempio n. 3
0
    private void Start()
    {
        dropdown.interactable   = false;
        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());
    }
    private void Start()
    {
        videoStreamTrackList      = new List <VideoStreamTrack>();
        sendingSenderList         = new List <RTCRtpSender>();
        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); };
        pc2Ontrack = e =>
        {
            if (e.Track is VideoStreamTrack track && !track.IsDecoderInitialized)
            {
                receiveImages[videoIndex].texture = track.InitializeReceiver(width, height);
                videoIndex++;
            }
        };

        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
        pc2OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc2)); };
    }
Esempio n. 5
0
    private void Start()
    {
        trackInfos = new StringBuilder();
        pc1Senders = new List <RTCRtpSender>();
        pc2Senders = new List <RTCRtpSender>();
        callButton.interactable = true;

        pc1OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { OnIceConnectionChange(pc1, state); });
        pc2OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { OnIceConnectionChange(pc2, state); });
        pc1OnIceCandidate        = new DelegateOnIceCandidate(candidate => { OnIceCandidate(pc1, candidate); });
        pc2OnIceCandidate        = new DelegateOnIceCandidate(candidate => { OnIceCandidate(pc1, candidate); });
        pc2Ontrack             = new DelegateOnTrack(e => { OnTrack(pc2, e); });
        pc1OnNegotiationNeeded = new DelegateOnNegotiationNeeded(() => { StartCoroutine(Pc1OnNegotiationNeeded()); });
        if (!WebRTC.HWEncoderSupport)
        {
            addTracksButton.interactable = false;
            callButton.interactable      = false;
            infoText.text = "Current GPU doesn't support Nvidia Encoder";
        }
        else
        {
            infoText.text = "Current GPU supports Nvidia Encoder";
        }
    }
    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();
    }
Esempio n. 7
0
 public static extern void PeerConnectionRegisterIceConnectionChange(IntPtr ptr, DelegateOnIceConnectionChange callback);