Ejemplo n.º 1
0
        public void Connect(
            string signalingUrl,
            ClientType clientType,
            string streamId,
            int videoWidth,
            int videoHeight,
            int videoBitrate,
            RenderTexture renderTexture)
        {
            this.clientType    = clientType;
            this.streamId      = streamId;
            this.videoWidth    = videoWidth;
            this.videoHeight   = videoHeight;
            this.renderTexture = renderTexture;
            try
            {
                signaling                   = new AntMediaSignaling(signalingUrl);
                signaling.OnOpen           += Signaling_OnOpen;
                signaling.OnStart          += Signaling_OnStart;
                signaling.OnAnswer         += Signaling_OnAnswer;
                signaling.OnOffer          += Signaling_OnOffer;
                signaling.OnIceCandidate   += Signaling_OnIceCandidate;
                signaling.OnClose          += Signaling_OnClose;
                signaling.OnWSError        += Signaling_OnWSError;
                signaling.OnSignalingError += Signaling_OnSignalingError;

                signaling.Connect();
            }
            catch (Exception ex)
            {
                OnErrorEvent.Invoke("Connect() Error", ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void Close()
        {
            try
            {
                signaling?.Close();
                signaling = null;
            }
            catch (Exception ex)
            {
                OnErrorEvent.Invoke("signaling.close", ex.Message);
            }

            try
            {
                if (dataChannel != null)
                {
                    dataChannel.OnOpen    = null;
                    dataChannel.OnMessage = null;
                    dataChannel.OnClose   = null;
                    dataChannel.Close();
                    dataChannel = null;
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent.Invoke("dataChannel dispose", ex.Message);
            }

            try
            {
                peer.OnConnectionStateChange   = null;
                peer.OnDataChannel             = null;
                peer.OnIceCandidate            = null;
                peer.OnIceGatheringStateChange = null;
                peer.OnNegotiationNeeded       = null;
                peer.OnTrack = null;
                peer.Close();
                peer.Dispose();
                peer = null;
            }
            catch (Exception ex)
            {
                OnErrorEvent.Invoke("peer dispose", ex.Message);
            }
        }