Beispiel #1
0
        void OnPause()
        {
            var transceiver1 = _pc1.GetTransceivers().First();
            var track        = transceiver1.Sender.Track;

            track.Enabled = false;

            buttonResume.gameObject.SetActive(true);
            buttonPause.gameObject.SetActive(false);
        }
Beispiel #2
0
        void OnCall()
        {
            buttonCall.interactable        = false;
            buttonPause.interactable       = true;
            dropdownBandwidth.interactable = true;

            _receiveStream             = new MediaStream();
            _receiveStream.OnAddTrack += OnAddTrack;
            _sendStream = new MediaStream();

            var configuration = GetSelectedSdpSemantics();

            _pc1 = new RTCPeerConnection(ref configuration)
            {
                OnIceCandidate      = candidate => _pc2.AddIceCandidate(candidate),
                OnNegotiationNeeded = () => StartCoroutine(PeerNegotiationNeeded(_pc1))
            };

            _pc2 = new RTCPeerConnection(ref configuration)
            {
                OnIceCandidate = candidate => _pc1.AddIceCandidate(candidate),
                OnTrack        = e => _receiveStream.AddTrack(e.Track),
            };

            var transceiver2 = _pc2.AddTransceiver(TrackKind.Audio);

            transceiver2.Direction = RTCRtpTransceiverDirection.RecvOnly;

            m_audioTrack          = new AudioStreamTrack(inputAudioSource);
            m_audioTrack.Loopback = toggleLoopback.isOn;
            _pc1.AddTrack(m_audioTrack, _sendStream);

            var transceiver1 = _pc1.GetTransceivers().First();

            if (dropdownAudioCodecs.value == 0)
            {
                var error = transceiver1.SetCodecPreferences(this.availableCodecs.ToArray());
                if (error != RTCErrorType.None)
                {
                    Debug.LogError(error);
                }
            }
            else
            {
                var codec = availableCodecs[dropdownAudioCodecs.value - 1];
                var error = transceiver1.SetCodecPreferences(new[] { codec });
                if (error != RTCErrorType.None)
                {
                    Debug.LogError(error);
                }
            }
        }