Esempio n. 1
0
        /// <summary>
        /// Closes a peer connection.
        /// </summary>
        private void ClosePeerConnection()
        {
            lock (MediaLock)
            {
                if (_peerConnection != null)
                {
                    _peerId = -1;
                    if (_mediaStream != null)
                    {
                        foreach (var track in _mediaStream.GetTracks())
                        {
                            track.Stop();
                            _mediaStream.RemoveTrack(track);
                        }
                    }
                    _mediaStream = null;

                    OnPeerConnectionClosed?.Invoke();

                    _peerConnection.Close(); // Slow, so do this after UI updated and camera turned off

                    SessionId = null;
#if ORTCLIB
                    OrtcStatsManager.Instance.CallEnded();
#endif
                    _peerConnection = null;

                    OnReadyToConnect?.Invoke();

                    GC.Collect(); // Ensure all references are truly dropped.
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Closes a peer connection.
        /// </summary>
        //private async Task ClosePeerConnection()
        private void ClosePeerConnection()
        {
            lock (MediaLock)
            {
                if (_peerConnection != null)
                {
                    _peerId = -1;
                    if (_mediaStream != null)
                    {
                        foreach (var track in _mediaStream.GetTracks())
                        {
                            // Check Track Status before action to avoid reference errors
                            // CRASH condition previously on non-XAML usage
                            if (track != null)
                            {
                                if (track.Enabled)
                                {
                                    track.Stop();
                                }
                                _mediaStream.RemoveTrack(track);
                            }
                        }
                    }
                    _mediaStream = null;

                    // TODO: Cleanup DataChannel
                    if (_peerSendDataChannel != null)
                    {
                        _peerSendDataChannel.Close();
                        _peerSendDataChannel = null;
                    }

                    if (_peerReceiveDataChannel != null)
                    {
                        _peerReceiveDataChannel.Close();
                        _peerReceiveDataChannel = null;
                    }

                    OnPeerConnectionClosed?.Invoke();

                    _peerConnection.Close(); // Slow, so do this after UI updated and camera turned off

                    SessionId = null;
    #if ORTCLIB
                    OrtcStatsManager.Instance.CallEnded();
    #endif
                    _peerConnection = null;

                    OnReadyToConnect?.Invoke();

                    // TODO: handle GC
                    //GC.Collect(); // Ensure all references are truly dropped.
                }
            }
        }
Esempio n. 3
0
        public void SetConnection(Connection connection)
        {
            Connection = connection;

            Connection.OnClose += (object sender, EventArgs e) => {
                if (OnLeave != null)
                {
                    OnLeave.Invoke(this, e);
                }
            };

            Connection.OnError += (object sender, ErrorEventArgs e) => {
                if (OnError != null)
                {
                    OnError.Invoke(this, e);
                }
            };

            OnReadyToConnect.Invoke(this, new EventArgs());
        }
Esempio n. 4
0
        /// <summary>
        /// Closes a peer connection.
        /// </summary>
        public void ClosePeerConnection()
        {
            lock (MediaLock)
            {
                if (PeerConnection != null)
                {
                    _peerId = -1;

                    PeerConnection.OnIceCandidate -= PeerConnection_OnIceCandidate;
                    PeerConnection.OnTrack        -= PeerConnection_OnTrack;
                    PeerConnection.OnRemoveTrack  -= PeerConnection_OnRemoveTrack;

                    if (_peerVideoTrack != null)
                    {
                        _peerVideoTrack.Element = null;
                    }
                    if (_selfVideoTrack != null)
                    {
                        _selfVideoTrack.Element = null;
                    }

                    (_peerVideoTrack as IDisposable)?.Dispose();
                    (_peerAudioTrack as IDisposable)?.Dispose();
                    (_selfVideoTrack as IDisposable)?.Dispose();
                    (_selfAudioTrack as IDisposable)?.Dispose();

                    _peerVideoTrack = null;
                    _peerAudioTrack = null;
                    _selfVideoTrack = null;
                    _selfAudioTrack = null;

                    OnPeerConnectionClosed?.Invoke();

                    PeerConnection = null;

                    OnReadyToConnect?.Invoke();

                    GC.Collect(); // Ensure all references are truly dropped.
                }
            }
        }