private void RegisterVideoEvents()
        {
            // Wire up event handlers for VideoRoomDelegate
            roomDelegate = new VideoRoomDelegate();
            roomDelegate.OnDidConnectToRoom        += HandleOnDidConnectToRoom;
            roomDelegate.OnParticipantDidConnect   += HandleOnParticipantDidConnect;
            roomDelegate.OnParticipantDisconnected += HandleOnParticipantDisconnected;

            // Wire up event handlers for VideoParticipantDelegate
            participantDelegate = new VideoParticipantDelegate();
        }
Example #2
0
        public async override void ViewDidLoad()
        {
            //this.View.Frame = new CoreGraphics.CGRect (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 64);
            base.ViewDidLoad();
            // LocalMedia represents the collection of tracks that we are sending to other Participants from our VideoClient.
            localMedia = new LocalMedia();
            this.NavigationController.NavigationBar.Translucent = false;
            this.NavigationController.NavigationBar.Hidden      = false;
            this.View.BackgroundColor = UIColor.FromRGB(0, 128, 64);
            messageLabel               = new UILabel();
            messageLabel.Frame         = new CGRect(10, 20, UIScreen.MainScreen.Bounds.Width, 20);
            messageLabel.TextColor     = UIColor.White;
            messageLabel.TextAlignment = UITextAlignment.Center;
            messageLabel.Font          = UIFont.SystemFontOfSize(12);
            View.Add(messageLabel);

            connectionLabel               = new UILabel();
            connectionLabel.Frame         = new CGRect(10, messageLabel.Frame.GetMaxY() + 100, UIScreen.MainScreen.Bounds.Width, 30);
            connectionLabel.TextColor     = UIColor.White;
            connectionLabel.Text          = "Connecting...";
            connectionLabel.TextAlignment = UITextAlignment.Center;
            connectionLabel.Font          = UIFont.SystemFontOfSize(16);
            View.Add(connectionLabel);

            micButton       = new UIButton();
            micButton.Frame = new CGRect(10, UIScreen.MainScreen.Bounds.Height - 64 - 40, 80, 40);
            micButton.SetTitle("Mute", UIControlState.Normal);
            micButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            micButton.BackgroundColor = UIColor.FromRGB(226, 29, 37);
            micButton.Font            = UIFont.SystemFontOfSize(12);
            View.Add(micButton);

            disconnectButton       = new UIButton();
            disconnectButton.Frame = new CGRect(UIScreen.MainScreen.Bounds.Width / 2 - 20, messageLabel.Frame.GetMaxY() + 20, 40, 40);
            disconnectButton.SetImage(UIImage.FromFile("HangupCall.png"), UIControlState.Normal);
            View.Add(disconnectButton);

            previewView                 = new UIView();
            previewView.Frame           = new CGRect(UIScreen.MainScreen.Bounds.Width - 160, UIScreen.MainScreen.Bounds.Height - 64 - 200, 150, 190);
            previewView.BackgroundColor = UIColor.Clear;
            View.Add(previewView);

            micButton.TouchUpInside += MicButton_TouchUpInside;
            // Wire up event handlers for VideoRoomDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            roomDelegate = new VideoRoomDelegate();
            roomDelegate.OnDidConnectToRoom        += HandleOnDidConnectToRoom;
            roomDelegate.OnDisconnectedWithError   += HandleOnDisconnectedWithError;
            roomDelegate.OnRoomFailedToConnect     += HandleOnRoomFailedToConnect;
            roomDelegate.OnParticipantDidConnect   += HandleOnParticipantDidConnect;
            roomDelegate.OnParticipantDisconnected += HandleOnParticipantDidConnect;

            // Wire up event handlers for VideoParticipantDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            participantDelegate = new VideoParticipantDelegate();
            participantDelegate.OnAddedVideoTrack   += HandleOnAddedVideoTrack;
            participantDelegate.OnRemovedVideoTrack += HandleOnRemovedVideoTrack;
            participantDelegate.OnAddedAudioTrack   += HandleOnAddedAudioTrack;
            participantDelegate.OnRemovedAudioTrack += HandleOnRemovedAudioTrack;
            participantDelegate.OnEnabledTrack      += HandleOnEnabledTrack;
            participantDelegate.OnDisabledTrack     += HandleOnDisabledTrack;

            if (IsSimulator)
            {
                //previewView.RemoveFromSuperview ();
            }
            else
            {
                // Preview our local camera track in the local video preview view.
                StartPreview();
            }
            // Disconnect and mic button will be displayed when client is connected to a room.
            disconnectButton.Hidden = false;
            micButton.Hidden        = false;

            if (accessToken == null)
            {
                LogMessage("Fetching an access token.");

                try {
                    var token = await Utils.GetTokenAsync(TokenUrl);

                    if (token != null)
                    {
                        accessToken = token;
                        DoConnect();
                    }
                    else
                    {
                        LogMessage("Error retrieving the access token.");
                        ShowRoomUI(false);
                    }
                } catch (Exception e) {
                    LogMessage($"Exception thrown when fetching access token: {e}");
                }
            }
            else
            {
                DoConnect();
            }

            // Should dispose of this.
            //roomTextField.ShouldReturn += (textField) => { ConnectButtonPressed (textField); return true; };
        }