예제 #1
0
        private SIPDialogue SendCallRequest(string forwardingNumber, string destinationNumber, int phoneType, int waitForCallbackTimeout, string contentType, string body)
        {
            try
            {
                int callbackTimeout = (waitForCallbackTimeout <MIN_CALLBACK_TIMEOUT || waitForCallbackTimeout> MAX_CALLBACK_TIMEOUT) ? WAIT_FOR_CALLBACK_TIMEOUT : waitForCallbackTimeout;

                CallbackWaiter callbackWaiter = new CallbackWaiter(m_username, CallbackWaiterEnum.GoogleVoice, forwardingNumber, MatchIncomingCall);
                m_callManager.AddWaitingApplication(callbackWaiter);

                string callData = "outgoingNumber=" + Uri.EscapeDataString(destinationNumber) + "&forwardingNumber=" + Uri.EscapeDataString(forwardingNumber) +
                                  "&subscriberNumber=undefined&remember=0&_rnr_se=" + Uri.EscapeDataString(m_rnrKey) + "&phoneType=" + phoneType;
                //logger.Debug("call data=" + callData + ".");

                // Build the call request.
                HttpWebRequest callRequest = (HttpWebRequest)WebRequest.Create(VOICE_CALL_URL);
                callRequest.ConnectionGroupName = "call";
                callRequest.CookieContainer     = m_cookies;
                callRequest.Method        = "POST";
                callRequest.ContentType   = "application/x-www-form-urlencoded;charset=utf-8";
                callRequest.ContentLength = callData.Length;
                callRequest.GetRequestStream().Write(Encoding.UTF8.GetBytes(callData), 0, callData.Length);
                callRequest.Timeout = HTTP_REQUEST_TIMEOUT * 1000;

                HttpWebResponse response       = (HttpWebResponse)callRequest.GetResponse();
                HttpStatusCode  responseStatus = response.StatusCode;
                response.Close();
                if (responseStatus != HttpStatusCode.OK)
                {
                    throw new ApplicationException("The call request failed with a " + responseStatus + " response.");
                }
                else
                {
                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Google Voice Call to " + destinationNumber + " initiated, callback #" + forwardingNumber + ", phone type " + phoneType + ", timeout " + callbackTimeout + "s.", m_username));
                }

                if (m_waitForCallback.WaitOne(callbackTimeout * 1000))
                {
                    if (!m_hasBeenCancelled)
                    {
                        Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Google Voice Call callback received.", m_username));
                        return(m_callbackCall.Answer(contentType, body, null, SIPDialogueTransferModesEnum.Default));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Google Voice Call timed out waiting for callback.", m_username));
                    CancelCall();
                    return(null);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception GoogleVoiceCall SendCallRequest. " + excp.Message);
                throw;
            }
        }
        public void CallAnswered(SIPResponseStatusCodesEnum answeredStatus, string reasonPhrase, string toTag, string[] customHeaders, string answeredContentType, string answeredBody, SIPDialogue answeredDialogue, SIPDialogueTransferModesEnum uasTransferMode)
        {
            try
            {
                if (m_sipServerUserAgent != null && !m_isAnswered)
                {
                    if (!m_sipServerUserAgent.IsInvite)
                    {
                        m_isAnswered = true;
                        Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Answering client call with a response status of " + (int)answeredStatus + ".", Owner));
                        m_sipServerUserAgent.AnswerNonInvite(answeredStatus, reasonPhrase, customHeaders, answeredContentType, answeredBody);
                    }
                    else
                    {
                        m_isAnswered = true;
                        Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Answering client call with a response status of " + (int)answeredStatus + ".", Owner));

                        SIPDialogue uasDialogue = m_sipServerUserAgent.Answer(answeredContentType, answeredBody, toTag, answeredDialogue, uasTransferMode);

                        if (m_sipServerUserAgent.IsB2B == false && answeredDialogue != null)
                        {
                            if (uasDialogue != null)
                            {
                                // Duplicate switchboard dialogue settings.
                                //uasDialogue.SwitchboardDescription = answeredDialogue.SwitchboardDescription;
                                //uasDialogue.SwitchboardCallerDescription = answeredDialogue.SwitchboardCallerDescription;
                                uasDialogue.SwitchboardLineName = answeredDialogue.SwitchboardLineName;
                                uasDialogue.CRMPersonName       = answeredDialogue.CRMPersonName;
                                uasDialogue.CRMCompanyName      = answeredDialogue.CRMCompanyName;
                                uasDialogue.CRMPictureURL       = answeredDialogue.CRMPictureURL;
                                uasDialogue.SwitchboardOwner    = answeredDialogue.SwitchboardOwner;

                                // Record the now established call with the call manager for in dialogue management and hangups.
                                CreateBridge_External(uasDialogue, answeredDialogue, m_dialPlan.Owner);
                            }
                            else
                            {
                                logger.Warn("Failed to get a SIPDialogue from UAS.Answer.");
                            }
                        }
                    }
                }
                else
                {
                    logger.Warn("DialPlanContext CallAnswered fired on already answered call.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception DialPlanContext CallAnswered. " + excp.Message);
            }
            finally
            {
                DialPlanExecutionFinished();
            }
        }