Example #1
0
        public void skype_CallStatus(Call call, TCallStatus status)
        {
            try
            {
                if (status == TCallStatus.clsRinging && call.Type != TCallType.cltOutgoingP2P)
                {
                    if (skypeCalls == 0)
                    {
                        try
                        {
                            call.Answer();
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            call.Finish();

                            skype.SendMessage(call.PartnerHandle, Properties.Settings.Default.waitMessage);
                        }
                        catch { }
                    }
                }
            }
            catch (InvalidCastException e)
            {
            }
        }
Example #2
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PlayAction actionPlay = call.PlayTTSAsync("I'm a little teapot, short and stout.  Here is my handle, here is my spout.", volume: 16);

            Thread.Sleep(1000);

            bool             increase         = false;
            PlayVolumeResult resultPlayVolume = null;

            while (!actionPlay.Completed)
            {
                increase         = !increase;
                resultPlayVolume = actionPlay.Volume(increase ? 8 : 0);
                if (!resultPlayVolume.Successful)
                {
                    break;
                }
                Thread.Sleep(3000);
            }

            call.Hangup();

            Successful = actionPlay.Result.Successful && resultPlayVolume.Successful;
            Completed.Set();
        }
Example #3
0
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                return;
            }

            // Request a random digit between 1 - 9
            string winning_number = RandomDigit();

            Console.WriteLine("Winning number is:" + winning_number);

            PromptResult guessResult = call.PromptTTS("Please, guess a number between one and nine.",
                                                      new CallCollect()
            {
                Digits = new CallCollect.DigitsParams
                {
                    Max = 1
                }
            }, "female");

            if (guessResult.Result == winning_number)
            {
                call.PlayTTS("Winner! Winner! Chicken Dinner! You guessed correctly.", "female");
            }
            else
            {
                call.PlayTTS("You do not pass go! You have guessed incorrectly.", "female");
            }

            call.PlayTTS("Thank you for playing, Good Bye!", "female");
            call.Hangup();
        }
Example #4
0
        /// <summary>
        /// Answer the current call.
        /// </summary>
        public void Answer()
        {
            // Create the call settings.
            CallSetting setting = new CallSetting(true);
            CallOpParam parm    = new CallOpParam(true);

            setting.AudioCount = 1;
            parm.Setting       = setting;
            parm.Code          = StatusCode.SC_OK;

            if (_call != null)
            {
                // Answer the call.
                _call.Answer(parm);
            }
        }
Example #5
0
        /// <summary>
        /// Notify application on incoming call.
        /// </summary>
        ///<param name="sender">The current sender.</param>
        /// <param name="e">The event parameter.</param>
        private void _voipManager_OnIncomingCall(object sender, OnIncomingCallParam e)
        {
            // Is valid call.
            if (e.CallId >= 0)
            {
                // Create a new call.
                Call            call     = _voipManager.CreateCall(e.CallId);
                Param.CallParam callInfo = new Param.CallParam(call, _voipManager.MediaManager, _recordFilename);

                // Create the call settings.
                CallSetting setting = new CallSetting(true);
                CallOpParam parm    = new CallOpParam(true);
                setting.AudioCount = 1;
                parm.Setting       = setting;

                // Continue ringing.
                parm.Code = StatusCode.SC_RINGING;
                call.Answer(parm);

                // Send a notification to the call.
                Param.OnIncomingCallParam param = new Param.OnIncomingCallParam();
                param.CallID     = e.CallId;
                param.Info       = e.RxData.Info;
                param.SrcAddress = e.RxData.SrcAddress;
                param.WholeMsg   = e.RxData.WholeMsg;
                param.Call       = callInfo;
                param.Contact    = FindContact(param);

                // Call the event handler.
                OnIncomingCall?.Invoke(this, param);
            }
        }
Example #6
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            // TODO call.Record
            RecordResult resultRecord = call.Record(new CallRecord
            {
                Audio = new CallRecord.AudioParams
                {
                    // Default parameters
                }
            });

            Logger.LogInformation("Recording {0} @ {1}", resultRecord.Successful ? "successful" : "unsuccessful", resultRecord.Url);

            HangupResult resultHangup = call.Hangup();

            Successful = resultRecord.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #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();
                    return;
                }

                try
                {
                    call.OnRecordStateChange += OnCallRecordStateChange;

                    call.Record(new CallRecord()
                    {
                        Audio = new CallRecord.AudioParams()
                        {
                            // Default parameters
                        }
                    });
                }
                catch (Exception exc)
                {
                    Logger.LogError(exc, "StartRecord failed");
                    sCompleted.Set();
                    return;
                }
            });
        }
Example #8
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;
                }
            });
        }
Example #9
0
        public Result Answer(string partialUsername = "")
        {
            if (calls == null)
            {
                return(Result.NoUserFound);
            }
            if (calls.Count == 0)
            {
                return(Result.NoUserFound);
            }
            if (partialUsername == "" || partialUsername == null)
            {
                calls.Last().Answer();
                return(Result.Successful);
            }
            else
            {
                Call foundcall = calls.Where(c => c.PartnerHandle.Contains(partialUsername)).FirstOrDefault();

                if (foundcall == null)
                {
                    return(Result.NoUserFound);
                }

                try
                {
                    foundcall.Answer();
                    return(Result.Successful);
                }
                catch
                {
                    return(Result.Failed);
                }
            }
        }
Example #10
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PlayAction actionPlayAudio = call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3");

            PlayAction actionPlayTTS = call.PlayTTSAsync("I'm a little teapot, short and stout.  Here is my handle, here is my spout.");

            while (!actionPlayTTS.Completed)
            {
                Thread.Sleep(500);
            }

            actionPlayAudio.Stop();

            call.Hangup();

            Successful = actionPlayAudio.Result.Successful && actionPlayTTS.Result.Successful;
            Completed.Set();
        }
Example #11
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PlayAction actionPlay = call.PlayTTSAsync("I'm a little teapot, short and stout.  Here is my handle, here is my spout.");
            bool       paused     = false;

            while (!actionPlay.Completed)
            {
                paused = !paused;
                if (paused)
                {
                    actionPlay.Pause();
                }
                else
                {
                    actionPlay.Resume();
                }
                Thread.Sleep(3000);
            }

            HangupResult resultHangup = call.Hangup();

            Successful = actionPlay.Result.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #12
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PromptResult resultPrompt = call.PromptTTS(
                "I'm a little teapot.",
                new CallCollect
            {
                Digits = new CallCollect.DigitsParams()
                {
                    Max = 1
                }
            });

            HangupResult resultHangup = call.Hangup();

            Successful = resultPrompt.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #13
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            Console.WriteLine("Answering");

            // Answer the incoming call, block until it's answered or an error occurs
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                // The call was not answered successfully, stop the consumer and bail out
                Stop();
                return;
            }

            call.PlayTTS("Welcome to SignalWire!");

            Console.WriteLine("Connecting");

            // Connect the inbound call to an outbound call
            ConnectResult resultConnect = call.Connect(new List <List <CallDevice> >
            {
                new List <CallDevice>
                {
                    new CallDevice
                    {
                        Type       = CallDevice.DeviceType.phone,
                        Parameters = new CallDevice.PhoneParams
                        {
                            ToNumber   = "+1555XXXXXXX",
                            FromNumber = "+1555XXXXXXX",
                        }
                    }
                }
            });

            if (resultConnect.Successful)
            {
                Console.WriteLine("Connected");
                resultConnect.Call.PlayTTS("Welcome!");

                // Wait upto 15 seconds for the connected side to hangup
                if (!resultConnect.Call.WaitForEnded()) //TimeSpan.FromSeconds(15)))
                {
                    // If the other side of the outbound call doesn't hang up, then hang it up
                    resultConnect.Call.Hangup();
                }
            }

            call.PlayTTS("Thank you for trying SignalWire!");

            // Hangup the inbound call
            call.Hangup();

            // Stop the consumer
            Stop();
        }
Example #14
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                // If answering fails, test stops
                Completed.Set();
            }
        }
Example #15
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;
                }
            });
        }
Example #16
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            UdpClient udpClient = new UdpClient(RTPPort);

            TapAction actionTap = call.TapAsync(
                new CallTap
            {
                Type       = CallTap.TapType.audio,
                Parameters = new CallTap.AudioParams
                {
                    Direction = CallTap.AudioParams.AudioDirection.both,
                }
            },
                new CallTapDevice
            {
                Type       = CallTapDevice.DeviceType.rtp,
                Parameters = new CallTapDevice.RTPParams
                {
                    Address = RTPAddr,
                    Port    = RTPPort,
                }
            }
                );

            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, RTPPort);

            byte[] data = udpClient.Receive(ref ipEndPoint);
            Task <UdpReceiveResult> resultReceive = udpClient.ReceiveAsync();

            bool gotData = false;

            gotData = resultReceive.Wait(5000);

            if (gotData)
            {
                Logger.LogInformation("Received {0} RTP bytes", data.Length);
            }

            actionTap.Stop();

            HangupResult resultHangup = call.Hangup();

            Successful = gotData && actionTap.Result.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #17
0
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                // The call was not answered successfully, stop the consumer and bail out
                Completed.Set();
                Stop();
                return;
            }

            TaskCompletionSource <bool> eventing = new TaskCompletionSource <bool>();

            call.OnFaxError += (a, c, e, p) =>
            {
                Logger.LogError("Actual fax receive had an error");
                eventing.SetResult(true);
            };
            call.OnFaxFinished += (a, c, e, p) =>
            {
                var settings = p.Fax.ParametersAs <CallingEventParams.FaxParams.FaxSettings.FinishedSettings>();
                if (settings.Success)
                {
                    Successful = true;
                }
                else
                {
                    Logger.LogError("Actual fax receive had an issue: {0}", settings.ResultText);
                }
                eventing.SetResult(true);
            };

            FaxResult receiveResult = call.FaxReceive();

            if (!receiveResult.Successful)
            {
                Successful = false;
                Logger.LogError("Receive fax was unsuccessful");
                eventing.SetResult(true);
            }
            else
            {
                eventing.Task.Wait();
                if (!Successful)
                {
                    Logger.LogError("Fax receive did not give a successful finished event");
                }
            }

            Completed.Set();
        }
Example #18
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();
                }
            });
        }
Example #19
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PlayResult resultPlay = call.PlayTTS("I'm a little teapot.");

            HangupResult resultHangup = call.Hangup();

            Successful = resultPlay.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #20
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();
        }
Example #21
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            // Answer the incoming call, block until it's answered or an error occurs
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                // The call was not answered successfully, stop the consumer and bail out
                Stop();
                return;
            }

            // Record the call, do not block
            RecordAction actionRecord = call.RecordAsync(new CallRecord
            {
                Audio = new CallRecord.AudioParams
                {
                    Direction         = CallRecord.AudioParams.AudioDirection.both,
                    InitialTimeout    = 5,
                    EndSilenceTimeout = 5,
                }
            });

            // Play some TTS to be captured in the recording with whatever the end user says
            call.PlayTTS("Welcome to SignalWire!");

            // If the recording doesn't hear anything for a few seconds it will cause the recording to complete
            while (!actionRecord.Completed)
            {
                // Wait for the async recording to complete, you can do other things here
                Thread.Sleep(1000);
            }

            Console.WriteLine("The recording was {0}", actionRecord.Result.Successful ? "Successful" : "Unsuccessful");
            if (actionRecord.Result.Successful)
            {
                Console.WriteLine("You can find the {0} duration recording at {1}", TimeSpan.FromSeconds(actionRecord.Result.Duration.Value).ToString(), actionRecord.Result.Url);
            }

            // Hangup
            call.Hangup();

            // Stop the consumer
            Stop();
        }
Example #22
0
        private void skype_CallStatus(Call call, TCallStatus status)
        {
            if (status == TCallStatus.clsRinging)
            {
                if (call.PartnerHandle == txbConsultant.Text)
                {
                    call.Answer();
                    Point screenBounds = ScreenBounds;
                    SkypeAutomation.SkypeObj.SendMessage(txbConsultant.Text, string.Format("screenbounds({0},{1})", screenBounds.X, screenBounds.Y));

                    SkypeAutomation.ShareFullScreen();
                }
                else
                {
                    call.Finish();
                }
            }
        }
Example #23
0
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
            }
            else
            {
                // incoming call failed
            }

            // Log Data
            PhoneCall theCall = call as PhoneCall;

            _data = new Helpers.DashboardDataModel()
            {
                Id                     = new System.Guid(),
                Direction              = "inbound",
                ConnectId              = theCall.ID,
                StartDateTime          = DateTime.UtcNow,
                State                  = theCall.State.ToString(),
                To                     = theCall.To,
                From                   = theCall.From,
                Duration               = 0,
                Disposition            = "",
                EndDateTime            = null,
                Context                = call.Context,
                StartDateTimeFormatted = DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt"),
                DurationFormatted      = "00:00",
                EndDateTimeFormatted   = ""
            };

            OnRealTimeEvent(new Helpers.RealTimeEventArgs()
            {
                ConsumptionId = _ConsumptionId,
                Type          = "phone",
                Payload       = _data
            });

            FlowRouter(call);
        }
Example #24
0
        private void skype_CallStatus(Call call, TCallStatus Status)
        {
            switch (Status)
            {
                case TCallStatus.clsRinging:
                    if (_skype.ActiveCalls.Count > 1)
                    {
                        foreach (Call activeCall in _skype.ActiveCalls)
                        {
                            call.Join(activeCall.Id);
                            break;
                        }
                    }
                    else
                        call.Answer();
                    break;

                default:
                    break;
            }
        }
Example #25
0
            protected override void OnIncomingCall(Call call)
            {
                // Answer the incoming call, block until it's answered or an error occurs
                AnswerResult resultAnswer = call.Answer();

                if (!resultAnswer.Successful)
                {
                    // The call was not answered successfully, stop the consumer and bail out
                    Stop();
                    return;
                }

                // Play an audio file, block until it's finished or an error occurs
                call.PlayAudio("https://cdn.signalwire.com/default-music/welcome.mp3");

                // Hangup
                call.Hangup();

                // Stop the consumer
                Stop();
            }
Example #26
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            // Answer the incoming call, block until it's answered or an error occurs
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                // The call was not answered successfully, stop the consumer and bail out
                Stop();
                return;
            }

            // Prompt with TTS and collect the PIN, block until it's finished or an error occurs
            PromptResult resultPrompt = call.PromptTTS(
                "Welcome to SignalWire! Please enter your PIN",
                new CallCollect
            {
                InitialTimeout = 10,
                Digits         = new CallCollect.DigitsParams {
                    Max = 4, DigitTimeout = 5
                }
            });

            if (resultPrompt.Successful)
            {
                // Play back what was collected
                call.PlayTTS("You entered " + resultPrompt.Result + ". Thanks and good bye!");
            }

            // Play an audio file, block until it's finished or an error occurs
            Console.Write("call has been answered, playing mp3 now...");
            call.PlayAudio("https://cdn.signalwire.com/default-music/welcome.mp3");

            // Hangup
            call.Hangup();

            // Stop the consumer
            Stop();
        }
Example #27
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void OnIncomingCall(Call call)
        {
            AnswerResult resultAnswer = call.Answer();

            if (!resultAnswer.Successful)
            {
                Completed.Set();
                return;
            }

            PromptAction actionPrompt = call.PromptTTSAsync(
                "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(5000);
            actionPrompt.Stop();

            Logger.LogDebug("Waiting for prompt to complete");
            while (!actionPrompt.Completed)
            {
                Thread.Sleep(500);
            }

            PlayResult resultPlay = call.PlayTTS("Stopped");

            HangupResult resultHangup = call.Hangup();

            Successful = resultPlay.Successful && resultHangup.Successful;
            Completed.Set();
        }
Example #28
0
 // Anwser the call
 public static void Answer()
 {
     call.Answer(0);
 }
Example #29
0
 public void Answer()
 {
     _call.Answer();
 }
Example #30
0
        private void skype_CallStatus(Call call, TCallStatus status)
        {
            if (status == TCallStatus.clsRinging)
            {
                if (call.PartnerHandle == txbConsultant.Text)
                {
                    call.Answer();
                    Point screenBounds = ScreenBounds;
                    SkypeAutomation.SkypeObj.SendMessage(txbConsultant.Text, string.Format("screenbounds({0},{1})", screenBounds.X, screenBounds.Y));

                    SkypeAutomation.ShareFullScreen();
                }
                else
                    call.Finish();
            }
        }
Example #31
0
        public void OurCallStatus(Call call, TCallStatus status)
        {
            try
            {
                if (status == TCallStatus.clsInProgress /*call.VideoSendStatus == TCallVideoSendStatus.vssAvailable*/)
                {
                    call.StartVideoSend();
                }
            }
            catch
            {

            }

            // Always use try/catch with ANY Skype calls.
            try
            {
                if (status == TCallStatus.clsRinging)
                {
                    if (numCalls == 0)
                    {
                        call.Answer();

                        callID = call.Id;
                        numCalls++;
                    }

                    else if (numCalls == 1 && callID != call.Id)
                    {
                       try
                       {
                           this.BeginInvoke((Action)(() =>
                           {
                               call.Finish();
                           }));
                       }
                       catch (InvalidCastException e)
                       {
                       }
                    }
                }
                // If this call is from a SkypeIn/Online number, show which one.
                else if (call.Type == TCallType.cltIncomingP2P && status == TCallStatus.clsInProgress && call.Id == callID)
                {
                    selectedSkypeChatUser = call.PartnerHandle.ToString();

                    this.BeginInvoke((Action)(() =>
                    {
                        skype.SendMessage(selectedSkypeChatUser, Properties.Settings.Default.controllerMessage);
                    }));

                    chatUserSelected = true;

                    user_combobox.ResetText();
                    user_combobox.SelectedText = call.PartnerHandle.ToString();

                    if (!skypeUserTabs.Contains(new SkypeUserTab(call.PartnerHandle)))
                    {
                        user_combobox.Items.Add(call.PartnerHandle);
                        var newTabUser = new SkypeUserTab(call.PartnerHandle);
                        skypeUserTabs.Add(newTabUser);
                        tabUsers.Controls.Add(newTabUser.tabPage);
                    }

                }

                else if (status == TCallStatus.clsFinished && call.Id == callID)
                {
                    numCalls--;
                    callID = 0;
                }
            }
            catch (Exception e)
            {
            }
        }
Example #32
0
        private void Skype_CallStatus(Call aCall, TCallStatus aStatus)
        {
            switch (aStatus)
            {
            case TCallStatus.clsRinging:
                // A call is ringing, see if it is us calling or
                // someone calling us
                if (aCall.Type == TCallType.cltIncomingP2P || aCall.Type == TCallType.cltIncomingPSTN)
                {
                    // Make sure this isn't a SkypeOut call request
                    if (aCall.PartnerHandle.Equals(_strMobileUser))
                    {
                        WriteToLog("SkypeOut call from " + _strMobileUser);
                        WriteToLog("Allowing call to be forwarded by Skype");
                        return;
                    }
                    // Incoming call, we need to initiate forwarding
                    WriteToLog("Answering call from " + aCall.PartnerHandle);
                    aCall.Answer();
                    this._intIncomingCallId = aCall.Id;
                    aCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeSoundcard, "default");
                    aCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypePort, "1");
                    string strWavPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\PleaseWait.wav";
                    aCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, strWavPath);
                    System.Threading.Thread.Sleep(8000);
                    aCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");
                    WriteToLog("Placing call on hold");
                    aCall.Hold();

                    // Check to see if we need to foward this to
                    // a configured SkypeIn mapping
                    string strTargetNumber;
                    if (this._colSkypeInMappings.ContainsKey(aCall.TargetIdentity))
                    {
                        // Yes set the target to the configured value
                        strTargetNumber = this._colSkypeInMappings[aCall.TargetIdentity];
                        WriteToLog("Calling SkypeIn forwarding number " + strTargetNumber);
                    }
                    else
                    {
                        // No, use the mobile user
                        strTargetNumber = this._strMobileUser;
                        WriteToLog("Calling mobile user");
                    }

                    System.Threading.Thread.Sleep(500);
                    try
                    {
                        Call oCall = _objSkype.PlaceCall(strTargetNumber, null, null, null);
                        this._intOutgoingCallId = oCall.Id;
                    }
                    catch (Exception ex)
                    {
                        WriteToLog("Error trying to call target: " + ex.Message);
                    }
                }
                break;

            case TCallStatus.clsInProgress:
                // We have a new call opened. Make sure it's our outgoing call
                if (aCall.Id == this._intOutgoingCallId)
                {
                    // Yes, the target user has answered.
                    WriteToLog("Target user has answered, attempting to join calls");
                    foreach (Call objCall in _objSkype.ActiveCalls)
                    {
                        if (objCall.Id == this._intIncomingCallId)
                        {
                            WriteToLog("Joining the calls...");
                            objCall.Join(aCall.Id);
                            WriteToLog("Taking incoming call off hold");
                            objCall.Resume();
                        }
                    }
                }
                break;

            case TCallStatus.clsFinished:
                // Someone has hung up, end the call
                WriteToLog("Someone has hung up. Attempting to end the conference");
                foreach (Conference objConf in _objSkype.Conferences)
                {
                    foreach (Call objCall in objConf.Calls)
                    {
                        if (objCall.Id == this._intIncomingCallId || objCall.Id == this._intOutgoingCallId)
                        {
                            System.Threading.Thread.Sleep(500);
                            try
                            {
                                objCall.Finish();
                            }
                            catch (Exception) { }
                            try
                            {
                                objConf.Finish();
                            }
                            catch (Exception) { }
                        }
                    }
                }
                break;

            default:
                // Something else?
                if ((aCall.Type == TCallType.cltOutgoingP2P || aCall.Type == TCallType.cltOutgoingPSTN) && (
                        aCall.Status == TCallStatus.clsCancelled ||
                        aCall.Status == TCallStatus.clsFailed ||
                        aCall.Status == TCallStatus.clsMissed ||
                        aCall.Status == TCallStatus.clsRefused ||
                        aCall.Status == TCallStatus.clsVoicemailPlayingGreeting ||
                        aCall.Status == TCallStatus.clsVoicemailRecording
                        )
                    )
                {
                    WriteToLog("Error calling target user: "******"Redirecting to voicemail");
                    // End the other call
                    foreach (Call objCall in _objSkype.ActiveCalls)
                    {
                        if (objCall.Id == this._intOutgoingCallId)
                        {
                            try
                            {
                                objCall.Finish();
                            }
                            catch (Exception ex)
                            {
                                WriteToLog("Error trying to end voicemail call: " + ex.Message);
                            }
                        }
                    }
                    // Now redirect the incoming call
                    foreach (Call objCall in _objSkype.ActiveCalls)
                    {
                        if (objCall.Id == this._intIncomingCallId)
                        {
                            System.Threading.Thread.Sleep(500);
                            try
                            {
                                //objCall.Resume();
                                objCall.RedirectToVoicemail();
                                objCall.Finish();
                                //objCall.Status = TCallStatus.clsFinished;
                            }
                            catch (Exception ex)
                            {
                                WriteToLog("Error trying to divert to voicemail: " + ex.Message);
                                objCall.Finish();
                            }
                        }
                    }
                }
                break;
            }
        }
        public void OurCallStatus(Call call, TCallStatus status)
        {
            try
            {
                if (call.VideoSendStatus == TCallVideoSendStatus.vssAvailable)
                {
                    call.StartVideoSend();
                }
            }
            catch
            {
            }


            // Always use try/catch with ANY Skype calls.
            try
            {
                if (status == TCallStatus.clsRinging)
                {
                    if (numCalls == 0)
                    {
                        call.Answer();


                        callID = call.Id;
                        numCalls++;
                    }

                    else if (numCalls == 1 && callID != call.Id)
                    {
                        try
                        {
                            this.BeginInvoke((Action)(() =>
                            {
                                call.Finish();
                            }));
                        }
                        catch (InvalidCastException e)
                        {
                        }
                    }
                }
                // If this call is from a SkypeIn/Online number, show which one.
                else if (call.Type == TCallType.cltIncomingP2P && status == TCallStatus.clsInProgress && call.Id == callID)
                {
                    selectedSkypeChatUser = call.PartnerHandle.ToString();

                    this.BeginInvoke((Action)(() =>
                    {
                        skype.SendMessage(selectedSkypeChatUser, Properties.Settings.Default.controllerMessage);
                    }));

                    chatUserSelected = true;

                    user_combobox.ResetText();
                    user_combobox.SelectedText = call.PartnerHandle.ToString();

                    if (!skypeUserTabs.Contains(new SkypeUserTab(call.PartnerHandle)))
                    {
                        user_combobox.Items.Add(call.PartnerHandle);
                        var newTabUser = new SkypeUserTab(call.PartnerHandle);
                        skypeUserTabs.Add(newTabUser);
                        tabUsers.Controls.Add(newTabUser.tabPage);
                    }
                }

                else if (status == TCallStatus.clsFinished && call.Id == callID)
                {
                    numCalls--;
                    callID = 0;
                }
            }
            catch (Exception e)
            {
            }
        }