/**
  * Cleans up the publisher and its view. At this point, the publisher should not
  * be attached to the session any more.
  */
 public void CleanupPublisher()
 {
     if (_publisher != null)
     {
         _publisher.View.RemoveFromSuperview();
         _publisher.Delegate = null;
         _publisher.Dispose();
         _publisher = null;
     }
 }
Esempio n. 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();
                }
            }
        }