Example #1
0
    private void Start()
    {
        pc1Senders = new List <RTCRtpSender>();
        callButton.interactable                  = true;
        hangUpButton.interactable                = false;
        bandwidthSelector.interactable           = false;
        scaleResolutionDownSelector.interactable = false;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
        pc2Ontrack = e =>
        {
            receiveStream.AddTrack(e.Track);
        };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };

        receiveStream.OnAddTrack = e =>
        {
            if (e.Track is VideoStreamTrack track)
            {
                track.OnVideoReceived += OnVideoReceived;
            }
        };
    }
Example #2
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;
        };
    }
        private void Start()
        {
            audioStreamTrackList      = new List <AudioStreamTrack>();
            sendingSenderList         = new List <RTCRtpSender>();
            callButton.interactable   = true;
            hangUpButton.interactable = false;
            dropdownAudioclip.options = sourceAudioClips.Select(clip => new Dropdown.OptionData(clip.name)).ToList();

            pc1OnIceCandidate = candidate => { OnIceCandidate(_pc1, candidate); };
            pc2OnIceCandidate = candidate => { OnIceCandidate(_pc2, candidate); };
            pc2Ontrack        = e =>
            {
                if (e.Track is AudioStreamTrack track)
                {
                    var outputAudioSource = receiveObjectList[audioIndex];
                    track.OnAudioReceived += clip =>
                    {
                        outputAudioSource.clip = clip;
                        outputAudioSource.loop = true;
                        outputAudioSource.Play();
                    };
                    audioIndex++;
                }
            };

            pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
            pc2OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc2)); };
        }
    private void Start()
    {
        pc1Senders = new List <RTCRtpSender>();
        callButton.interactable        = true;
        hangUpButton.interactable      = false;
        bandwidthSelector.interactable = false;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
        pc2Ontrack = e =>
        {
            Debug.LogWarning("Receiver OnTrack");
            receiveStream.AddTrack(e.Track);
        };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };

        receiveStream.OnAddTrack = e =>
        {
            Debug.LogWarning("receiveStream");

            if (e.Track is VideoStreamTrack track)
            {
                receiveImage.texture = track.InitializeReceiver(width, height);
                receiveImage.color   = Color.white;
            }
        };
    }
Example #5
0
    private void Start()
    {
        receiveStreamList         = new List <MediaStream>();
        videoStreamTrackList      = new List <VideoStreamTrack>();
        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.Kind == TrackKind.Video)
            {
                receiveStreamList[videoIndex % MaxVideoIndexLength].AddTrack(e.Track);
                videoIndex++;
            }

            if (videoIndex >= MaxVideoIndexLength)
            {
                addTracksButton.interactable = false;
            }
        };

        pc2OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc2)); };
    }
Example #6
0
    private void Start()
    {
        // This sample uses Compute Shader.
        if (!SystemInfo.supportsComputeShaders)
        {
            throw new System.NotSupportedException("Compute shader is not supported on this device");
        }

        vSyncCount      = QualitySettings.vSyncCount;
        targetFrameRate = Application.targetFrameRate;

        callButton.interactable         = false;
        hangUpButton.interactable       = false;
        dropDownResolution.interactable = true;
        dropDownResolution.options      =
            listResolution.Select(_ => new Dropdown.OptionData($"{_.x}x{_.y}")).ToList();
        dropDownResolution.value       = 3;
        dropDownFramerate.interactable = true;
        dropDownFramerate.options      =
            listFramerate.Select(_ => new Dropdown.OptionData($"{_}")).ToList();
        dropDownFramerate.value = 1;
        dropDownFramerate.onValueChanged.AddListener(OnFramerateChanged);

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
        pc2Ontrack = e =>
        {
            receiveStream.AddTrack(e.Track);
        };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };

        StartCoroutine(WebRTC.Update());
    }
Example #7
0
    private void Start()
    {
        pc1Senders = new List <RTCRtpSender>();
        callButton.interactable    = true;
        hangUpButton.interactable  = false;
        codecSelector.interactable = false;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
        pc2Ontrack = e =>
        {
            receiveStream.AddTrack(e.Track);
        };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };

        receiveStream.OnAddTrack = e =>
        {
            if (e.Track is VideoStreamTrack track)
            {
                track.OnVideoReceived += tex =>
                {
                    receiveImage.texture = tex;
                    receiveImage.color   = Color.white;
                };
            }
        };
    }
Example #8
0
        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.OnVideoReceived += tex =>
                    {
                        receiveImages[videoIndex].texture = tex;
                        videoIndex++;
                    };
                }
            };

            pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
            pc2OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc2)); };
        }
 private void Start()
 {
     callButton.interactable  = true;
     pc1OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { OnIceConnectionChange(pc1, state); });
     pc2OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { OnIceConnectionChange(pc2, state); });
     pc1OnIceCandidate        = new DelegateOnIceCandidate(candidate => { OnIceCandidate(pc2, candidate); });
     pc2OnIceCandidate        = new DelegateOnIceCandidate(candidate => { OnIceCandidate(pc1, candidate); });
 }
    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 => { receiveStream.AddTrack(e.Track); };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
    }
    private void Start()
    {
        trackInfos = new StringBuilder();
        pc1Senders = new List <RTCRtpSender>();
        pc2Senders = new List <RTCRtpSender>();
        callButton.interactable = true;

        pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
        pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
        pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
        pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
        pc2Ontrack             = e => { OnTrack(_pc2, e); };
        pc1OnNegotiationNeeded = () => { StartCoroutine(Pc1OnNegotiationNeeded()); };
        infoText.text          = !WebRTC.SupportHardwareEncoder ? "Current GPU doesn't support encoder" : "Current GPU supports encoder";
    }
        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.IsDecoderInitialized)
                {
                    receiveImage.texture             = video.InitializeReceiver(streamSize.x, streamSize.y);
                    receiveVideoStream               = e.Streams.First();
                    receiveVideoStream.OnRemoveTrack = ev =>
                    {
                        receiveImage.texture = null;
                        ev.Track.Dispose();
                    };
                }

                if (e.Track is AudioStreamTrack audioTrack)
                {
                    audioTrack.OnAudioReceived += clip =>
                    {
                        receiveAudio.clip = clip;
                        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());
        }
Example #13
0
        private void Start()
        {
            trackInfos = new StringBuilder();
            pc1Senders = new List <RTCRtpSender>();
            callButton.interactable = true;

            pc1OnIceConnectionChange = state => { OnIceConnectionChange(_pc1, state); };
            pc2OnIceConnectionChange = state => { OnIceConnectionChange(_pc2, state); };
            pc1OnIceCandidate        = candidate => { OnIceCandidate(_pc1, candidate); };
            pc2OnIceCandidate        = candidate => { OnIceCandidate(_pc2, candidate); };
            pc2Ontrack             = e => { OnTrack(_pc2, e); };
            pc1OnNegotiationNeeded = () => { StartCoroutine(PcOnNegotiationNeeded(_pc1)); };

            var codecName = WebRTCSettings.UseVideoCodec == null
                ? "Default"
                : $"{WebRTCSettings.UseVideoCodec.mimeType} {WebRTCSettings.UseVideoCodec.sdpFmtpLine}";

            infoText.text = $"Currently selected video codec is {codecName}";
        }
Example #14
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());
    }
Example #15
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 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)
            {
                receiveImage.texture = video.InitializeReceiver(1280, 720);
            }
        };
        pc1OnNegotiationNeeded = () => { StartCoroutine(PeerNegotiationNeeded(_pc1)); };
    }
Example #17
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();
    }