public IEnumerator UnitySetUp()
        {
            WebRTC.WebRTC.Initialize();

            RTCConfiguration config     = default;
            RTCIceCandidate? candidate_ = null;

            config.iceServers = new[] { new RTCIceServer {
                                            urls = new[] { "stun:stun.l.google.com:19302" }
                                        } };

            var peer1 = new RTCPeerConnection(ref config);
            var peer2 = new RTCPeerConnection(ref config);

            peer1.OnIceCandidate = candidate => { candidate_ = candidate; };

            MediaStream stream = WebRTC.Audio.CaptureStream();

            peer1.AddTrack(stream.GetTracks().First());

            RTCOfferOptions offerOptions = new RTCOfferOptions();
            var             op1          = peer1.CreateOffer(ref offerOptions);

            yield return(op1);

            m_DescOffer = op1.Desc;
            var op2 = peer1.SetLocalDescription(ref m_DescOffer);

            yield return(op2);

            var op3 = peer2.SetRemoteDescription(ref m_DescOffer);

            yield return(op3);

            RTCAnswerOptions answerOptions = new RTCAnswerOptions();
            var op4 = peer2.CreateAnswer(ref answerOptions);

            yield return(op4);

            m_DescAnswer = op4.Desc;
            var op5 = peer2.SetLocalDescription(ref m_DescAnswer);

            yield return(op5);

            var op6 = peer1.SetRemoteDescription(ref m_DescAnswer);

            yield return(op6);

            yield return(new WaitUntil(() => candidate_ != null));

            m_candidate = candidate_.Value;

            stream.Dispose();
            peer1.Close();
            peer2.Close();

            m_Context  = SynchronizationContext.Current;
            signaling1 = CreateSignaling(m_SignalingType, m_Context);
            signaling2 = CreateSignaling(m_SignalingType, m_Context);
        }
    IEnumerator proccessOffer(string clientId)
    {
        var op = pc.CreateOffer(ref offerOptions);

        yield return(op);

        if (op.isError)
        {
            Debug.Log("create offer error");
        }
        else
        {
            var ret = pc.SetLocalDescription(ref op.desc);
            yield return(ret);

            if (ret.isError)
            {
                Debug.LogError($"set local offer error:{ret.error}");
            }
            else
            {
                Debug.Log($"send offer: {op.desc.sdp}");
                wssMessageHandler.SendOffer(clientId, op.desc.sdp);
            }
        }
    }
Esempio n. 3
0
        IEnumerator SendOfferCoroutine(string connectionId, RTCPeerConnection pc)
        {
            RTCOfferOptions option = new RTCOfferOptions {
                offerToReceiveAudio = true, offerToReceiveVideo = true
            };
            var offerOp = pc.CreateOffer(ref option);

            yield return(offerOp);

            if (offerOp.IsError)
            {
                Debug.LogError($"Network Error: {offerOp.Error.message}");
                yield break;
            }

            if (pc.SignalingState != RTCSignalingState.Stable)
            {
                Debug.LogError($"peerConnection's signaling state is not stable. {pc.SignalingState}");
                yield break;
            }

            var desc        = offerOp.Desc;
            var setLocalSdp = pc.SetLocalDescription(ref desc);

            yield return(setLocalSdp);

            if (setLocalSdp.IsError)
            {
                Debug.LogError($"Network Error: {setLocalSdp.Error.message}");
                yield break;
            }
            _signaling.SendOffer(connectionId, desc);
        }
        public IEnumerator SetLocalDescription()
        {
            var             peer    = new RTCPeerConnection();
            RTCOfferOptions options = default;
            var             op      = peer.CreateOffer(ref options);

            yield return(op);

            Assert.True(op.IsDone);
            Assert.False(op.IsError);
            var desc = op.Desc;
            var op2  = peer.SetLocalDescription(ref desc);

            yield return(op2);

            Assert.True(op2.IsDone);
            Assert.False(op2.IsError);

            var desc2 = peer.LocalDescription;

            Assert.AreEqual(desc.sdp, desc2.sdp);
            Assert.AreEqual(desc.type, desc2.type);

            peer.Close();
            peer.Dispose();
        }
Esempio n. 5
0
        public IEnumerator CreateAnswer()
        {
            var config = GetDefaultConfiguration();

            var peer1 = new RTCPeerConnection(ref config);
            var peer2 = new RTCPeerConnection(ref config);

            peer1.CreateDataChannel("data");

            var op1 = peer1.CreateOffer();

            yield return(op1);

            var desc = op1.Desc;
            var op2  = peer1.SetLocalDescription(ref desc);

            yield return(op2);

            var op3 = peer2.SetRemoteDescription(ref desc);

            yield return(op3);

            var op4 = peer2.CreateAnswer();

            yield return(op4);

            Assert.True(op4.IsDone);
            Assert.False(op4.IsError);

            peer1.Close();
            peer2.Close();
            peer1.Dispose();
            peer2.Dispose();
        }
Esempio n. 6
0
    IEnumerator CreateOffer()
    {
        if (!_IsOffer)
        {
            yield break;
        }
        //オファー
        var op1 = localConnection.CreateOffer(ref OfferOptions);

        yield return(op1);

        var op2 = localConnection.SetLocalDescription(ref op1.desc);

        yield return(op2);

        if (!op1.isError)
        {
            //TextSDP(op1.desc, _mySDPText);
            SendSDP(op1.desc, NCMBStateData.MyNCMBstate.SENDED_offer);
        }
        else
        {
            Debug.Log("error offer");
        }
    }
Esempio n. 7
0
        private RTCSessionDescriptionAsyncOperation StartClientOffer()
        {
            // Client caller code.
            RTCOfferOptions options = default;

            return(_peerConnection.CreateOffer(ref options));
        }
    /// <summary>
    /// Creates a new WebRTC peer connection and send an SDP offer to the node DSS server.
    /// </summary>
    public IEnumerator Start()
    {
        var nodeDssClient = new HttpClient();

        Debug.WriteLine($"node-dss starting receive task for server {_nodeDssServerUri}, our ID {_ourID} and their ID {_theirID}.");

        RTCOfferOptions offerOptions  = new RTCOfferOptions();
        var             createOfferOp = _pc.CreateOffer(ref offerOptions);

        yield return(createOfferOp);

        if (createOfferOp.IsError)
        {
            Debug.WriteLine($"Error creating local description on peer connection. {createOfferOp.Error}");
        }
        else
        {
            Debug.WriteLine($"Offer SDP: {createOfferOp.Desc.sdp}.");

            var init       = createOfferOp.Desc;
            var setLocalOp = _pc.SetLocalDescription(ref init);
            yield return(setLocalOp);

            if (setLocalOp.IsError)
            {
                Debug.WriteLine($"Error setting local description on peer connection. {setLocalOp.Error}");
            }
            else
            {
                Debug.WriteLine("node-dss sending initial SDP offer to server.");
                _ = Task.Run(() => ReceiveFromNSS(nodeDssClient, _pc));
            }
        }
    }
Esempio n. 9
0
    IEnumerator Call()
    {
        callButton.interactable = false;
        Debug.Log("GetSelectedSdpSemantics");
        var configuration = GetSelectedSdpSemantics();

        pc1 = new RTCPeerConnection(ref configuration);
        Debug.Log("Created local peer connection object pc1");
        pc1.OnIceCandidate        = pc1OnIceCandidate;
        pc1.OnIceConnectionChange = pc1OnIceConnectionChange;
        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(true);

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

        Debug.Log("pc1 createOffer start");
        var op = pc1.CreateOffer(ref OfferOptions);

        yield return(op);

        if (!op.IsError)
        {
            yield return(StartCoroutine(OnCreateOfferSuccess(op.Desc)));
        }
        else
        {
            OnCreateSessionDescriptionError(op.Error);
        }
    }
        public IEnumerator SetLocalDescriptionFailed()
        {
            var peer   = new RTCPeerConnection();
            var stream = new MediaStream();
            var track  = new AudioStreamTrack("audio");
            var sender = peer.AddTrack(track, stream);

            RTCOfferOptions options = default;
            var             op      = peer.CreateOffer(ref options);

            yield return(op);

            Assert.True(op.IsDone);
            Assert.False(op.IsError);
            var desc = op.Desc;

            // change sdp to cannot parse
            desc.sdp = desc.sdp.Replace("m=audio", "m=audiable");
            var op2 = peer.SetLocalDescription(ref desc);

            yield return(op2);

            Assert.True(op2.IsDone);
            Assert.True(op2.IsError);
            Assert.IsNotEmpty(op2.Error.message);

            peer.RemoveTrack(sender);
            track.Dispose();
            stream.Dispose();
            peer.Close();
            peer.Dispose();
        }
Esempio n. 11
0
        public IEnumerator CurrentDirection()
        {
            var config     = GetConfiguration();
            var peer1      = new RTCPeerConnection(ref config);
            var peer2      = new RTCPeerConnection(ref config);
            var audioTrack = new AudioStreamTrack("audio");

            var transceiver1 = peer1.AddTransceiver(TrackKind.Audio);

            transceiver1.Direction = RTCRtpTransceiverDirection.RecvOnly;
            Assert.IsNull(transceiver1.CurrentDirection);

            RTCOfferOptions options1 = new RTCOfferOptions {
                offerToReceiveAudio = true
            };
            RTCAnswerOptions options2 = default;
            var op1 = peer1.CreateOffer(ref options1);

            yield return(op1);

            var desc = op1.Desc;
            var op2  = peer1.SetLocalDescription(ref desc);

            yield return(op2);

            var op3 = peer2.SetRemoteDescription(ref desc);

            yield return(op3);

            var transceiver2 = peer2.GetTransceivers().First(x => x.Receiver.Track.Kind == TrackKind.Audio);

            Assert.True(transceiver2.Sender.ReplaceTrack(audioTrack));
            transceiver2.Direction = RTCRtpTransceiverDirection.SendOnly;

            var op4 = peer2.CreateAnswer(ref options2);

            yield return(op4);

            desc = op4.Desc;
            var op5 = peer2.SetLocalDescription(ref desc);

            yield return(op5);

            var op6 = peer1.SetRemoteDescription(ref desc);

            yield return(op6);

            Assert.AreEqual(transceiver1.CurrentDirection, RTCRtpTransceiverDirection.RecvOnly);
            Assert.AreEqual(transceiver2.CurrentDirection, RTCRtpTransceiverDirection.SendOnly);

            audioTrack.Dispose();
            peer1.Close();
            peer2.Close();
            peer1.Dispose();
            peer2.Dispose();
        }
Esempio n. 12
0
        private static IEnumerator SignalingPeers(RTCPeerConnection offerPc, RTCPeerConnection answerPc)
        {
            offerPc.OnIceCandidate = candidate => answerPc.AddIceCandidate(ref candidate);
            answerPc.OnIceCandidate = candidate => offerPc.AddIceCandidate(ref candidate);

            var offerOption = new RTCOfferOptions {offerToReceiveVideo = true};
            var answerOption = new RTCAnswerOptions {iceRestart = false};

            var pc1CreateOffer = offerPc.CreateOffer(ref offerOption);
            yield return pc1CreateOffer;
            Assert.False(pc1CreateOffer.IsError);
            var offerDesc = pc1CreateOffer.Desc;

            var pc1SetLocalDescription = offerPc.SetLocalDescription(ref offerDesc);
            yield return pc1SetLocalDescription;
            Assert.False(pc1SetLocalDescription.IsError);

            var pc2SetRemoteDescription = answerPc.SetRemoteDescription(ref offerDesc);
            yield return pc2SetRemoteDescription;
            Assert.False(pc2SetRemoteDescription.IsError);

            var pc2CreateAnswer = answerPc.CreateAnswer(ref answerOption);
            yield return pc2CreateAnswer;
            Assert.False(pc2CreateAnswer.IsError);
            var answerDesc = pc2CreateAnswer.Desc;

            var pc2SetLocalDescription = answerPc.SetLocalDescription(ref answerDesc);
            yield return pc2SetLocalDescription;
            Assert.False(pc2SetLocalDescription.IsError);

            var pc1SetRemoteDescription = offerPc.SetRemoteDescription(ref answerDesc);
            yield return pc1SetRemoteDescription;
            Assert.False(pc1SetRemoteDescription.IsError);

            var waitConnectOfferPc = new WaitUntilWithTimeout(() =>
                offerPc.IceConnectionState == RTCIceConnectionState.Connected ||
                offerPc.IceConnectionState == RTCIceConnectionState.Completed, 5000);
            yield return waitConnectOfferPc;
            Assert.True(waitConnectOfferPc.IsCompleted);

            var waitConnectAnswerPc = new WaitUntilWithTimeout(() =>
                answerPc.IceConnectionState == RTCIceConnectionState.Connected ||
                answerPc.IceConnectionState == RTCIceConnectionState.Completed, 5000);
            yield return waitConnectAnswerPc;
            Assert.True(waitConnectAnswerPc.IsCompleted);

            var checkSenders = new WaitUntilWithTimeout(() => offerPc.GetSenders().Any(), 5000);
            yield return checkSenders;
            Assert.True(checkSenders.IsCompleted);

            var checkReceivers = new WaitUntilWithTimeout(() => answerPc.GetReceivers().Any(), 5000);
            yield return checkReceivers;
            Assert.True(checkReceivers.IsCompleted);
        }
Esempio n. 13
0
        IEnumerator Negotiate(RTCPeerConnection peer1, RTCPeerConnection peer2)
        {
            if (negotiating)
            {
                Debug.LogError("Negotiating");
                yield break;
            }
            negotiating = true;
            var op1 = peer1.CreateOffer();

            yield return(op1);

            Assert.That(op1.IsError, Is.False, op1.Error.message);
            var desc = op1.Desc;
            var op2  = peer1.SetLocalDescription(ref desc);

            yield return(op2);

            Assert.That(op2.IsError, Is.False, op2.Error.message);

            var op3 = peer2.SetRemoteDescription(ref desc);

            yield return(op3);

            Assert.That(op3.IsError, Is.False, op3.Error.message);
            var op4 = peer2.CreateAnswer();

            yield return(op4);

            Assert.That(op4.IsError, Is.False, op4.Error.message);
            desc = op4.Desc;
            var op5 = peer2.SetLocalDescription(ref desc);

            yield return(op5);

            Assert.That(op5.IsError, Is.False, op5.Error.message);

            var op6 = peer1.SetRemoteDescription(ref desc);

            yield return(op6);

            Assert.That(op6.IsError, Is.False, op6.Error.message);

            var op7 = new WaitUntilWithTimeout(() =>
                                               peers[0].SignalingState == RTCSignalingState.Stable &&
                                               peers[1].SignalingState == RTCSignalingState.Stable, 5000);

            yield return(op7);

            Assert.That(op7.IsCompleted, Is.True);

            IsTestFinished = true;
            negotiating    = false;
        }
Esempio n. 14
0
        private IEnumerator sendDesc(RTCSdpType type)
        {
            RTCSessionDescriptionAsyncOperation opCreate = null;

            if (type == RTCSdpType.Offer)
            {
                OnLogEvent.Invoke("CreateOffer()", "");
                opCreate = peer.CreateOffer(ref offerOption);
            }
            else
            {
                OnLogEvent.Invoke("CreateAnswer()", "");
                opCreate = peer.CreateAnswer(ref answerOptions);
            }

            yield return(opCreate);

            if (opCreate.IsError)
            {
                OnErrorEvent.Invoke($"Create {opCreate.Desc.type}", opCreate.Error.message);
                yield break;
            }
            else
            {
                OnLogEvent.Invoke($"Create {opCreate.Desc.type}", "");
            }

            if (opCreate.Desc.sdp == null)
            {
                OnErrorEvent.Invoke("opCreate.Desc.sdp is null", "");
                yield break;
            }
            else
            {
                OnLogEvent.Invoke($"SetLocalDescription {type}", $"{opCreate.Desc.sdp.Substring(0, 10)} ...");
            }
            var desc  = opCreate.Desc;
            var opSet = peer.SetLocalDescription(ref desc);

            yield return(opSet);

            if (opSet.IsError)
            {
                OnErrorEvent.Invoke($"SetLocalDescription {type}", opSet.Error.message);
                yield break;
            }

            OnLogEvent.Invoke($"Send {type}", "");
            signaling.SendDesc(streamId, desc.type.ToString().ToLower(), desc.sdp);
        }
Esempio n. 15
0
        public IEnumerator CreateOffer()
        {
            var config = GetDefaultConfiguration();
            var peer   = new RTCPeerConnection(ref config);
            var op     = peer.CreateOffer();

            yield return(op);

            Assert.True(op.IsDone);
            Assert.False(op.IsError);

            peer.Close();
            peer.Dispose();
        }
        public IEnumerator PeerConnection_CreateOffer()
        {
            var             config  = GetConfiguration();
            var             peer    = new RTCPeerConnection(ref config);
            RTCOfferOptions options = default;
            var             op      = peer.CreateOffer(ref options);

            yield return(op);

            Assert.True(op.isDone);
            Assert.False(op.isError);

            peer.Close();
        }
Esempio n. 17
0
        private async void NewElement_OfferRequested(object sender, EventArgs e)
        {
            var offer = await _peerConnection.CreateOffer();

            Debug.WriteLine("OfferRequested CreateOffer, sdp\n" + offer.Sdp);

            await _peerConnection.SetLocalDescription(offer);

            Debug.WriteLine("OfferRequested SetLocalDescription complete offer");

            //await _remoteRtcPeerConnection.SetRemoteDescription(offer);
            //Debug.WriteLine("SetRemoteDescription complete offer");

            Element.SendOfferRecived(offer.ToWebRTCSDP());
        }
Esempio n. 18
0
    private IEnumerator CreateOffer()
    {
        var op = pcLocal.CreateOffer();

        yield return(op);

        if (op.IsError)
        {
            OnCreateSessionDescriptionError(op.Error);
            yield break;
        }

        offerSdpInput.text         = op.Desc.sdp;
        offerSdpInput.interactable = true;
    }
    private IEnumerator createDesc(RTCSdpType type)
    {
        RTCSessionDescriptionAsyncOperation opCreate;

        if (type == RTCSdpType.Offer)
        {
            opCreate = peer.CreateOffer(ref offerOptions);
        }
        else
        {
            opCreate = peer.CreateAnswer(ref answerOptions);
        }

        yield return(opCreate);

        if (opCreate.IsError)
        {
            log(LogLevel.Error, $"Create {opCreate.Desc.type}: {opCreate.Error.message}");
            yield break;
        }
        else
        {
            log(LogLevel.Log, $"Create {opCreate.Desc.type}");
        }

        if (opCreate.Desc.sdp == null)
        {
            log(LogLevel.Error, $"opCreate.Desc.sdp is null");
            yield break;
        }
        else
        {
            log(LogLevel.Log, $"SetLocalDescription {type}: {opCreate.Desc.sdp}");
        }
        var desc  = opCreate.Desc;
        var opSet = peer.SetLocalDescription(ref desc);

        yield return(opSet);

        if (opSet.IsError)
        {
            log(LogLevel.Error, $"SetLocalDescription {type}: {opSet.Error.message}");
            yield break;
        }

        log(LogLevel.Log, $">>> Send \"takeConfiguration\" Command ({type}: '{desc.sdp.Substring(0, 10)} ...')");
        signaling.SendDesc(streamId, desc.type.ToString().ToLower(), desc.sdp);
    }
    IEnumerator Pc1OnNegotiationNeeded()
    {
        Debug.Log("pc1 createOffer start");
        var op = _pc1.CreateOffer(ref _offerOptions);

        yield return(op);

        if (!op.IsError)
        {
            yield return(StartCoroutine(OnCreateOfferSuccess(op.Desc)));
        }
        else
        {
            OnCreateSessionDescriptionError(op.Error);
        }
    }
    IEnumerator CreateOffer()
    {
        Debug.Log("createOffer start");
        var op = peerConnection.CreateOffer(ref _offerOptions);

        yield return(op);

        if (!op.IsError)
        {
            yield return(StartCoroutine(OnCreateOfferSuccess(op.Desc)));
        }
        else
        {
            OnCreateSessionDescriptionError(op.Error);
        }
    }
Esempio n. 22
0
    IEnumerator PcOnNegotiationNeeded(RTCPeerConnection pc)
    {
        Debug.Log($"{GetName(pc)} createOffer start");
        var op = pc.CreateOffer(ref _offerOptions);

        yield return(op);

        if (!op.IsError)
        {
            yield return(StartCoroutine(OnCreateOfferSuccess(pc, op.Desc)));
        }
        else
        {
            OnCreateSessionDescriptionError(op.Error);
        }
    }
Esempio n. 23
0
        public async Task <ICallInfo> PlaceCallAsync(CallConfiguration config)
        {
            Debug.Assert(_peerId == -1);

            if (PeerConnection != null)
            {
                Debug.WriteLine("[Error] We only support connection to one peer at a time.");
                return(null);
            }

            if (CreatePeerConnection())
            {
                string selectedAudioCodecName = (string)_localSettings.Values["SelectedAudioCodecName"];
                string selectedVideoCodecName = (string)_localSettings.Values["SelectedVideoCodecName"];

                _peerId = PeerId;

                var offerOptions = new RTCOfferOptions();
                offerOptions.OfferToReceiveAudio = true;
                offerOptions.OfferToReceiveVideo = true;
                IRTCSessionDescription offer = await PeerConnection.CreateOffer(offerOptions);

                // Alter sdp to force usage of selected codecs
                string modifiedSdp = offer.Sdp;
                SdpUtils.SelectCodec(ref modifiedSdp, selectedAudioCodecName, "audio");
                SdpUtils.SelectCodec(ref modifiedSdp, selectedVideoCodecName, "video");
                RTCSessionDescriptionInit sdpInit = new RTCSessionDescriptionInit();
                sdpInit.Sdp  = modifiedSdp;
                sdpInit.Type = offer.SdpType;
                var modifiedOffer = new RTCSessionDescription(sdpInit);
                await PeerConnection.SetLocalDescription(modifiedOffer);

                Debug.WriteLine($"Sending offer: {modifiedOffer.Sdp}");

                string jsonString = SdpToJsonString(modifiedOffer);

                CallInfo callInfo = new CallInfo();
                callInfo.SetCall(new Call());
                callInfo.SetSdp(modifiedSdp);
                callInfo.SetJsonString(jsonString);

                OnSendMessageToRemotePeer.Invoke(this, jsonString);

                return(callInfo);
            }
            return(null);
        }
Esempio n. 24
0
        public IEnumerator SetRemoteDescription()
        {
            var config   = GetConfiguration();
            var peer1    = new RTCPeerConnection(ref config);
            var peer2    = new RTCPeerConnection(ref config);
            var conf     = new RTCDataChannelInit(true);
            var channel1 = peer1.CreateDataChannel("data", ref conf);

            RTCOfferOptions  options1 = default;
            RTCAnswerOptions options2 = default;
            var op1 = peer1.CreateOffer(ref options1);

            yield return(op1);

            var desc = op1.Desc;
            var op2  = peer1.SetLocalDescription(ref desc);

            yield return(op2);

            var op3 = peer2.SetRemoteDescription(ref desc);

            yield return(op3);

            var op4 = peer2.CreateAnswer(ref options2);

            yield return(op4);

            desc = op4.Desc;
            var op5 = peer2.SetLocalDescription(ref desc);

            yield return(op5);

            var op6 = peer1.SetRemoteDescription(ref desc);

            yield return(op6);

            var desc2 = peer1.RemoteDescription;

            Assert.AreEqual(desc.sdp, desc2.sdp);
            Assert.AreEqual(desc.type, desc2.type);

            channel1.Dispose();
            peer1.Close();
            peer2.Close();
            peer1.Dispose();
            peer2.Dispose();
        }
Esempio n. 25
0
    IEnumerator CreateDescription(RTCSdpType type)
    {
        Debug.Log($"[Create {type}]");

        var op = type == RTCSdpType.Offer ? localConnection.CreateOffer(ref offerOption) : localConnection.CreateAnswer(ref answerOptions);

        yield return(op);

        if (op.IsError)
        {
            Debug.LogError(op.Error.message);
        }
        else
        {
            yield return(SetDescription(op.Desc, Side.Local));
        }
    }
        public IEnumerator PeerConnection_SetRemoteDescription()
        {
            RTCConfiguration config = default;

            config.iceServers = new[] { new RTCIceServer {
                                            urls = new[] { "stun:stun.l.google.com:19302" }
                                        } };
            var            peer1    = new RTCPeerConnection(ref config);
            var            peer2    = new RTCPeerConnection(ref config);
            RTCDataChannel channel1 = null;

            var conf = new RTCDataChannelInit(true);

            channel1 = peer1.CreateDataChannel("data", ref conf);

            RTCOfferOptions  options1 = default;
            RTCAnswerOptions options2 = default;
            var op1 = peer1.CreateOffer(ref options1);

            yield return(op1);

            var op2 = peer1.SetLocalDescription(ref op1.desc);

            yield return(op2);

            var op3 = peer2.SetRemoteDescription(ref op1.desc);

            yield return(op3);

            var op4 = peer2.CreateAnswer(ref options2);

            yield return(op4);

            var op5 = peer2.SetLocalDescription(ref op4.desc);

            yield return(op5);

            var op6 = peer1.SetRemoteDescription(ref op4.desc);

            yield return(op6);

            channel1.Dispose();
            peer1.Dispose();
            peer2.Dispose();
        }
        public IEnumerator PeerConnection_SetLocalDescription()
        {
            var             peer    = new RTCPeerConnection();
            RTCOfferOptions options = default;
            var             op      = peer.CreateOffer(ref options);

            yield return(op);

            Assert.True(op.isDone);
            Assert.False(op.isError);
            var op2 = peer.SetLocalDescription(ref op.desc);

            yield return(op2);

            Assert.True(op2.isDone);
            Assert.False(op2.isError);
            peer.Close();
        }
Esempio n. 28
0
        private IEnumerator SignalingOffer(RTCPeerConnection @from, RTCPeerConnection to)
        {
            var op1 = @from.CreateOffer();

            yield return(op1);

            var desc = op1.Desc;
            var op2  = @from.SetLocalDescription(ref desc);

            yield return(op2);

            var op3 = to.SetRemoteDescription(ref desc);

            yield return(op3);

            var op4 = to.CreateAnswer();

            yield return(op4);

            desc = op4.Desc;
            var op5 = to.SetLocalDescription(ref desc);

            yield return(op5);

            var op6 = @from.SetRemoteDescription(ref desc);

            yield return(op6);

            var op7 = new WaitUntilWithTimeout(
                () => @from.IceConnectionState == RTCIceConnectionState.Connected ||
                @from.IceConnectionState == RTCIceConnectionState.Completed, 5000);

            yield return(op7);

            Assert.That(op7.IsCompleted, Is.True);
            var op8 = new WaitUntilWithTimeout(
                () => to.IceConnectionState == RTCIceConnectionState.Connected ||
                to.IceConnectionState == RTCIceConnectionState.Completed, 5000);

            yield return(op8);

            Assert.That(op8.IsCompleted, Is.True);
        }
Esempio n. 29
0
        public IEnumerator SetRemoteDescriptionFailed()
        {
            var config = GetDefaultConfiguration();
            var peer1  = new RTCPeerConnection(ref config);
            var peer2  = new RTCPeerConnection(ref config);

            var stream = new MediaStream();
            var obj    = new GameObject("audio");
            var source = obj.AddComponent <AudioSource>();

            source.clip = AudioClip.Create("test", 480, 2, 48000, false);
            var track  = new AudioStreamTrack(source);
            var sender = peer1.AddTrack(track, stream);

            var op1 = peer1.CreateOffer();

            yield return(op1);

            var desc = op1.Desc;
            var op2  = peer1.SetLocalDescription(ref desc);

            yield return(op2);

            // change sdp to cannot parse
            desc.sdp = desc.sdp.Replace("a=mid:0", "a=mid:10");
            var op3 = peer2.SetRemoteDescription(ref desc);

            yield return(op3);

            Assert.True(op3.IsDone);
            Assert.True(op3.IsError);
            Assert.IsNotEmpty(op3.Error.message);

            peer1.RemoveTrack(sender);
            track.Dispose();
            stream.Dispose();
            peer1.Close();
            peer2.Close();
            peer1.Dispose();
            peer2.Dispose();
            Object.DestroyImmediate(source.clip);
            Object.DestroyImmediate(obj);
        }
Esempio n. 30
0
    IEnumerator Call()
    {
        callButton.interactable = false;
        Debug.Log("GetSelectedSdpSemantics");
        var configuration = GetSelectedSdpSemantics();

        pc1 = new RTCPeerConnection(ref configuration);
        Debug.Log("Created local peer connection object pc1");
        pc1.OnIceCandidate        = pc1OnIceCandidate;
        pc1.OnIceConnectionChange = pc1OnIceConnectionChange;
        pc2 = new RTCPeerConnection(ref configuration);
        Debug.Log("Created remote peer connection object pc2");
        pc2.OnIceCandidate        = pc2OnIceCandidate;
        pc2.OnIceConnectionChange = pc2OnIceConnectionChange;
        pc2.OnDataChannel         = onDataChannel;

        dataChannel        = pc1.CreateDataChannel("data");
        dataChannel.OnOpen = onDataChannelOpen;

        var audioTrack = new AudioStreamTrack(source);
        var videoTrack = cam.CaptureStreamTrack(1280, 720);

        yield return(0);

        pc1.AddTrack(audioTrack);
        pc1.AddTrack(videoTrack);

        Debug.Log("pc1 createOffer start");
        var op = pc1.CreateOffer();

        yield return(op);

        if (!op.IsError)
        {
            yield return(StartCoroutine(OnCreateOfferSuccess(op.Desc)));
        }
        else
        {
            OnCreateSessionDescriptionError(op.Error);
        }
    }