Beispiel #1
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(mymsg = "Call state: {0}." + e.State);

            if (e.State == CallState.Answered)
            {
                StartDevices();
                MediaReciever.AttachToCall(PhoneCall);
                MediaSender.AttachToCall(PhoneCall);

                InvokeGUIThread(mymsg = "Call started" + e.State);
            }

            if (e.State.IsCallEnded() == true)
            {
                StopDevices();

                MediaReciever.Detach();
                MediaSender.Detach();

                WireDownCallEvents();

                PhoneCall             = null;
                InvokeGUIThread(mymsg = "Call ended" + e.State);
            }
        }
 /// <summary>
 /// Attaches the media handlers to the given phone call.
 /// </summary>
 public void AttachAudio(IPhoneCall call)
 {
     AudioEnhancer.Refresh();
     AudioEnhancer.Start();
     _phoneCallAudioSender.AttachToCall(call);
     _phoneCallAudioReceiver.AttachToCall(call);
 }
        private void CallAnswered()
        {
            _callID = _call.CallID;
            _log.Info("Call Answered. Call ID: " + _callID);

            _log.Info(String.Format("Recording to {0}", _wavFileName));
            _audioReceiver.AttachToCall(_call);
            _wavRecorder.DataSent += WavRecorderDataReceived;
            _wavRecorder.StartStreaming();
        }
Beispiel #4
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            switch (e.State)
            {
            case CallState.Ringing:
                StateChanged?.Invoke(PhoneState.Ringing);
                break;

            case CallState.InCall:
                StateChanged?.Invoke(PhoneState.InCall);
                break;

            default:
                StateChanged?.Invoke(PhoneState.Other);
                break;
            }
            RaiseMessage?.Invoke(e.State.ToString());

            if (e.State == CallState.Answered)
            {
                if (microphone != null)
                {
                    microphone.Start();
                }

                if (speaker != null)
                {
                    speaker.Start();
                }

                mediaSender.AttachToCall(call);
                mediaReceiver.AttachToCall(call);
                return;
            }

            if (e.State.IsCallEnded())
            {
                if (microphone != null)
                {
                    microphone.Stop();
                }

                if (speaker != null)
                {
                    speaker.Stop();
                }

                mediaSender.Detach();
                mediaReceiver.Detach();

                UnsubscribeFromCallEvents(sender as IPhoneCall);
                call = null;
                StateChanged?.Invoke(PhoneState.CallEnded);
            }
        }
Beispiel #5
0
        static void SetupDevices()
        {
            microphone.Start();
            connector.Connect(microphone, mediaSender);

            speaker.Start();
            connector.Connect(mediaReceiver, speaker);

            mediaSender.AttachToCall(call);
            mediaReceiver.AttachToCall(call);
        }
Beispiel #6
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            _message = new List <string>();
            _message.Add(e.State.ToString());
            StopMp3Ring();
            if (e.State == CallState.Answered)
            {
                StartDevices();

                _mediaReceiver.AttachToCall(_call);
                _mediaSender.AttachToCall(_call);

                //InvokeGUIThread(() => { lb_Log.Items.Add("Call started."); });
            }

            if (e.State == CallState.InCall)
            {
                //btn_Hold.Enabled = true;
                //btn_Hold.Text = "Hold";
                StartDevices();
            }

            if (e.State.IsRinging())
            {
                StartMP3Ring("Ringing.mp3");
            }
            if (e.State == CallState.Busy)
            {
                StartMP3Ring("Busy.mp3");
            }

            if (e.State.IsCallEnded())
            {
                //_localHeld = false;

                StopDevices();

                _mediaReceiver.Detach();
                _mediaSender.Detach();

                WireDownCallEvents();

                _call = null;

                //InvokeGUIThread(() => { lb_Log.Items.Add("Call ended."); tb_Display.Text = string.Empty; });
            }

            if (e.State == CallState.LocalHeld)
            {
                StopDevices();
            }
        }
        /// <summary>
        /// Occurs when the phone call state has changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void call_CallStateChanged(object sender, VoIPEventArgs <CallState> e)
        {
            InvokeGUIThread(() => { labelCallStateInfo.Text = e.Item.ToString(); });

            switch (e.Item)
            {
            case CallState.InCall:
                if (microphone != null)
                {
                    microphone.Start();
                }
                connector.Connect(microphone, mediaSender);

                if (speaker != null)
                {
                    speaker.Start();
                }
                connector.Connect(mediaReceiver, speaker);

                mediaSender.AttachToCall(call);
                mediaReceiver.AttachToCall(call);

                break;

            case CallState.Completed:
                if (microphone != null)
                {
                    microphone.Stop();
                }
                connector.Disconnect(microphone, mediaSender);
                if (speaker != null)
                {
                    speaker.Stop();
                }
                connector.Disconnect(mediaReceiver, speaker);

                mediaSender.Detach();
                mediaReceiver.Detach();

                WireDownCallEvents();
                call = null;

                InvokeGUIThread(() => { labelDialingNumber.Text = string.Empty; });
                break;

            case CallState.Cancelled:
                WireDownCallEvents();
                call = null;
                break;
            }
        }
Beispiel #8
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            if (e.State == CallState.Answered)
            {
                //player.Stop();
                StartDevices();

                _mediaReceiver.AttachToCall(frmSipAccount._call);
                _mediaSender.AttachToCall(frmSipAccount._call);


                AsynThread(() => { lb_Log.Items.Add("Call started."); });
            }
            if (e.State == CallState.InCall)
            {
                //isCalling = false;
                player.Stop();
                StartDevices();
            }
            if (e.State.IsCallEnded())
            {
                StopDevices();

                _mediaReceiver.Detach();
                _mediaSender.Detach();
                UnSubcribeCallEvents();
            }
            if (e.State == CallState.LocalHeld)
            {
                AsynThread(() => { lb_Log.Items.Add("Call Hold."); });
                StopDevices();
            }
            if (e.State == CallState.Ringing)
            {
                AsynThread(() => {
                    //if (isCalling)
                    //    playSound(calling);
                    //else
                    playSound(ringing);
                });
            }
            DispatchAsync(() =>
            {
                var handler = CallStateChanged;
                if (handler != null)
                {
                    handler(this, e);
                }
            });
        }
        /// <summary>
        /// Connecting the microphone and speaker to the call
        /// </summary>
        private void ConnectDevicesToCall()
        {
            if (microphone != null)
            {
                microphone.Start();
            }
            connector.Connect(microphone, mediaSender);

            if (speaker != null)
            {
                speaker.Start();
            }
            connector.Connect(mediaReceiver, speaker);

            mediaSender.AttachToCall(call);
            mediaReceiver.AttachToCall(call);
        }
Beispiel #10
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(() => { lb_Log.Items.Add("Callstate changed." + e.State.ToString()); tb_Display.Text = e.State.ToString(); });

            if (e.State == CallState.Answered)
            {
                btn_Hold.Enabled = true;
                btn_Hold.Text    = "Hold";

                StartDevices();

                mediaReceiver.AttachToCall(call);
                mediaSender.AttachToCall(call);


                InvokeGUIThread(() => { lb_Log.Items.Add("Call started."); });
            }

            if (e.State == CallState.InCall)
            {
                btn_Hold.Enabled = true;
                btn_Hold.Text    = "Hold";
                StartDevices();
            }

            if (e.State.IsCallEnded() == true)
            {
                localHeld = false;

                StopDevices();

                mediaReceiver.Detach();
                mediaSender.Detach();

                WireDownCallEvents();

                call = null;

                InvokeGUIThread(() => { lb_Log.Items.Add("Call ended."); tb_Display.Text = string.Empty; });
            }

            if (e.State == CallState.LocalHeld)
            {
                StopDevices();
            }
        }
Beispiel #11
0
        static void SetupDevices()
        {
            if (x > 0)
            {
                OzekiInit();
                Console.WriteLine("setupDevices With OZEKI ####################################");
            }


            x++;
            microphone.Start();
            connector.Connect(microphone, mediaSender);

            speaker.Start();
            connector.Connect(mediaReceiver, speaker);

            mediaSender.AttachToCall(call);
            mediaReceiver.AttachToCall(call);
        }
Beispiel #12
0
        void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(() => { lbl_CallState.Text = e.State.ToString(); });

            if (e.State == CallState.Answered)
            {
                StartDevices();
                _mediaSender.AttachToCall(_call);
                _mediaReceiver.AttachToCall(_call);

                InvokeGUIThread(() => { tb_Display.Text = "In call with: " + ((IPhoneCall)sender).DialInfo.Dialed; });
            }
            else if (e.State == CallState.InCall)
            {
                StartDevices();
            }

            if (e.State == CallState.LocalHeld || e.State == CallState.InactiveHeld)
            {
                StopDevices();
                InvokeGUIThread(() => { btn_Hold.Text = "Unhold"; });
            }
            else
            {
                InvokeGUIThread(() => { btn_Hold.Text = "Hold"; });
            }

            if (e.State.IsCallEnded())
            {
                StopDevices();

                _mediaSender.Detach();
                _mediaReceiver.Detach();

                WireDownCallEvents();

                _call = null;

                InvokeGUIThread(() => { tb_Display.Text = String.Empty; });
                ClearUserInfos();
            }
        }
        public void SetupDevices()
        {
            if (x > 0)
            {
                OzekiInitialization();
            }
            Console.WriteLine("setupDevices1");

            x++;
            microphone.Start();
            connector.Connect(microphone, mediaSender);
            Console.WriteLine("setupDevices2");

            speaker.Start();
            connector.Connect(mediaReceiver, speaker);
            Console.WriteLine("setupDevices3");

            mediaSender.AttachToCall(call);
            Console.WriteLine("setupDevices4");
            mediaReceiver.AttachToCall(call);
            Console.WriteLine("setupDevices5");
        }
        private void SetupDevices()
        {
            microphone.Start();
            connector.Connect(microphone, mediaSender);

            speaker.Start();
            connector.Connect(mediaReceiver, speaker);

            mediaSender.AttachToCall(call);
            mediaReceiver.AttachToCall(call);

            Application.Current.Dispatcher.Invoke(() =>
            {
                uplynelo_sekund                 = 0;
                CzasRozmowy_Label.Content       = "Czas rozmowy: " + TimeSpan.FromSeconds(uplynelo_sekund).ToString(@"hh\:mm\:ss");
                ZakonczRozmowe_Button.IsEnabled = true;
                if (rozmawiajacyUzytkownik != null)//my dzwonimy
                {
                    //rozmawiajacyUzytkownik.wiadomosci.Add(DateTime.Now.ToShortTimeString() + " rozpoczęto rozmowę");
                    call.OtherParty.UserName = rozmawiajacyUzytkownik.login;
                }
                else//ktos dzwoni
                {
                    var kontakt            = listaKontaktow.Find(X => X.login == call.OtherParty.UserName);
                    rozmawiajacyUzytkownik = kontakt;
                }
                CzasRozmowy_Label.Visibility = Visibility.Visible;
                if (stoper != null)
                {
                    stoper.Stop();
                }
                stoper          = new System.Windows.Threading.DispatcherTimer();
                stoper.Interval = TimeSpan.FromSeconds(1);
                stoper.Tick    += Stoper_Tick;
                stoper.Start();
            });
        }
Beispiel #15
0
        /// <summary>
        /// This will be called when the state of the call call has changed.
        /// </summary>
        /// <remarks>
        /// In this sample only three states will be handled: Answered, InCall, Ended
        ///
        /// Answered: when the call has been answered, the audio devices will be started and attached to the call.
        /// It is required to comminicate with the other party and hear them.
        /// The devices are connected at softphone initialization time,
        /// so no need to connect them every time when a call is being answered.
        ///
        /// InCall: when the call is in an active state, the audio deveices will be started.
        ///
        /// Ended: when the call ends, the audio devices will be stopped and detached from the call.
        /// </remarks>
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            // the call has been answered
            if (e.State == CallState.Answered)
            {
                StartDevices();

                mediaReceiver.AttachToCall(call);
                mediaSender.AttachToCall(call);
            }

            // the call is in active communication state
            // IMPORTANT: this state can occur multiple times. for example when answering the call or the call has been taken off hold.
            if (e.State == CallState.InCall)
            {
                StartDevices();
            }


            // the call has ended
            if (e.State.IsCallEnded())
            {
                if (call != null)
                {
                    CallFinished();
                }
            }

            DispatchAsync(() =>
            {
                var handler = CallStateChanged;
                if (handler != null)
                {
                    handler(this, e);
                }
            });
        }
 public void AttachReceiveCall()
 {
     videoReceiver.AttachToCall(call);
     audioReceiver.AttachToCall(call);
 }
Beispiel #17
0
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            try
            {
                InvokeGUIThread(() => { lb_Log.Items.Add("Callstate changed." + e.State.ToString()); });// tb_Display.Text = e.State.ToString();

                if (e.State == CallState.Answered)
                {
                    player.Stop();
                    StartDevices();

                    _mediaReceiver.AttachToCall(_call);
                    _mediaSender.AttachToCall(_call);

                    SetupAnswered();
                    InvokeGUIThread(() => { lb_Log.Items.Add("Call started."); });
                }

                if (e.State == CallState.InCall)
                {
                    player.Stop();
                    StartDevices();
                    InvokeGUIThread(() =>
                    {
                    });
                }

                if (e.State.IsCallEnded() || e.State == CallState.Rejected)
                {
                    StopDevices();

                    _mediaReceiver.Detach();
                    _mediaSender.Detach();

                    UnSubcribedCallEvents();
                    if (isInComingCompleted)
                    {
                        isInComingCompleted = false;
                        InvokeGUIThread(() =>
                        {
                        });
                    }
                    InvokeGUIThread(() =>
                    {
                    });
                    _call = null;
                    EndCalling();
                    InvokeGUIThread(() =>
                    {
                        lb_Log.Items.Add("Call ended.");
                        playSound(hangup);
                    });
                }

                if (e.State == CallState.LocalHeld)
                {
                    InvokeGUIThread(() => { lb_Log.Items.Add("Call Holding."); });
                    StopDevices();
                }
                if (e.State == CallState.RemoteHeld)
                {
                    InvokeGUIThread(() => { lb_Log.Items.Add("Callee Holding."); });
                    InvokeGUIThread(() => { playSound(holding); });
                }
                if (e.State == CallState.Ringing)
                {
                    InvokeGUIThread(() =>
                    {
                        if (isCalling)
                        {
                            playSound(calling);
                        }
                        else
                        {
                            playSound(ringing);
                        }
                    });
                }

                DispatchAsync(() =>
                {
                    var handler = CallStateChanged;
                    if (handler != null)
                    {
                        handler(this, e);
                    }
                });
            }
            catch (Exception ex)
            {
            }
        }
        private void Call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            IPhoneCall grCall = sender as IPhoneCall;

            _grCall = grCall;
            MyCallState tmp = MyCallState.DoNotthing;

            if (e.State == CallState.Answered)
            {
                StartDevices();
                mediaReceiver.AttachToCall(call);
                mediaSender.AttachToCall(call);
                videoReceiver.AttachToCall(call);
                videoSender.AttachToCall(call);
                tmp = MyCallState.Answered;
            }

            if (e.State == CallState.InCall)
            {
                StartDevices();
                tmp = MyCallState.InCall;
                CallDuration();
            }

            if (e.State.IsCallEnded() == true)
            {
                StopDevices();
                mediaReceiver.Detach();
                mediaSender.Detach();
                videoSender.Detach();
                videoReceiver.Detach();
                WireDownCallEvents();
                call = null;
                tmp  = MyCallState.CallEnd;
                Instance.IsLocalCameraUsed = false;
                timer.Stop();
            }

            if (e.State == CallState.LocalHeld)
            {
                StopDevices();
            }
            if (e.State == CallState.Busy)
            {
                StopDevices();
                tmp = MyCallState.Busy;
            }
            if (e.State == CallState.Cancelled)
            {
                StopDevices();
                tmp = MyCallState.Canceled;
            }
            if (e.State == CallState.Completed)
            {
                tmp = MyCallState.CallEnd;
            }

            if (CallStateChange != null)
            {
                CallStateChange.Invoke(tmp);
            }
        }
Beispiel #19
0
        void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(() => { lbl_CallState.Text = e.State.ToString(); lblEstatusLlamada.Text = e.State.ToString(); });

            if (e.State == CallState.Answered)
            {
                InvokeGUIThread(() => {
                    wplayer.controls.stop();
                    crearFolio();
                    ALlamadaData.bCurso = true;

                    string sRuta = string.Format(@"{0}\mpy\records\nws", Path.GetTempPath());
                    if (!Directory.Exists(sRuta))
                    {
                        Directory.CreateDirectory(sRuta);
                    }
                });

                StartDevices();
                SendDTMFSingnal();

                sFechaInicio = DateTime.Now;
                sRecordName  = AProspeccionData.bCurso ? string.Format("pcll-{1}.wav", Path.GetTempPath(), AProspeccionData.iIdLlamada) : string.Format("Folio-{0}-{1}{2}{3}{4}{5}{6}.wav", iIdFolio, sFechaInicio.Day, sFechaInicio.Month, sFechaInicio.Year, sFechaInicio.Hour, sFechaInicio.Minute, sFechaInicio.Second);
                filename     = string.Format(@"{0}\mpy\records\nws\{1}", Path.GetTempPath(), sRecordName);

                recorder = new WaveStreamRecorder(filename);  // new recorder object
                _connector.Connect(_microphone, recorder);    // connects the outgoing voice to the recorder
                _connector.Connect(_mediaReceiver, recorder); // connects the incoming voice to the recorder

                _mediaSender.AttachToCall(_call);
                _mediaReceiver.AttachToCall(_call);
                recorder.Start();  // starts the recording

                InvokeGUIThread(() => {
                    timer1.Start();
                    txtDisplay.Text     = "" + ((IPhoneCall)sender).DialInfo.SIPCallerID.DisplayName;
                    lblExtEntrante.Text = "" + ((IPhoneCall)sender).DialInfo.SIPCallerID.DisplayName;

                    if (!AProspeccionData.bCurso)
                    {
                        // Valida despues de mostrar la modal para registrar la llamada
                        if (RegistrarLlamadaModal.Show(iIdFolio, filename) == DialogResult.Yes)
                        {
                            Cliente ACliente = new Cliente();
                            Caso NoCliente;
                            if (bSeguimiento)
                            {
                                NoCliente = new Caso().ClienteCaso(iIdFolioSeguimiento);
                            }
                            else
                            {
                                NoCliente = new Caso().ClienteCaso(iIdFolio);
                            }
                        }
                    }
                });
            }
            else if (e.State == CallState.InCall)
            {
                StartDevices();
            }

            if (e.State == CallState.LocalHeld || e.State == CallState.InactiveHeld)
            {
                StopDevices();
                InvokeGUIThread(() => {
                    lnkHold.Text         = "Unhold";
                    lnkHold.Image        = Properties.Resources.resume_button_48px;
                    lnkHold.NoFocusImage = Properties.Resources.resume_button_48px;
                });
            }
            else
            {
                InvokeGUIThread(() => {
                    lnkHold.Text         = "Hold";
                    lnkHold.Image        = Properties.Resources.pause_48px;
                    lnkHold.NoFocusImage = Properties.Resources.pause_48px;
                });
            }

            if (e.State.IsCallEnded())
            {
                StopDevices();

                _mediaSender.Detach();
                _mediaReceiver.Detach();

                WireDownCallEvents();

                if (recorder != null)
                {
                    recorder.Dispose();
                    recorder = null;
                }

                _call = null;

                timer1.Stop();

                InvokeGUIThread(() => {
                    wplayer.controls.stop();
                    txtDisplay.Text     = String.Empty;
                    lblExtEntrante.Text = string.Empty;
                    lblTiempo.Text      = string.Empty;

                    if (pnlLlamada.Visible == true)
                    {
                        frmTelefono.Animate2(pnlLlamada, frmTelefono.Effect.Slide, 150, 360);
                        frmTelefono.Animate(pnlKeyPad, frmTelefono.Effect.Slide, 150, 360);
                    }

                    lnkPickUpInCall.Visible      = true;
                    lnkVolverLLamada.Visible     = false;
                    pnlTransferirLlamada.Visible = false;
                    txtNoTransferir.Text         = string.Empty;
                    lnkConfigurar.Enabled        = true;
                    lnkHangUp.Location           = new Point(150, 94);
                    AProspeccionData.bCurso      = false;

                    string sFilePath = "";
                    if (bSeguimiento && iIdFolioSeguimiento != 0)
                    {
                        sFilePath = string.Format(@"{0}\mpy\records\nws\Folio-{1}-{2}{3}{4}{5}{6}{7}.wav", Path.GetTempPath(), iIdFolioSeguimiento, sFechaInicio.Day, sFechaInicio.Month, sFechaInicio.Year, sFechaInicio.Hour, sFechaInicio.Minute, sFechaInicio.Second);
                        File.Move(filename, sFilePath);
                        CasoHistorial _UpdRecord = new CasoHistorial();
                        _UpdRecord.UpdateHistorialRecord(iIdHistorialFolio, sFilePath);
                    }

                    if (ALlamadaData.bCurso)
                    {
                        if (sFilePath == "")
                        {
                            string FullPath = string.Format("{0}/{1}/Records/", FTPCredentials.Path, ConnectionString.FolderConnection);
                            FTPServer.Upload(FullPath, FTPCredentials.User, FTPCredentials.Password, Path.GetFileName(filename), filename);
                            File.Delete(filename);
                        }
                        else
                        {
                            string FullPath = string.Format("{0}/{1}/Records/", FTPCredentials.Path, ConnectionString.FolderConnection);
                            FTPServer.Upload(FullPath, FTPCredentials.User, FTPCredentials.Password, Path.GetFileName(sFilePath), sFilePath);
                            File.Delete(sFilePath);
                        }
                        ALlamadaData.bCurso = false;
                    }
                });
            }
        }
Beispiel #20
0
        public void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            InvokeGUIThread(() => { lb_Log.Items.Add("Callstate changed." + e.State.ToString()); }); // tb_Display.Text = e.State.ToString();

            if (e.State == CallState.Answered)
            {
                player.Stop();
                StartDevices();

                _mediaReceiver.AttachToCall(_call);
                _mediaSender.AttachToCall(_call);


                InvokeGUIThread(() => { lb_Log.Items.Add("Call started."); });
            }

            if (e.State == CallState.InCall)
            {
                isCalling = false;
                player.Stop();
                StartDevices();
                InvokeGUIThread(() => {
                    btnHangup.Enabled   = true;
                    btnHold.Enabled     = true;
                    btnHangup.BackColor = Color.Red;
                    btnHangup.ForeColor = Color.Snow;
                    btnHold.BackColor   = Color.Red;
                    btnHold.ForeColor   = Color.Snow;
                });
            }

            if (e.State.IsCallEnded())
            {
                StopDevices();

                _mediaReceiver.Detach();
                _mediaSender.Detach();

                WireDownCallEvents();
                if (isInComingCompleted)
                {
                    isInComingCompleted = false;
                    InvokeGUIThread(() =>
                    {
                        btnAccpect.Enabled   = false;
                        btnAccpect.BackColor = Color.Teal;
                        btnAccpect.ForeColor = Color.DimGray;
                        btnHold.Enabled      = false;
                        btnHangup.Enabled    = false;
                        btnHold.BackColor    = Color.Teal;
                        btnHold.ForeColor    = Color.DimGray;
                        btnHangup.BackColor  = Color.Teal;
                        btnHangup.ForeColor  = Color.DimGray;
                    });
                }
                InvokeGUIThread(() =>
                {
                    btnHold.Enabled     = false;
                    btnHangup.Enabled   = false;
                    btnHold.BackColor   = Color.Teal;
                    btnHold.ForeColor   = Color.DimGray;
                    btnHangup.BackColor = Color.Teal;
                    btnHangup.ForeColor = Color.DimGray;
                });
                _call = null;

                InvokeGUIThread(() => {
                    lb_Log.Items.Add("Call ended.");
                    playSound(hangup);
                });
            }

            if (e.State == CallState.LocalHeld)
            {
                InvokeGUIThread(() => { lb_Log.Items.Add("Call Hold."); });
                StopDevices();
            }
            if (e.State == CallState.RemoteHeld)
            {
                InvokeGUIThread(() => { playSound(holding); });
            }
            if (e.State == CallState.Ringing)
            {
                InvokeGUIThread(() => {
                    if (isCalling)
                    {
                        playSound(calling);
                    }
                    else
                    {
                        playSound(ringing);
                    }
                });
            }

            DispatchAsync(() =>
            {
                var handler = CallStateChanged;
                if (handler != null)
                {
                    handler(this, e);
                }
            });
        }
Beispiel #21
0
        /// <summary>
        /// This will be called when the state of the call call has changed.
        /// </summary>
        /// <remarks>
        /// In this sample only three states will be handled: Answered, InCall, Ended
        ///
        /// Answered: when the call has been answered, the audio devices will be started and attached to the call.
        /// It is required to comminicate with the other party and hear them.
        /// The devices are connected at softphone initialization time,
        /// so no need to connect them every time when a call is being answered.
        ///
        /// InCall: when the call is in an active state, the audio deveices will be started.
        ///
        /// Ended: when the call ends, the audio devices will be stopped and detached from the call.
        /// </remarks>
        private void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            // the call has been answered
            if (e.State == CallState.Answered)
            {
                StartDevices();
                MediaHandlers.StopRingback();
                _mediaReceiver.AttachToCall(_call);
                _mediaSender.AttachToCall(_call);

                // For further information about the calling of the ConnectMedia(), please check the implementation of this method.
                ConnectMedia();
            }

            if (e.State == CallState.Ringing)
            {
                StartDevices();
                MediaHandlers.StartRingback();

                //  MediaHandlers.AttachAudio(_call);
                //  MediaHandlers.AttachVideo(_call);

                _mediaReceiver.AttachToCall(_call);
                _mediaSender.AttachToCall(_call);

                // For further information about the calling of the ConnectMedia(), please check the implementation of this method.
                ConnectMedia();
            }
            if (e.State == CallState.RingingWithEarlyMedia)
            {
                MediaHandlers.StartRingback();
                //  MediaHandlers.AttachAudio(_call);
                //  MediaHandlers.AttachVideo(_call);
                // For further information about the calling of the ConnectMedia(), please check the implementation of this method.
                ConnectMedia();
            }

            // the call is in active communication state
            // IMPORTANT: this state can occur multiple times. for example when answering the call or the call has been taken off hold.
            if (e.State == CallState.InCall)
            {
                StartDevices();
                // MediaHandlers.StopRingback();
            }

            // the call has ended
            if (e.State.IsCallEnded())
            {
                if (_call != null)
                {
                    CallFinished();
                }
            }

            DispatchAsync(() =>
            {
                var handler = CallStateChanged;
                if (handler != null)
                {
                    handler(this, e);
                }
            });
        }