private void OnUserEvent(object sender, UserStateChangedEvent e)
 {
     Debug.WriteLine("Got new user event for user with id: " + e.UserId);
     Debug.WriteLine("User just " + (e.IsConnected ? "joined" : "left") + "the scope");
     if (e.IsConnected)
     {
         Debug.WriteLine("User is " + (!e.AudioPublished ? "not" : "") + " publishing audio stream");
         Debug.WriteLine("User is " + (!e.VideoPublished ? "not" : "") + " publishing video stream");
         if (e.VideoPublished)
         {
             Debug.WriteLine("Creating renderer for remote user sink: " + e.VideoSinkId);
             var rOptions = new RenderOptions();
             rOptions.mirror = true;
             rOptions.sinkId = e.VideoSinkId;
             rOptions.filter = VideoScalingFilter.FAST_BILINEAR;
             var rHandler =
                 new ResultHandler <RenderingWidget>((_1) => AppendRenderer(RemoteVideoPanel, _1));
             Platform.renderSink(Platform.R <RenderingWidget>(rHandler,
                                                              GenErrHandler("renderSink")), rOptions);
         }
     }
     else
     {
     }
 }
        private void HandleToggleCamera(object sender, RoutedEventArgs e)
        {
            _currentVideoDevice++;
            _currentVideoDevice = _currentVideoDevice % _availableVideoDevices.Count;
            _videoDevId         = _availableVideoDevices[_currentVideoDevice];
            Debug.WriteLine("Switching to video device id: " + _videoDevId);

            Platform.Service.setVideoCaptureDevice(Platform.R <object>(MaybeStartLocalVideo, GenErrHandler("setVideoCaptureDevice")), _videoDevId);
        }
 private void MaybeStartLocalVideo(object nothing = null)
 {
     if (_localVideoStarted)
     {
         return;
     }
     Debug.WriteLine("Starting local video");
     Platform.Service.startLocalVideo(Platform.R <string>(OnLocalVideoStarted, GenErrHandler("startLocalVideo")));
     _localVideoStarted = true;
 }
        private void OnLocalVideoStarted(string sinkId)
        {
            Debug.WriteLine("Local video started. Creating renderer");
            var rOptions = new RenderOptions();

            rOptions.mirror = true;
            rOptions.sinkId = sinkId;
            rOptions.filter = VideoScalingFilter.FAST_BILINEAR;
            var rHandler =
                new ResultHandler <RenderingWidget>((_1) => AppendRenderer(LocalVideoPanel, _1));

            Platform.renderSink(Platform.R <RenderingWidget>(rHandler,
                                                             GenErrHandler("renderSink")), rOptions);

            Debug.WriteLine("Connecting to scope with id: " + ViewModel.Config.ScopeId);
            var connDescr = new ConnectionDescription();

            connDescr.autopublishAudio = true;
            connDescr.autopublishVideo = true;
            connDescr.scopeId          = ViewModel.Config.ScopeId;
            connDescr.url   = "174.127.76.172:443/" + ViewModel.Config.ScopeId;
            connDescr.token = ViewModel.UserId.ToString(CultureInfo.InvariantCulture);
            connDescr.lowVideoStream.maxBitRate = 64;
            connDescr.lowVideoStream.maxWidth   = 150;
            connDescr.lowVideoStream.maxHeight  = 150;
            connDescr.lowVideoStream.maxFps     = 5;
            connDescr.lowVideoStream.publish    = true;
            connDescr.lowVideoStream.receive    = true;

            connDescr.highVideoStream.maxBitRate = 512;
            connDescr.highVideoStream.maxWidth   = 150;
            connDescr.highVideoStream.maxHeight  = 150;
            connDescr.highVideoStream.maxFps     = 15;
            connDescr.highVideoStream.publish    = true;
            connDescr.highVideoStream.receive    = true;

            connDescr.authDetails = GenAuthDetails(ViewModel.Config.ScopeId, ViewModel.UserId);
            _connectedScopeId     = ViewModel.Config.ScopeId;
            Platform.Service.connect(GenGenericResponder <object>("connect"), connDescr);
            Platform.Service.publish(GenGenericResponder <object>("publishVideo"), _connectedScopeId,
                                     MediaType.VIDEO, null);

            ViewModel.VideoInitCompleted = true;
            Action a1 = () => InitVideoText.Visibility = Visibility.Collapsed;

            Application.Current.Dispatcher.BeginInvoke(a1, null);

            if (_availableVideoDevices.Count >= 2 && ToggleCamerasButton != null)
            {
                Action a = () => ToggleCamerasButton.Visibility = Visibility.Visible;
                System.Windows.Application.Current.Dispatcher.BeginInvoke(a, null);
            }
        }
 private void InitPlatform()
 {
     _localVideoStarted = false;
     try
     {
         Platform.init(_dispatcher);
     }
     catch (Exception)
     {
         MessageBox.Show("oops");
     }
     _isPlatformInitialized = true;
 }
        private void PostInitializePlatform()
        {
            Platform.Service.getVersion(Platform.R <string>(OnVersion, GenErrHandler("getVersion")));
            Platform.Service.setApplicationId(GenGenericResponder <object>("setApplicationId"), ViewModel.Config.AppId);
            Platform.Service.addServiceListener(GenGenericResponder <object>("addServiceListener"), _eDispatcher);

            Platform.Service.getAudioCaptureDeviceNames(
                Platform.R <Dictionary <string, string> >(OnAudioCaptureDevices));
            Platform.Service.getAudioOutputDeviceNames(
                Platform.R <Dictionary <string, string> >(OnAudioOutputDevices));
            Platform.Service.getVideoCaptureDeviceNames(
                Platform.R <Dictionary <string, string> >(OnVideoCaptureDevices));
        }
        private void OnLocalVideoChanged(string sinkId)
        {
            Debug.WriteLine("Local video changed. Creating renderer");
            var rOptions = new RenderOptions();

            rOptions.mirror = true;
            rOptions.sinkId = sinkId;
            rOptions.filter = VideoScalingFilter.FAST_BILINEAR;
            var rHandler =
                new ResultHandler <RenderingWidget>((_1) => AppendRenderer(LocalVideoPanel, _1));

            Platform.renderSink(Platform.R <RenderingWidget>(rHandler,
                                                             GenErrHandler("renderSink")), rOptions);
        }
        private void MaybeSwitchLocalVideo(object nothing = null)
        {
            if (!_localVideoStarted)
            {
                MaybeStartLocalVideo();
                return;
            }

            RemoveRenderer(LocalVideoPanel);

            ADL.Responder <object> wasStopped = new ResponderAdapter <object>(
                s => Platform.Service.startLocalVideo(Platform.R <string>(OnLocalVideoChanged, GenErrHandler("startLocalVideo"))), GenErrHandler("stopLocalVideo"));

            Platform.Service.stopLocalVideo(wasStopped);
        }
        private void OnADLInitStateChanged(object sender, InitStateChangedEvent e)
        {
            if (e.state == InitStateChangedEvent.InitState.ERROR)
            {
                if (_retryCount <= MaxRetryCount)
                {
                    _retryCount++;
                    Debug.WriteLine("Retying init");
                    Platform.init(_dispatcher);
                    return;
                }
                Debug.WriteLine("Failed to initialize platform. Cause: " + e.errMessage + "(" + e.errCode + ")");
                return;
            }
            InitializeCDOEventListener();

            Debug.WriteLine("Platform initialized. Proceeding with the initialization");

            PostInitializePlatform();
        }
        public void CleanupVideoConf()
        {
            if (_localVideoStarted)
            {
                if (ViewModel != null)
                {
                    ViewModel.VideoInitCompleted = false;
                }

                RemoveRenderer(LocalVideoPanel);
                RemoveRenderer(RemoteVideoPanel);

                if (Platform.Service != null)
                {
                    Platform.Service.stopLocalVideo(GenGenericResponder <object>("stopLocalVideo"));
                    Platform.Service.unpublish(GenGenericResponder <object>("unpublish"), _scopeId, MediaType.VIDEO);
                    Platform.Service.disconnect(GenGenericResponder <object>("disconnect"), _scopeId);
                }
                Thread.Sleep(1000);
                Platform.release();
                _scopeId = null;
            }
        }
 private void SwitchLocalVideo()
 {
     Platform.Service.setVideoCaptureDevice(Platform.R <object>(MaybeSwitchLocalVideo, GenErrHandler("setVideoCaptureDevice")), _videoDevId);
 }
 private Responder <T> GenGenericResponder <T>(string methodName)
 {
     return(Platform.R <T>(
                delegate(T sth) { Debug.WriteLine("Got successfull result of method call: " + methodName); }, GenErrHandler(methodName)));
 }