Пример #1
0
        private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams)
        {
            Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State);

            Task.Run(() =>
            {
                try { call.Answer(); }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "Answer failed");
                    sCompleted.Set();
                    return;
                }

                try
                {
                    call.OnPlayStateChange += OnCallPlayStateChange;
                    call.PlayTTS(
                        new CallMedia.TTSParams()
                    {
                        Text = "i'm a little teapot",
                    });
                }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "PlayTTS failed");
                    sCompleted.Set();
                    return;
                }
            });
        }
Пример #2
0
 private static void OnCallRecordStateChange(CallingAPI api, Call call, CallEventParams.RecordParams recordParams)
 {
     Logger.LogInformation("OnCallRecordStateChange: {0}, {1} for {2}, {3}", call.CallID, call.State, recordParams.ControlID, recordParams.State);
     if (recordParams.State == CallEventParams.RecordParams.RecordState.finished || recordParams.State == CallEventParams.RecordParams.RecordState.no_input)
     {
         Logger.LogInformation("OnCallRecordStateChange: {0}, {1}, {2}", recordParams.Duration, recordParams.Size, recordParams.URL);
         sSuccessful = true;
         sCompleted.Set();
     }
 }
Пример #3
0
 private static void OnCallPlayStateChange(CallingAPI api, Call call, CallEventParams.PlayParams playParams)
 {
     Logger.LogInformation("OnCallPlayStateChange: {0}, {1} for {2}, {3}", call.CallID, call.State, playParams.ControlID, playParams.State);
     if (playParams.State == CallEventParams.PlayParams.PlayState.finished)
     {
         Logger.LogInformation("OnCallPlayStateChange completed successfully");
         sSuccessful = true;
         sCompleted.Set();
     }
 }
Пример #4
0
        private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams)
        {
            Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State);

            Task.Run(() =>
            {
                try { call.Answer(); }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "Answer failed");
                    sCompleted.Set();
                    return;
                }

                Thread.Sleep(1000);

                try
                {
                    call.OnCollect += OnCallCollect;

                    PlayTTSAndCollectAction action = call.PlayTTSAndCollect(
                        new CallMedia.TTSParams()
                    {
                        Text = "i'm a little teapot, short and stout. Here is my handle, here is my spout.",
                    },
                        new CallCollect()
                    {
                        Digits = new CallCollect.DigitsParams()
                        {
                            Max = 1
                        }
                    });

                    Thread.Sleep(2000);
                    action.Stop();

                    call.PlayTTS(new CallMedia.TTSParams()
                    {
                        Text = "Stopped"
                    });
                    Thread.Sleep(1000);

                    call.Hangup();

                    sSuccessful = true;
                    sCompleted.Set();
                }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "PlayTTSAndCollect failed");
                    sCompleted.Set();
                    return;
                }
            });
        }
Пример #5
0
        private void Call_OnPlayStateChange(CallingAPI api, Call call, CallEventParams.PlayParams playParams)
        {
            switch (playParams.State)
            {
            case CallEventParams.PlayParams.PlayState.error:
            case CallEventParams.PlayParams.PlayState.finished:
                Call.OnPlayStateChange -= Call_OnPlayStateChange;
                mFinished.SetResult(true);
                break;

            default: break;
            }
        }
Пример #6
0
        private void Call_OnRecordStateChange(CallingAPI api, Call call, CallEventParams.RecordParams recordParams)
        {
            switch (recordParams.State)
            {
            case CallEventParams.RecordParams.RecordState.finished:
            case CallEventParams.RecordParams.RecordState.no_input:
                Call.OnRecordStateChange -= Call_OnRecordStateChange;
                mFinished.SetResult(true);
                break;

            default: break;
            }
        }
Пример #7
0
        private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams)
        {
            Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State);

            Task.Run(() =>
            {
                try { call.Answer(); }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "Answer failed");
                    sCompleted.Set();
                }
            });
        }
Пример #8
0
        private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams)
        {
            // This is called when the client is informed that a new inbound call has been created
            Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State);

            // Answer the inbound call
            try { call.Answer(); }
            catch (Exception exc)
            {
                Logger.LogError(exc, "CallAnswer failed");
                return;
            }

            Call callB = null;

            try
            {
                // The top level list of the devices represents entries that will be called in serial,
                // one at a time.  The inner list of devices represents a set of devices to call in
                // parallel with each other.  Ultimately only one device wins by answering first.
                callB = call.Connect(new List <List <CallDevice> >
                {
                    new List <CallDevice>
                    {
                        new CallDevice
                        {
                            Type       = CallDevice.DeviceType.phone,
                            Parameters = new CallDevice.PhoneParams
                            {
                                ToNumber   = sCallToNumber,
                                FromNumber = sCallFromNumber,
                            }
                        }
                    }
                });
            }
            catch (Exception exc)
            {
                Logger.LogError(exc, "Connect failed");
                return;
            }

            // Wait upto 15 seconds for the connected side to end then hangup
            callB.WaitForState(TimeSpan.FromSeconds(15), CallState.ended);
            call.Hangup();
        }
Пример #9
0
        private static void Client_OnReady(Client client)
        {
            // This is called when the client has established a new session, this is NOT called when a session is restored
            Logger.LogInformation("OnReady");

            // Create the api associating it to the client for transport
            sCallingAPI = new CallingAPI(client);

            // Hook the callback that occurs when an inbound call is created
            sCallingAPI.OnCallReceived += CallingAPI_OnCallReceived;

            // Request that the inbound calls for the given context reach this client
            try { sCallingAPI.Receive(sCallReceiveContext); }
            catch (Exception exc)
            {
                Logger.LogError(exc, "CallReceive failed");
                return;
            }
        }
Пример #10
0
 private static void OnCallCollect(CallingAPI api, Call call, CallEventParams.CollectParams collectParams)
 {
     Logger.LogInformation("OnCallCollectResult: {0}, {1} for {2}, {3}", call.CallID, call.State, collectParams.ControlID, collectParams.Result.Type);
 }
Пример #11
0
 private static void CallingAPI_OnCallCreated(CallingAPI api, Call call)
 {
     Logger.LogInformation("OnCallCreated: {0}, {1}", call.CallID, call.State);
 }
Пример #12
0
        private static void Client_OnReady(Client client)
        {
            // This is called when the client has established a new session, this is NOT called when a session is restored
            Logger.LogInformation("OnReady");

            // Create the api associating it to the client for transport
            sCallingAPI = client.Calling;

            Task.Run(() =>
            {
                CallSetup(
                    "Human",
                    sCallToHumanNumber,
                    sRunHuman,
                    sHumanCompleted,
                    OnCallDetectHuman,
                    () => sHumanSuccessful = true,
                    new CallDetect()
                {
                    Type       = CallDetect.DetectType.machine,
                    Parameters = new CallDetect.MachineParams()
                    {
                    },
                });

                CallSetup(
                    "Machine",
                    sCallToMachineNumber,
                    sRunMachine,
                    sMachineCompleted,
                    OnCallDetectMachine,
                    () => sMachineSuccessful = true,
                    new CallDetect()
                {
                    Type       = CallDetect.DetectType.machine,
                    Parameters = new CallDetect.MachineParams()
                    {
                    },
                });

                CallSetup(
                    "Fax",
                    sCallToFaxNumber,
                    sRunFax,
                    sFaxCompleted,
                    OnCallDetectFax,
                    () => sFaxSuccessful = true,
                    new CallDetect()
                {
                    Type       = CallDetect.DetectType.fax,
                    Parameters = new CallDetect.FaxParams()
                    {
                    },
                });

                CallSetup(
                    "Digit",
                    sCallToDigitNumber,
                    sRunDigit,
                    sDigitCompleted,
                    OnCallDetectDigit,
                    () => sDigitSuccessful = true,
                    new CallDetect()
                {
                    Type       = CallDetect.DetectType.digit,
                    Parameters = new CallDetect.DigitParams()
                    {
                    },
                });
            });
        }
Пример #13
0
 internal PhoneCall(CallingAPI api, string temporaryCallID)
     : base(api, temporaryCallID)
 {
 }
Пример #14
0
 internal PhoneCall(CallingAPI api, string nodeID, string callID)
     : base(api, nodeID, callID)
 {
 }
Пример #15
0
 protected Call(CallingAPI api, string temporaryCallID)
 {
     mLogger      = SignalWireLogging.CreateLogger <Client>();
     mAPI         = api;
     mTemporaryID = temporaryCallID;
 }
Пример #16
0
 private void Call_OnCollect(CallingAPI api, Call call, CallEventParams.CollectParams collectParams)
 {
     Call.OnCollect -= Call_OnCollect;
     mFinished.SetResult(true);
 }