示例#1
0
        //private void _remoteRtcPeerConnection_OnIceConnectionChange(RTCPeerConnectionIceStateChangeEvent __param0)
        //{
        //    Debug.WriteLine($"Entered _remoteRtcPeerConnection_OnIceConnectionChange {__param0.State}");
        //}

        //private async void _remoteRtcPeerConnection_OnIceCandidate(RTCPeerConnectionIceEvent __param0)
        //{
        //    Debug.WriteLine("Entered _remoteRtcPeerConnection_OnIceCandidate");
        //    await _remoteRtcPeerConnection.AddIceCandidate(__param0.Candidate);
        //}

        //private void _remoteRtcPeerConnection_OnAddStream(MediaStreamEvent __param0)
        //{
        //    MediaStream remoteStream = __param0.Stream;
        //    var tracks = remoteStream.GetVideoTracks();
        //    _media.AddVideoTrackMediaElementPair(tracks.FirstOrDefault(), _remoteVideo, remoteStream.Id);
        //    Debug.WriteLine("Received a remote stream");
        //}

        private void _peerConnection_OnAddStream(MediaStreamEvent __param0)
        {
            MediaStream remoteStream = __param0.Stream;
            var         tracks       = remoteStream.GetVideoTracks();

            _media.AddVideoTrackMediaElementPair(tracks.FirstOrDefault(), _remoteVideo, remoteStream.Id);
            Debug.WriteLine("Received a remote stream");
        }
示例#2
0
        private async Task Initialize()
        {
            //Initialization of WebRTC worker threads, etc
            Org.WebRtc.WebRTC.Initialize(Dispatcher);

            _media = Media.CreateMedia();

            //Selecting video device to use, setting preferred capabilities
            var videoDevices        = _media.GetVideoCaptureDevices();
            var selectedVideoDevice = videoDevices.First();
            var videoCapabilites    = await selectedVideoDevice.GetVideoCaptureCapabilities();

            var selectedVideoCapability = videoCapabilites.FirstOrDefault();

            //Needed for HoloLens camera, will not set compatible video capability automatically
            //Hololens Cam default capability: 1280x720x30
            Org.WebRtc.WebRTC.SetPreferredVideoCaptureFormat(
                (int)selectedVideoCapability.Width,
                (int)selectedVideoCapability.Height,
                (int)selectedVideoCapability.FrameRate);

            //Setting up local stream
            RTCMediaStreamConstraints mediaStreamConstraints = new RTCMediaStreamConstraints
            {
                audioEnabled = false,
                videoEnabled = true
            };

            _localStream = await _media.GetUserMedia(mediaStreamConstraints);

            _media.SelectVideoDevice(selectedVideoDevice);

            // Get Video Tracks
            var videotrac = _localStream.GetVideoTracks();

            foreach (var videoTrack in videotrac) //This foreach may not be necessary
            {
                videoTrack.Enabled = true;
            }
            var selectedVideoTrac = videotrac.FirstOrDefault();

            Debug.WriteLine("Creating RTCPeerConnection");
            var config = new RTCConfiguration()
            {
                BundlePolicy       = RTCBundlePolicy.Balanced,
                IceTransportPolicy = RTCIceTransportPolicy.All,
                IceServers         = GetDefaultList()
            };

            _peerConnection = new RTCPeerConnection(config);
            _peerConnection.OnIceCandidate        += _localRtcPeerConnection_OnIceCandidate;
            _peerConnection.OnIceConnectionChange += _localRtcPeerConnection_OnIceConnectionChange;
            _peerConnection.OnAddStream           += _peerConnection_OnAddStream;

            //_peerConnection.AddStream(_localStream);
            _media.AddVideoTrackMediaElementPair(selectedVideoTrac, _localVideo, _localStream.Id);

            // Send event started
            Element.SendStarted();

            //Debug.WriteLine("Creating 'remote' RTCPeerConnection");
            //_remoteRtcPeerConnection = new RTCPeerConnection(config);
            //_remoteRtcPeerConnection.OnIceCandidate += _remoteRtcPeerConnection_OnIceCandidate;
            //_remoteRtcPeerConnection.OnIceConnectionChange += _remoteRtcPeerConnection_OnIceConnectionChange;
            //// Wait for Stream
            //_remoteRtcPeerConnection.OnAddStream += _remoteRtcPeerConnection_OnAddStream;
        }