Example #1
0
        internal void StartVideo()
        {
            //starts a video call or the video stream in a audio call
            AsyncCallback callback = new AsyncOperationHandler(videoChannel.EndStart).Callback;

            try
            {
                videoChannel.BeginStart(callback, null);
            }
            catch (LyncClientException lyncClientException)
            {
                Console.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (Utilities.IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }
Example #2
0
        //*****************************************************************************************
        //                              VideoChannel related actions
        //
        // The video channel action will behave differently depending on whether the audio is already
        // connected.
        //
        // If audio is not connected, starting video is equivalent to connecting the modality. If the
        // conversation already has audio, starting video will start the outgoing video stream. The
        // other participants in the conversation also need to start their own video.
        //
        // Stopping the video channel will stop both outgoing and incoming video. It will remove video
        // from the conversation.
        //
        //*****************************************************************************************

        /// <summary>
        /// Starts the video channel: VideoChannel.BeginStart()
        /// </summary>
        private void StartVideo()
        {
            _log.Debug("StartVideo");

            if (!_videoChannel.CanInvoke(ChannelAction.Start))
            {
                _log.Debug("StartVideo  can't  start");
                return;
            }

            //starts a video call or the video stream in a audio call
            AsyncCallback callback = new AsyncOperationHandler(_videoChannel.EndStart).Callback;

            try
            {
                _videoChannel.BeginStart(callback, null);
            }
            catch (LyncClientException lyncClientException)
            {
                Console.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (LyncModelExceptionHelper.IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    _log.ErrorException("Error: ", systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }
Example #3
0
        /// <summary>
        /// 启动视频
        /// </summary>
        /// <param name="conversationWindow"></param>
        public static void StartVideo(ConversationWindow conversationWindow)
        {
            try
            {
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    AVModality avModality = (AVModality)conversationWindow.Conversation.SelfParticipant.Modalities[ModalityTypes.AudioVideo];
                    if (avModality != null)
                    {
                        VideoChannel videoChannel = avModality.VideoChannel;

                        //object obV = videoChannel.InnerObject;
                        if (videoChannel != null)
                        {
                            if (videoChannel != null && videoChannel.CanInvoke(ChannelAction.Start))
                            {
                                videoChannel.BeginStart(null, null);
                            }

                            TimerJob.StartRun(new Action(() =>
                            {
                                if (videoChannel.State != ChannelState.Connecting)
                                {
                                    if (videoChannel != null && videoChannel.CanInvoke(ChannelAction.Start))
                                    {
                                        videoChannel.BeginStart(null, null);
                                    }
                                }
                            }), 1500);
                            LyncHelper.ExitFullScreen();
                            LyncHelper.FullScreen();
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(LyncHelper), ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// 会话加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            //查看是否已进入一个会议【倘若未进入会议,则直接进行拒绝,该逻辑有待斟酌】
            bool canOpenTheConversation = true;

            if (HasConferenceCallBack != null)
            {
                HasConferenceCallBack(new Action <bool>((hasConference) =>
                {
                    //if (hasConference)
                    //{
                    //    canOpenTheConversation = false;
                    //}
                }));
            }


            //子线程不可直接调用主线程的UI(需要通过异步委托的机制去执行)
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                try
                {
                    #region 响应会话

                    //获取发起人的会话模式
                    IDictionary <ModalityTypes, Modality> modalities = e.Conversation.Modalities;

                    //通知模式
                    //NotifyType notifyType = NotifyType.InstantMessage;

                    AVModality avModality = (AVModality)modalities[ModalityTypes.AudioVideo];

                    //视频通道
                    VideoChannel videoChannel = ((AVModality)modalities[ModalityTypes.AudioVideo]).VideoChannel;

                    //音频通道
                    AudioChannel audioChannel = ((AVModality)modalities[ModalityTypes.AudioVideo]).AudioChannel;
                    //IM类型
                    var instantMessage = modalities[ModalityTypes.InstantMessage];
                    //查看当前视频会话具体应用
                    if (videoChannel.State == ChannelState.Notified)
                    {
                        if (canOpenTheConversation)
                        {
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Accept();
                            //notifyType = NotifyType.Video;

                            TimerJob.StartRun(new Action(() =>
                            {
                                //判断是否可以执行该操作
                                if (videoChannel.CanInvoke(ChannelAction.Start))
                                {
                                    ////接受请求,开启摄像头
                                    videoChannel.BeginStart(null, null);
                                    //停止计时器
                                    timerAcept.Stop();
                                }
                            }), 500, out timerAcept);
                        }
                        else
                        {
                            //拒绝音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                            return;
                        }
                    }
                    //查看当前音频会话具体应用
                    else if (audioChannel.State == ChannelState.Notified)
                    {
                        if (canOpenTheConversation)
                        {
                            //接受音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Accept();
                            //notifyType = NotifyType.Autio;
                        }
                        else
                        {
                            //拒绝音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                        }
                    }
                    //IMM文本会话,查看是否为通知状态(避免与语音、视频通话相互之间发生冲突)
                    if (instantMessage.State == ModalityState.Notified || instantMessage.State == ModalityState.Connected)
                    {
                        if (canOpenTheConversation)
                        {
                            ((InstantMessageModality)modalities[ModalityTypes.InstantMessage]).Accept();

                            #region old solution

                            //if (e.Conversation.Participants.Count <= 2)
                            //{
                            //    //模仿鼠标点击
                            //    Win32API.SetCursorPos(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - 100, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - 160);
                            //    Win32API.mouse_event(Win32API.MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
                            //    Win32API.mouse_event(Win32API.MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
                            //}

                            #endregion
                        }
                        else
                        {
                            ((InstantMessageModality)modalities[ModalityTypes.InstantMessage]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                        }
                    }

                    #endregion

                    #region 设置窗体位置和尺寸

                    //获取会话窗体
                    ConversationWindow window = null;

                    //获取会话窗体
                    window = ConversationCodeEnterEntity.lyncAutomation.GetConversationWindow(e.Conversation);
                    window.NeedsSizeChange -= window_NeedsSizeChange;
                    window.NeedsSizeChange += window_NeedsSizeChange;
                    if (MainConversationOutCallBack != null)
                    {
                        MainConversationOutCallBack(window);
                    }

                    //设置会话窗体的事件
                    SettingConversationWindowEvent(window);

                    #endregion

                    #region 共享设置

                    window.StateChanged -= MainConversation_StateChanged;
                    //状态更改
                    window.StateChanged += MainConversation_StateChanged;

                    //为共享做准备
                    TimerJob.StartRun(new Action(() =>
                    {
                        //连接共享
                        var modaly = ((ContentSharingModality)e.Conversation.SelfParticipant.Conversation.Modalities[ModalityTypes.ContentSharing]);

                        if (modaly.CanInvoke(ModalityAction.Accept))
                        {
                            modaly.Accept();
                        }

                        if (modaly.CanInvoke(ModalityAction.Connect))
                        {
                            modaly.BeginConnect(null, null);
                        }
                    }));

                    #endregion

                    #region 会话加载完成事件激活

                    if (ConversationAddCompleateCallBack != null)
                    {
                        ConversationAddCompleateCallBack();
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    LogManage.WriteLog(typeof(LyncHelper), ex);
                }
            }));
        }
        private static void Modality_Response_Connect(ConversationWindow conversationWindow)
        {
            try
            {
                var modalities = conversationWindow.Conversation.Modalities;

                //视频通道
                VideoChannel videoChannel = null;

                //音频通道
                AudioChannel audioChannel = null;

                AVModality avModality = ((AVModality)modalities[ModalityTypes.AudioVideo]);
                if (avModality != null)
                {
                    //视频通道
                    videoChannel = avModality.VideoChannel;
                    //音频通道
                    audioChannel = avModality.AudioChannel;
                }

                //视频
                if (videoChannel != null && videoChannel.State == ChannelState.Connecting)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            if (avModality.CanInvoke(ModalityAction.Accept))
                            {
                                //接受
                                avModality.Accept();

                                if (videoChannel.CanInvoke(ChannelAction.Start))
                                {
                                    videoChannel.BeginStart(null, null);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManage.WriteLog(typeof(LyncHelper), ex);
                        };
                    }));
                }
                //语音
                else if (audioChannel != null && audioChannel.State == ChannelState.Connecting)
                {
                    if (avModality.CanInvoke(ModalityAction.Accept))
                    {
                        //接受
                        avModality.Accept();
                    }
                }
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(LyncHelper), ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// 通道响应(accept)
        /// </summary>
        /// <param name="conversationWindow">会话窗体</param>
        private static void Modality_Response_Accept(ConversationWindow conversationWindow)
        {
            try
            {
                var modalities = conversationWindow.Conversation.Modalities;

                //视频通道
                VideoChannel videoChannel = null;

                //音频通道
                AudioChannel audioChannel = null;

                AVModality avModality = ((AVModality)modalities[ModalityTypes.AudioVideo]);
                if (avModality != null)
                {
                    //视频通道
                    videoChannel = avModality.VideoChannel;
                    //音频通道
                    audioChannel = avModality.AudioChannel;
                }

                //内容共享
                ContentSharingModality shareContent = (ContentSharingModality)modalities[ModalityTypes.ContentSharing];
                //程序共享
                ApplicationSharingModality applicationSharing = (ApplicationSharingModality)modalities[ModalityTypes.ApplicationSharing];


                //视频
                if (videoChannel != null && videoChannel.State == ChannelState.Receive)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            if (avModality.CanInvoke(ModalityAction.Accept))
                            {
                                //接受
                                avModality.Accept();

                                if (videoChannel.CanInvoke(ChannelAction.Start))
                                {
                                    videoChannel.BeginStart(null, null);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManage.WriteLog(typeof(LyncHelper), ex);
                        };
                    }));
                }
                //语音
                else if (audioChannel != null && audioChannel.State == ChannelState.Receive)
                {
                    if (avModality.CanInvoke(ModalityAction.Accept))
                    {
                        //接受
                        avModality.Accept();
                    }
                }
                //共享ppt、电子白板
                else if (shareContent != null && shareContent.State == ModalityState.Notified)
                {
                    shareContent.Accept();
                }
                //共享应用程序
                else if (applicationSharing != null && applicationSharing.State == ModalityState.Notified)
                {
                    applicationSharing.Accept();
                    if (AddContent_Type_CallBack != null)
                    {
                        AddContent_Type_CallBack(SharingType.Application);
                    }
                }
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(LyncHelper), ex);
            }
            finally
            {
            }
        }