예제 #1
0
 /**
  * Cleans the subscriber from the view hierarchy, if any.
  * NB: You do *not* have to call unsubscribe in your controller in response to
  * a streamDestroyed event. Any subscribers (or the publisher) for a stream will
  * be automatically removed from the session during cleanup of the stream.
  */
 public void CleanupSubscriber()
 {
     if (_subscriber != null)
     {
         _subscriber.View.RemoveFromSuperview();
         _subscriber.Delegate = null;
         _subscriber.Dispose();
         _subscriber = null;
     }
 }
예제 #2
0
        public void DoEndSession()
        {
            lock (syncLock)
            {
                if (Subscriber != null)
                {
                    if (Subscriber.SubscribeToAudio)
                    {
                        Subscriber.SubscribeToAudio = false;
                    }
                    if (Subscriber.SubscribeToVideo)
                    {
                        Subscriber.SubscribeToVideo = false;
                    }

                    Subscriber.DidConnectToStream -= OnSubscriberDidConnectToStream;
                    Subscriber.VideoDataReceived  -= OnSubscriberVideoDataReceived;
                    Subscriber.VideoEnabled       -= OnSubscriberVideoEnabled;

                    Subscriber.Dispose();
                    Subscriber = null;
                }

                if (Publisher != null)
                {
                    if (Publisher.PublishAudio)
                    {
                        Publisher.PublishAudio = false;
                    }
                    if (Publisher.PublishVideo)
                    {
                        Publisher.PublishVideo = false;
                    }
                    Publisher.Dispose();
                    Publisher = null;
                }

                if (Session != null)
                {
                    Session.ConnectionDestroyed -= OnConnectionDestroyed;
                    Session.DidConnect          -= OnDidConnect;
                    Session.StreamCreated       -= OnStreamCreated;
                    Session.StreamDestroyed     -= OnStreamDestroyed;

                    Session.Disconnect();
                    Session.Dispose();
                    Session = null;
                }

                PublisherContianer?.InvokeOnMainThread(() =>
                {
                    DeactivateStreamContainer(PublisherContianer);
                    PublisherContianer = null;
                });

                SubscriberContainer?.InvokeOnMainThread(() =>
                {
                    DeactivateStreamContainer(SubscriberContainer);
                    SubscriberContainer = null;
                });
            }
        }
        public void EndSession()
        {
            lock (_syncRoot)
            {
                try
                {
                    _sessionTerminationIsInProgress = true;
                    if (_subscriber != null)
                    {
                        if (_subscriber.SubscribeToAudio)
                        {
                            _subscriber.SubscribeToAudio = false;
                        }
                        if (_subscriber.SubscribeToVideo)
                        {
                            _subscriber.SubscribeToVideo = false;
                        }
                        SubscribeForSubscriberEvents(_subscriber, false);
                        _subscriber.Dispose();
                        _subscriber = null;
                    }
                    if (_publisher != null)
                    {
                        if (_publisher.PublishAudio)
                        {
                            _publisher.PublishAudio = false;
                        }
                        if (_publisher.PublishVideo)
                        {
                            _publisher.PublishVideo = false;
                        }
                        SubscribeForPublisherEvents(_publisher, false);
                        _publisher.Dispose();
                        _publisher = null;
                    }

                    if (_session != null)
                    {
                        SubscribeForSessionEvents(_session, false);
                        _session.Disconnect();
                        _session.Dispose();
                        _session = null;
                    }

                    _myStreamContainer.InvokeOnMainThread(() =>
                    {
                        DeactivateStreamContainer(_myStreamContainer);
                        _myStreamContainer = null;

                        DeactivateStreamContainer(_otherStreamContainer);
                        _otherStreamContainer = null;
                    });

                    _apiKey    = null;
                    _sessionId = null;
                    _userToken = null;

                    IsVideoPublishingEnabled   = false;
                    IsAudioPublishingEnabled   = false;
                    IsVideoSubscriptionEnabled = false;
                    IsAudioSubscriptionEnabled = false;
                    IsSubscriberVideoEnabled   = false;

                    _subscriberConnected = false;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    _sessionTerminationIsInProgress = false;
                    OnSessionEnded();
                }
            }
        }