Example #1
0
        void CloseTempPeer()
        {
            if (tempPeer == null)
            {
                return;
            }

            tempPeer.OnError -= TempPeer_OnError;
            tempPeer.OnClose -= TempPeer_OnClose;

            tempPeer.Close();

            tempPeer = null;
        }
Example #2
0
        void ClosePeer()
        {
            Logger.Debug("MediaChannel", "Close Peer");

            if (peer == null)
            {
                Logger.Debug("MediaChannel", "peer not found");
                return;
            }

            peer.OnConnect            -= Peer_OnConnect;
            peer.OnClose              -= Peer_OnClose;
            peer.OnError              -= Peer_OnError;
            peer.OnIceCandidate       -= Peer_OnIceCandidate;
            peer.OnAddLocalAudioTrack -= Peer_OnAddLocalAudioTrack;
            peer.OnAddLocalVideoTrack -= Peer_OnAddLocalVideoTrack;
            peer.OnAddRemoteTrack     -= Peer_OnAddRemoteTrack;
            peer.OnRemoveRemoteTrack  -= Peer_OnRemoveRemoteTrack;

            Logger.Debug("MediaChannel", "dispose local media tracks");

            if (localAudioTrack != null)
            {
                Logger.Debug("MediaChannel", "dispose local audio track");
                (localAudioTrack as IDisposable)?.Dispose();
                localAudioTrack = null;
            }

            if (localVideoTrack != null)
            {
                Logger.Debug("MediaChannel", "dispose local video track");
                (localVideoTrack as IDisposable)?.Dispose();
                localVideoTrack = null;
            }

            Logger.Debug("MediaChannel", "dispose remote media tracks");
            remoteTracksHolder.Dispose();

            Logger.Debug("MediaChannel", "Close Peer");
            peer.Close();

            peer = null;
        }