Exemplo n.º 1
0
        /// <summary>
        /// WebRTC Establishment: Builds the Peer Connection.
        /// </summary>
        /// <param name="mediaOptions"></param>
        /// <returns></returns>
        private async Task <RTCPeerConnection> BuildPeerConnection(MediaOptions mediaOptions)
        {
            return(await Task.Run(() =>
            {
                var factory = new WebRtcFactory(new WebRtcFactoryConfiguration());

                var peerConnection = new RTCPeerConnection(
                    new RTCConfiguration()
                {
                    Factory = factory,
                    BundlePolicy = RTCBundlePolicy.Balanced,
                    IceTransportPolicy = RTCIceTransportPolicy.All
                });

                peerConnection.OnTrack += this.OnTrack;
                peerConnection.OnRemoveTrack += this.OnRemoveTrack;

                if ((mediaOptions.SendVideo || mediaOptions.LocalLoopback) && this.LocalVideoTrack == null)
                {
                    if (mediaOptions.SendVideo || mediaOptions.LocalLoopback)
                    {
                        this.LocalVideoTrack = this.GetLocalVideo(factory);
                    }
                }

                if (mediaOptions.SendAudio && this.LocalAudioTrack == null)
                {
                    if (mediaOptions.SendAudio)
                    {
                        this.LocalAudioTrack = this.GetLocalAudio(factory);
                    }
                }

                if (mediaOptions.SendVideo)
                {
                    peerConnection.AddTrack(this.LocalVideoTrack);
                }
                if (mediaOptions.SendAudio)
                {
                    peerConnection.AddTrack(this.LocalAudioTrack);
                }

                if (mediaOptions.LocalLoopback)
                {
                    this.LocalVideoTrack.Element = MediaElementMaker.Bind(this.LocalVideo);
                }

                return peerConnection;
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set the desired media options.
        /// Will throw an exception if the conductor
        /// is not configured to support these options.
        /// </summary>
        /// <param name="options"></param>
        public void SetMediaOptions(MediaOptions options)
        {
            // media options are global for the source
            if (options.LocalLoopback && this.LocalVideo == null)
            {
                throw new ArgumentException();
            }

            if (options.ReceiveVideo && this.RemoteVideo == null)
            {
                throw new ArgumentException();
            }

            this.MediaOpts = options;
        }