Beispiel #1
0
        private void OnStreamCreated(object sender, OTSessionDelegateStreamEventArgs e)
        {
            if (Session == null)
            {
                return;
            }

            DestroyStream(e.Stream?.StreamId);

            var subscriberKit = new OTSubscriber(e.Stream, null)
            {
                SubscribeToVideo = IsVideoSubscriptionEnabled,
                SubscribeToAudio = IsAudioSubscriptionEnabled
            };

            subscriberKit.DidConnectToStream      += OnSubscriberConnected;
            subscriberKit.DidDisconnectFromStream += OnSubscriberDisconnected;
            subscriberKit.VideoDataReceived       += OnSubscriberVideoDataReceived;
            subscriberKit.VideoEnabled            += OnSubscriberVideoEnabled;
            subscriberKit.VideoDisabled           += OnSubscriberVideoDisabled;

            Session.Subscribe(subscriberKit);
            var streamId = e.Stream.StreamId;

            _subscribers.Add(subscriberKit);
            _subscriberStreamIds.Add(streamId);
        }
        private void OnStreamCreated(object sender, OTSessionDelegateStreamEventArgs e)
        {
            lock (_locker)
            {
                if (Session == null || Subscribers != null &&
                    Subscribers.ContainsKey(e.Stream.StreamId))
                {
                    return;
                }

                var subscriberKit = new OTSubscriber(e.Stream, null)
                {
                    SubscribeToVideo = IsVideoSubscriptionEnabled,
                    SubscribeToAudio = IsAudioSubscriptionEnabled
                };
                subscriberKit.DidConnectToStream      += OnSubscriberConnected;
                subscriberKit.DidDisconnectFromStream += OnSubscriberDisconnected;
                subscriberKit.VideoDataReceived       += OnSubscriberVideoDataReceived;
                subscriberKit.VideoEnabled            += OnSubscriberVideoEnabled;
                subscriberKit.VideoDisabled           += OnSubscriberVideoDisabled;
                Session.Subscribe(subscriberKit);

                Subscribers?.Add(e.Stream.StreamId, subscriberKit);
                OnSubscriberAdded(e.Stream.StreamId);
            }
        }
            public override void DidFail(OTSubscriber subscriber, OTError error)
            {
                Debug.WriteLine("Subscriber {0} DidFailWithError {1}", subscriber.Stream.StreamId, error);
                var msg = string.Format("There was an error subscribing to stream {0}", subscriber.Stream.StreamId);

                _this.ShowAlert(msg);
            }
Beispiel #4
0
            public override void DidFailWithError(OTSubscriber subscriber, OTError error)
            {
                var msg = String.Format("SubscriberDelegate:DidFailWithError: Stream {0}, Error: {1}", subscriber.Stream.StreamId, error.Description);

                Debug.WriteLine(msg);

                _this.RaiseOnError(msg);
            }
Beispiel #5
0
        public override void DidConnectToStream(OTSubscriber subscriber)
        {
            Debug.WriteLine("SubscriberDelegate:DidConnectToStream: " + subscriber.Stream.StreamId);

            //this.provider._subscriber.View.Frame = new RectangleF(0, 0, _this.Frame.Width, _this.Frame.Height);
            this.provider._subscriber.View.Frame = new RectangleF(0, 0, 200, 200);

            this.provider.SubscriberView.AddSubview(this.provider._subscriber.View);
        }
        public override void EndSession(bool sendBackToRoot, bool showEvaluateCall)
        {
            try
            {
                if (Session == null)
                {
                    return;
                }

                lock (_locker)
                {
                    if (SubscriberKit != null)
                    {
                        SubscriberKit.SubscribeToAudio         = false;
                        SubscriberKit.SubscribeToVideo         = false;
                        SubscriberKit.DidConnectToStream      -= OnSubscriberConnected;
                        SubscriberKit.DidDisconnectFromStream -= OnSubscriberDisconnected;
                        SubscriberKit.VideoDataReceived       -= OnSubscriberVideoDataReceived;
                        SubscriberKit.VideoEnabled            -= OnSubscriberVideoEnabled;
                        SubscriberKit.VideoDisabled           -= OnSubscriberVideoDisabled;
                        SubscriberKit.Dispose();
                        SubscriberKit = null;
                    }

                    if (PublisherKit != null)
                    {
                        PublisherKit.PublishAudio   = false;
                        PublisherKit.PublishVideo   = false;
                        PublisherKit.StreamCreated -= OnPublisherStreamCreated;
                        PublisherKit.Dispose();
                        PublisherKit = null;
                    }

                    if (Session != null)
                    {
                        Session.ConnectionDestroyed -= OnConnectionDestroyed;
                        Session.DidConnect          -= OnDidConnect;
                        Session.StreamCreated       -= OnStreamCreated;
                        Session.StreamDestroyed     -= OnStreamDestroyed;
                        Session.DidFailWithError    -= OnError;
                        Session.ReceivedSignalType  -= OnSignalReceived;
                        Session.Disconnect();
                        Session.Dispose();
                        Session = null;
                    }
                }
                ClearPublisherUpdated();
                ClearSubscribeUpdated();
                VideoCallStatus((int)CallStatus.Ending, null, sendBackToRoot, showEvaluateCall);
            }
            finally
            {
                _medicalVideoCall.Messages.Clear();
                IsSessionStarted    = false;
                IsPublishingStarted = false;
            }
        }
Beispiel #7
0
            public override void DidConnectToStream(OTSubscriber subscriber)
            {
                Debug.WriteLine("SubscriberDelegate:DidConnectToStream: " + subscriber.Stream.StreamId);

                _this._subscriber.View.Frame = new RectangleF(0, 0, _this.Frame.Width, _this.Frame.Height);

                _this.SubscriberView.AddSubview(_this._subscriber.View);

                _this.StatusLabel.Text = String.Empty;
            }
 /**
  * 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;
     }
 }
 private void UpdateSubscriber()
 {
     foreach (var streamId in _session.Streams)
     {
         var stream = (OTStream)streamId.Value;
         if (!Equals(stream.Connection.ConnectionId, _session.Connection.ConnectionId))
         {
             _subscriber = new OTSubscriber(stream, new SubDelegate(this));
             break;
         }
     }
 }
        public override void EndSession()
        {
            try
            {
                if (Session == null)
                {
                    return;
                }

                lock (_locker)
                {
                    if (SubscriberKit != null)
                    {
                        SubscriberKit.SubscribeToAudio    = false;
                        SubscriberKit.SubscribeToVideo    = false;
                        SubscriberKit.DidConnectToStream -= OnSubscriberDidConnectToStream;
                        SubscriberKit.VideoDataReceived  -= OnSubscriberVideoDataReceived;
                        SubscriberKit.VideoEnabled       -= OnSubscriberVideoEnabled;
                        SubscriberKit.VideoDisabled      -= OnSubscriberVideoDisabled;
                        SubscriberKit.Dispose();
                        SubscriberKit = null;
                    }

                    if (PublisherKit != null)
                    {
                        PublisherKit.PublishAudio   = false;
                        PublisherKit.PublishVideo   = false;
                        PublisherKit.StreamCreated -= OnPublisherStreamCreated;
                        PublisherKit.Dispose();
                        PublisherKit = null;
                    }

                    if (Session != null)
                    {
                        Session.ConnectionDestroyed -= OnConnectionDestroyed;
                        Session.DidConnect          -= OnDidConnect;
                        Session.StreamCreated       -= OnStreamCreated;
                        Session.StreamDestroyed     -= OnStreamDestroyed;
                        Session.DidFailWithError    -= OnError;
                        Session.ReceivedSignalType  -= OnSignalReceived;
                        Session.Disconnect();
                        Session.Dispose();
                        Session = null;
                    }
                }
            }
            finally
            {
                IsSessionStarted    = false;
                IsPublishingStarted = false;
            }
        }
 private void ClearSubscriber(OTSubscriber subscriberKit)
 {
     using (subscriberKit)
     {
         subscriberKit.SubscribeToAudio         = false;
         subscriberKit.SubscribeToVideo         = false;
         subscriberKit.DidConnectToStream      -= OnSubscriberConnected;
         subscriberKit.DidDisconnectFromStream -= OnSubscriberDisconnected;
         subscriberKit.VideoDataReceived       -= OnSubscriberVideoDataReceived;
         subscriberKit.VideoEnabled            -= OnSubscriberVideoEnabled;
         subscriberKit.VideoDisabled           -= OnSubscriberVideoDisabled;
     }
 }
        /**
         * Instantiates a subscriber for the given stream and asynchronously begins the
         * process to begin receiving A/V content for this stream. Unlike doPublish,
         * this method does not add the subscriber to the view hierarchy. Instead, we
         * add the subscriber only after it has connected and begins receiving data.
         */
        public void DoSubscribe(OTStream stream)
        {
            _subscriber = new OTSubscriber(stream, new SubscriberDelegate(this));

            OTError error;

            _session.Subscribe(_subscriber, out error);

            if (error != null)
            {
                this.RaiseOnError(error.Description);
            }
        }
            public override void DidConnectToStream(OTSubscriber subscriber)
            {
                InvokeOnMainThread(() => {
                    _this._subscriber.View.Frame = new RectangleF(0, 0, (float)_this.View.Frame.Width, (float)_this.View.Frame.Height);
                    _this.SubscriberView.AddSubview(_this._subscriber.View);

                    // In this case, we are sending a signal to a specific peer
                    // using its connection as the connection parameter.
                    OTError error;
                    _this._session.SignalWithType("PrivateSignal",
                                                  "Hello Subscriber",
                                                  subscriber.Stream.Connection,
                                                  out error);
                });
            }
        private void Subscribe(OTStream stream)
        {
            lock (_syncRoot)
            {
                if (_subscriber != null || _session == null)
                {
                    return;
                }

                OTError error;
                _subscriber = new OTSubscriber(stream, null);
                SubscribeForSubscriberEvents(_subscriber);
                _session.Subscribe(_subscriber, out error);
            }
        }
        void OnStreamCreated(object sender, OTSessionDelegateStreamEventArgs e)
        {
            lock (syncLock)
            {
                if (Subscriber != null || Session == null)
                {
                    return;
                }

                Subscriber = new OTSubscriber(e.Stream, null);
                HandleSubscriptionEvents();

                Session.Subscribe(Subscriber, out var error);
            }
        }
 private void OnSubscriberConnectionChanged(bool isConnected, OTSubscriber subscriberKit)
 {
     lock (_locker)
     {
         if (subscriberKit?.Stream != null)
         {
             if (Subscribers.ContainsKey(subscriberKit.Stream.StreamId))
             {
                 SubscriberUpdated?.Invoke(this, new OpenTokUserUpdatedEventArgs(subscriberKit.Stream.StreamId));
                 IsSubscriberConnected    = isConnected;
                 IsSubscriberVideoEnabled = subscriberKit.Stream?.HasVideo ?? false;
                 PublisherUpdated?.Invoke(this, new OpenTokUserUpdatedEventArgs(PublisherKit.Session.SessionId));
             }
         }
     }
 }
Beispiel #17
0
            public override void DidConnectToStream(OTSubscriber subscriber)
            {
                InvokeOnMainThread(() => {
                    var subView   = _this._subscriber.View;
                    subView.Frame = new RectangleF(0, 0, 1, 1);

                    _this.AddSubview(subView);
                    subView.TranslatesAutoresizingMaskIntoConstraints = false;
                    _this.AddConstraints(new NSLayoutConstraint[] {
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Top, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Bottom, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Leading, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Trailing, 1, 0)
                    });
                    _this.BringSubviewToFront(subView);
                    _this.BringSubviewToFront(_this._publisher.View);
                });
            }
        private void SubscribeForSubscriberEvents(OTSubscriber subscriber, bool subscribe = true)
        {
            if (subscriber == null)
            {
                return;
            }

            if (subscribe)
            {
                subscriber.DidConnectToStream += OnSubscriberDidConnectToStream;
                subscriber.VideoDataReceived  += OnSubscriberVideoDataReceived;
                subscriber.VideoEnabled       += OnSubscriberVideoEnabled;
            }
            else
            {
                subscriber.DidConnectToStream -= OnSubscriberDidConnectToStream;
                subscriber.VideoDataReceived  -= OnSubscriberVideoDataReceived;
                subscriber.VideoEnabled       -= OnSubscriberVideoEnabled;
            }
        }
        private void OnStreamCreated(object sender, OTSessionDelegateStreamEventArgs e)
        {
            lock (_locker)
            {
                if (Session == null || SubscriberKit != null)
                {
                    return;
                }

                SubscriberKit = new OTSubscriber(e.Stream, null);
                SubscriberKit.SubscribeToVideo    = IsVideoSubscriptionEnabled;
                SubscriberKit.SubscribeToVideo    = IsAudioSubscriptionEnabled;
                SubscriberKit.DidConnectToStream += OnSubscriberDidConnectToStream;
                SubscriberKit.VideoDataReceived  += OnSubscriberVideoDataReceived;
                SubscriberKit.VideoEnabled       += OnSubscriberVideoEnabled;
                SubscriberKit.VideoDisabled      += OnSubscriberVideoDisabled;

                OTError error;
                Session.Subscribe(SubscriberKit, out error);
            }
        }
 public override void DidConnectToStream(OTSubscriber subscriber)
 {
 }
 public override void DidFail(OTSubscriber subscriber, OTError error)
 {
     Debug.WriteLine("Subscriber {0} DidFailWithError {1}", subscriber.Stream.StreamId, error);
     var msg = string.Format("There was an error subscribing to stream {0}", subscriber.Stream.StreamId);
     _this.ShowAlert(msg);
 }
            public override void DidConnectToStream(OTSubscriber subscriber)
            {
                InvokeOnMainThread (() => {
                    var subView = _this._subscriber.View;
                    subView.Frame = new RectangleF (0, 0, 1, 1);

                    _this.AddSubview (subView);
                    subView.TranslatesAutoresizingMaskIntoConstraints = false;
                    _this.AddConstraints(new NSLayoutConstraint[] {
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Top, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Bottom, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Leading, 1, 0),
                        NSLayoutConstraint.Create(subView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, _this, NSLayoutAttribute.Trailing, 1, 0)
                    });
                    _this.BringSubviewToFront (subView);
                    _this.BringSubviewToFront(_this._publisher.View);
                });
            }
        private void DoSubscribe(OTStream stream)
        {
            _subscriberDelegate = new SubscriberDelegate (this);
            _subscriber = new OTSubscriber(stream, _subscriberDelegate);

            OTError error;

            _session.Subscribe(_subscriber, out error);

            if (error != null)
            {
                this.RaiseOnError(error.Description);
            }
        }
 private void UpdateSubscriber()
 {
     foreach(var streamId in _session.Streams)
     {
         var stream = (OTStream)streamId.Value;
         if (!Equals(stream.Connection.ConnectionId, _session.Connection.ConnectionId))
         {
             _subscriber = new OTSubscriber(stream, new SubDelegate(this));
             break;
         }
     }
 }
            public override void DidConnectToStream(OTSubscriber subscriber)
            {
                InvokeOnMainThread (() => {
                    _this._subscriber.View.Frame = new RectangleF (0, 0, (float)_this.View.Frame.Width, (float)_this.View.Frame.Height);
                    _this.SubscriberView.AddSubview (_this._subscriber.View);

                    // In this case, we are sending a signal to a specific peer
                    // using its connection as the connection parameter.
                    OTError error;
                    _this._session.SignalWithType("PrivateSignal",
                        "Hello Subscriber",
                        subscriber.Stream.Connection,
                        out error);
                });
            }
 public override void DidFailWithError(OTSubscriber subscriber, OTError error)
 {
     var msg = String.Format("SubscriberDelegate:DidFailWithError: Stream {0}, Error: {1}", subscriber.Stream.StreamId, error.Description);
     _this.RaiseOnError(msg);
 }
        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;
                });
            }
        }
 private void CleanupSubscriber()
 {
     if (_subscriber != null)
     {
         _subscriber.View.RemoveFromSuperview();
         _subscriber.Delegate = null;
         _subscriber.Dispose();
         _subscriber = null;
         _subscriberDelegate = 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();
                }
            }
        }
 public override void DidConnectToStream(OTSubscriber subscriber)
 {
 }