示例#1
0
 /// <summary>
 /// 电话机摘机处理
 /// </summary>
 public static void phoneHook()
 {
     if (VoipHelper.callState == VoipHelper.telState.IN)
     {
         Utils.WriteLog(string.Format("电话机摘机"));
         VoipHelper.StopVoice(VoipHelper.playHandle);
         ConstDefault.isMissed = false;
         VoipHelper.OffOnHook(1);
     }
 }
示例#2
0
 /// <summary>
 /// 远程挂机
 /// </summary>
 public static void remoteHang()
 {
     Utils.WriteLog(string.Format("远程挂机"));
     VoipHelper.playHandle = VoipHelper.StopVoice(VoipHelper.playHandle);
     ConstDefault.isBySelf = false;
     ConstDefault.retToJs remoteHang = new Tools.ConstDefault.retToJs();
     remoteHang.action = ConstDefault.LINE_IS_BUSYORHANGUP;
     Utils.resultToJavascript(remoteHang);
     MainWindow.form.Activate();
 }
示例#3
0
        /// <summary>
        /// 接收到来电号码
        /// </summary>
        /// <param name="phone"> 手机号码</param>
        public static void getCallID(string phone)
        {
            Utils.WriteLog(string.Format("获取到来电号码 ==>> {0}", phone));
            #region 号码小于7位屏蔽
            if (phone.Length < 7)
            {
                Utils.WriteLog(string.Format("来电小于7位号码  号码为 ==>> {0}", phone));
                VoipHelper.StopVoice(VoipHelper.playHandle);
                VoipHelper.OffOnHook(0);
                return;
            }
            #endregion
            if (ConstDefault.isCalling)
            {
                return;
            }
            ConstDefault.isCalling = true;
            ConstDefault.isMissed  = true;
            VoipHelper.callState   = VoipHelper.telState.IN;
            MainWindow.form.Activate();
            MainWindow.form.Topmost = true;
            VoipHelper.playHandle   = VoipHelper.PlayVoice(VoipHelper.callBell);

            VoipHelper.callId = Utils.GetCallId();

            ConstDefault.retToJs getCallId = new ConstDefault.retToJs();
            getCallId.action      = ConstDefault.PHONE_RINGING;
            getCallId.phoneNumber = phone;
            Utils.resultToJavascript(getCallId);

            Utils.SetTimeOut(1000 * 30, new Action(() =>
            {
                MainWindow.form.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                                  (ThreadStart) delegate()
                {
                    if (ConstDefault.isMissed) // 如果是未接,30秒后 挂断。 因为 停止呼入时间有问题。
                    {
                        Utils.WriteLog(string.Format("来电30秒未处理"));
                        VoipHelper.StopVoice(VoipHelper.playHandle); // 单独挂断处理不行,因为有摘机才有挂机事件。
                        ConstDefault.isBySelf   = false;
                        ConstDefault.isCalling  = false;
                        MainWindow.form.Topmost = false;
                        VoipHelper.lineToSpk(0);
                        ConstDefault.retToJs resultToJs = new ConstDefault.retToJs();
                        resultToJs.action = ConstDefault.PHONE_IDEL;
                        Utils.resultToJavascript(resultToJs);
                    }
                }
                                                  );
            }));
        }
示例#4
0
        /// <summary>
        /// 软摘机/挂机
        /// </summary>
        /// <param name="result">1摘机 0挂机</param>
        public static void enableHook(int result)
        {
            try
            {
                if (result == 1)//摘机
                {
                    Utils.WriteLog(string.Format("软摘机"));
                    VoipHelper.StopVoice(VoipHelper.playHandle);
                    VoipHelper.lineToSpk(1);
                    VoipHelper.domicToLine(1);
                    if (VoipHelper.callState == VoipHelper.telState.IN)
                    {
                        ConstDefault.isMissed = false;

                        ConstDefault.retToJs resultToJs = new ConstDefault.retToJs();
                        resultToJs.action = ConstDefault.PHONE_CALLING;
                        Utils.resultToJavascript(resultToJs);
                    }
                    else
                    {
                        ConstDefault.retToJs resultToJs = new ConstDefault.retToJs();
                        resultToJs.action      = ConstDefault.PHONE_DIALING;
                        resultToJs.phoneNumber = VoipHelper.callNumber;
                        Utils.resultToJavascript(resultToJs);
                    }
                }
                else //挂机
                {
                    Utils.WriteLog(string.Format("软挂机"));
                    VoipHelper.lineToSpk(0);
                    VoipHelper.offHookCallNumber = null;
                    VoipHelper.playHandle        = VoipHelper.StopVoice(VoipHelper.playHandle);
                    ConstDefault.isBySelf        = true;
                    ConstDefault.isCalling       = false;

                    if (VoipHelper.callState == VoipHelper.telState.IN)
                    {
                        MainWindow.form.Topmost = false;
                    }
                    if (VoipHelper.isHookError)
                    {
                        VoipHelper.isHookError = false;
                        return;
                    }

                    ConstDefault.retToJs resultToJs = new ConstDefault.retToJs();
                    resultToJs.action = ConstDefault.PHONE_IDEL;
                    Utils.resultToJavascript(resultToJs);
                }
            }
            catch (Exception err)
            {
                VoipHelper.isHookError = true;
                ConstDefault.retToJs errToJs = new ConstDefault.retToJs();
                errToJs.action = ConstDefault.PHONE_IDEL;
                Utils.resultToJavascript(errToJs);
                VoipHelper.OffOnHook(0);
                Utils.WriteLog(string.Format("软摘软挂错误==>>{0}", err));
                return;
            }
        }