Exemplo n.º 1
0
        private void OnNewCall(int sessionId)
        {
            try
            {
                timerEndCall.Stop();
                IStateMachine call   = CallManager.getCall(sessionId);
                string        number = Globals.NormalizeTelNumber(call.CallingNumber);
                if (sesje.ContainsKey(sessionId))
                {
                    sesje.Remove(sessionId);
                }
                sesje.Add(sessionId, new CallInfo(number, call.Incoming, sessionId));
                if (Globals.FindByNumber(number) != null)
                {
                    Contact con = Globals.FindByNumber(number);
                    lACFullName.Text = con.Fullname;
                    TelNumber tn = con.getTelByNumber(number);
                    lACNumber.Text      = tn.Number;
                    lACTelType.Text     = tn.TypeString + ":";
                    picAvatar.EditValue = con.Photo;
                }
                else
                {
                    if (call.CallingNumber == "")
                    {
                        lACFullName.Text = "Nieznany";
                    }
                    else
                    {
                        lACFullName.Text = number;
                    }
                    lACNumber.Text      = "";
                    lACTelType.Text     = "";
                    picAvatar.EditValue = Resources.phone_256;
                }
                if (call.Incoming)
                {
                    CallSmall callSmall = new CallSmall(lACFullName.Text, lACNumber.Text);
                    callSmall.Show(this);

                    tlpACButtons.SetColumnSpan(btnEndCall, 2);
                    tlpACButtons.SetColumn(btnEndCall, 2);
                    btnAnswerCall.Visible = btnEndCall.Visible = btnTransferCall.Visible = true;
                    btnAnswerCall.Enabled = true;
                }
                else
                {
                    btnAnswerCall.Visible = false;
                    tlpACButtons.SetColumn(btnEndCall, 0);
                    tlpACButtons.SetColumnSpan(btnEndCall, 4);
                    btnEndCall.Visible      = true;
                    btnTransferCall.Visible = true;
                }
                btnAnswerCall.Visible   = call.Incoming;
                btnEndCall.Visible      = true;
                btnTransferCall.Visible = true;
                lCallStatus.Text        = call.Incoming ? "Przychodzące" : "Łączenie";
                lTime.Text                  = "00:00";
                lTime.Visible               = false;
                lCallStatus.BackColor       = Color.Green;
                lTime.BackColor             = Color.Green;
                tabActiveCall.PageVisible   = true;
                tabControll.SelectedTabPage = tabActiveCall;
                Send("NEWCALL:" + number + ";" + call.Incoming.ToString() + ";" + DateTime.Now.ToString() + ";" + TimeSpan.Zero.ToString());
                dtmf = "";
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
Exemplo n.º 2
0
 private void timerCallDuration_Tick(object sender, EventArgs e)
 {
     lTime.Text = CallManager.getCallInState(EStateId.ACTIVE).RuntimeDuration.ToString(@"mm\:ss");
 }
Exemplo n.º 3
0
        private void OnCallStateChanged(int sessionId)
        {
            IStateMachine call = CallManager.getCall(sessionId);

            //MessageBox.Show(call.Session.ToString() + ": " + call.StateId.ToString());
            if (call.StateId == EStateId.INCOMING)
            {
                try
                {
                    if (Settings.PlaySound)
                    {
                        //SetVolume(10);

                        ringtone.SoundLocation = Settings.Ringtone;
                        ringtone.PlayLooping();
                    }
                    else
                    {
                        //SetVolume(0);

                        StackProxy.setSoundDevice("0", "0");
                    }
                }
                catch { }
                try
                {
                    OnNewCall(sessionId);
                }
                catch { }
            }
            else if (call.StateId == EStateId.ALERTING)
            {
                OnNewCall(sessionId);
            }
            else if (call.StateId == EStateId.ACTIVE)
            {
                ringtone.Stop();
                timerCallDuration.Start();
                lTime.Visible         = true;
                btnAnswerCall.Visible = false;
                lCallStatus.Text      = "Rozmowa";
                tlpACButtons.SetColumn(btnEndCall, 0);
                tlpACButtons.SetColumnSpan(btnEndCall, 4);
                sesje[sessionId].Begin();
                Send("ACTIVECALL:" + sesje[sessionId].Number + ";" + sesje[sessionId].Incoming.ToString() + ";" + sesje[sessionId].Start.ToString() + ";" + sesje[sessionId].Duration.ToString());
            }
            else if (call.StateId == EStateId.NULL)
            {
                if (sesje.ContainsKey(sessionId))
                {
                    ringtone.Stop();
                    tabControll.SelectedTabPage = tabActiveCall;
                    sesje[sessionId].End();
                    timerCallDuration.Stop();
                    timerEndCall.Start();
                    lCallStatus.Text        = "Rozmowa zakończona";
                    lCallStatus.BackColor   = Color.Maroon;
                    lTime.BackColor         = Color.Maroon;
                    btnAnswerCall.Visible   = false;
                    btnEndCall.Visible      = false;
                    btnTransferCall.Visible = false;
                    teDialNumber.Text       = "";
                    Send("ENDCALL:" + sesje[sessionId].Number + ";" + sesje[sessionId].Incoming.ToString() + ";" + sesje[sessionId].Start.ToString() + ";" + sesje[sessionId].Duration.ToString());
                    Histories.Add(new History(sesje[sessionId]));
                    gvHistory.RefreshData();
                    sesje.Remove(sessionId);
                    dtmf       = "";
                    IsTransfer = false;
                    //call.destroy();
                }
            }
        }
Exemplo n.º 4
0
        private void OnStateUpdate(Int32 iSessionId)
        {
            IStateMachine sm = CallManager.getCall(iSessionId);

            v_hCall = sm;

            pCallStatusLabel.Text = sm.CallingNumber + " : " + sm.StateId.ToString();

            if (sm.StateId == EStateId.IDLE || sm.StateId == EStateId.NULL)
            {
                System.Media.SoundPlayer player = new System.Media.SoundPlayer();
                player.SoundLocation = "Sounds\\disconnect.wav";
                player.Load();
                player.Play();

                /*if (sm.StateId == EStateId.IDLE)
                 * {
                 *  System.Media.SoundPlayer player = new System.Media.SoundPlayer();
                 *  player.SoundLocation = "Sounds\\disconnect.wav";
                 *  player.Load();
                 *  player.Play();
                 * }*/

                if (curCallInfoDG.SelectedRows.Count > 0)
                {
                    v_hCall = CallManager.getCall(ActiveCallList[curCallInfoDG.SelectedRows[0].Index].SessionID);
                }

                CallInfo ci = ActiveCallList.Find(p => p.SessionID == iSessionId);

                if (ci != null)
                {
                    if (ci.isIncoming)
                    {
                        listener.SendResponse("{\"Event\":\"Cancel\",\"Call-ID\":\"" + ci.SessionID.ToString() + "@1.1.1.1:5060\",\"From\":\"sip:" + ci.Phone + "@1.1.1.1\",\"To\":\"sip:" + DeliveryRI.Login + "@1.1.1.1:8780\"}");
                    }

                    dataGridView2.Rows.Add(ci.Phone, (DateTime.Now - sm.Duration).ToString("dd.MM.yyyy HH:mm:ss"), sm.Duration.ToString(@"hh\:mm\:ss"), "ОК");

                    int ind = ActiveCallList.IndexOf(ci);

                    ActiveCallList.Remove(ci);

                    if (ind >= 0)
                    {
                        curCallInfoDG.Rows.RemoveAt(ind);
                    }
                }
            }

            if (sm.StateId == EStateId.INCOMING || sm.StateId == EStateId.CONNECTING)
            {
                CallInfo ci = new CallInfo();
                ci.Phone      = sm.CallingNumber;
                ci.CallDT     = DateTime.Now;
                ci.dt         = DateTime.Now;
                ci.SessionID  = sm.Session;
                ci.isIncoming = sm.Incoming;
                ActiveCallList.Add(ci);
                curCallInfoDG.Rows.Add(ci.Phone, ci.Duration);

                if (sm.StateId == EStateId.ALERTING)
                {
                    curCallInfoDG.Rows[curCallInfoDG.Rows.Count - 1].Selected = true;
                }
            }

            if (sm.StateId == EStateId.ACTIVE)
            {
                System.Media.SoundPlayer player = new System.Media.SoundPlayer();
                player.SoundLocation = "Sounds\\aa.wav";
                player.Load();
                player.Play();
            }

            if (sm.IsHeld)
            {
                rejectButton.Checked = true;
            }
            else
            {
                rejectButton.Checked = false;
            }

            if (ActiveCallList.Count > 0)
            {
                rejectButton.Enabled = true;
                holdButton.Enabled   = true;
                timer1.Enabled       = true;
            }
            else
            {
                rejectButton.Enabled = false;
                holdButton.Enabled   = false;
                timer1.Enabled       = false;
            }
        }
Exemplo n.º 5
0
        private void bbtnRegister_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            StackProxy.initialize();
            CallManager.StackProxy = StackProxy;

            Config.CFNRFlag            = false;
            Config.CFUFlag             = false;
            Config.DefaultAccountIndex = 0;
            Config.AAFlag  = Settings.AutoAnswer;
            Config.DNDFlag = Settings.DoNotDisturb;

            if (Config.Accounts.Count > 0)
            {
                Registrar.unregisterAccounts();
            }
            Config.Accounts.Clear();

            AccountConfig acc = new AccountConfig();

            acc.AccountName   = Settings.UserName;
            acc.DisplayName   = Settings.UserName;
            acc.DomainName    = Settings.Domain;
            acc.HostName      = Settings.Host;
            acc.Password      = Settings.Password;
            acc.TransportMode = ETransportMode.TM_UDP;
            acc.UserName      = Settings.UserName;
            acc.Id            = Settings.UserName;
            acc.ProxyAddress  = "";
            Config.Accounts.Add(acc);

            //ConfigStruct.listenPort = Settings.Port;
            //ConfigStruct.noUDP = false;
            //ConfigStruct.noTCP = true;
            //ConfigStruct.stunServer = "";
            //ConfigStruct.publishEnabled = false;
            //ConfigStruct.expires = 3600;
            //ConfigStruct.VADEnabled = true;
            //ConfigStruct.ECTail = 200;
            //ConfigStruct.nameServer = Settings.Host;
            //ConfigStruct.pollingEventsEnabled = false;


            CallManager.Config = Config;
            StackProxy.Config  = Config;
            Registrar.Config   = Config;
            pjsipPresenceAndMessaging.Instance.Config = Config;

            CallManager.CallStateRefresh -= CallManager_CallStateRefresh;
            CallManager.CallStateRefresh += CallManager_CallStateRefresh;
            //CallManager.IncomingCallNotification += CallManager_IncomingCallNotification;

            Registrar.AccountStateChanged -= Instance_AccountStateChanged;
            Registrar.AccountStateChanged += Instance_AccountStateChanged;

            if (CallManager.Initialize() == 0)
            {
                Registrar.registerAccounts();
            }
            else
            {
                lMessages.Caption = "Popraw ustawienia.";
                lStatus.Caption   = "Nie połączono";
                timerMessages.Start();
            }

            int noOfCodecs = StackProxy.getNoOfCodecs();

            for (int i = 0; i < noOfCodecs; i++)
            {
                string codecname = StackProxy.getCodec(i);
                StackProxy.setCodecPriority(codecname, 128);
            }

            StackProxy.DtmfDigitReceived -= Instance_DtmfDigitReceived;
            StackProxy.DtmfDigitReceived += Instance_DtmfDigitReceived;
        }
Exemplo n.º 6
0
 private void buttonReleaseCall_Click(object sender, EventArgs e)
 {
     textBoxDial.Clear();
     CallManager.onUserRelease(_call.Session);
 }
Exemplo n.º 7
0
 private void CallManager_CallAppeared(CallManager sender, Call args)
 {
     RefreshCallNotification();
     _CallHandler.Set();
 }
Exemplo n.º 8
0
 private void buttonMakeCall_Click(object sender, EventArgs e)
 {
     _call = CallManager.createOutboundCall(textBoxDial.Text);
 }
Exemplo n.º 9
0
 private void OnStateUpdate(int sessionId)
 {
     textBoxCallState.Text = CallManager.getCall(sessionId).StateId.ToString();
 }
Exemplo n.º 10
0
 private void CallManager_CallAppeared(CallManager sender, Call call)
 {
     call.StateChanged += Call_StateChanged;
 }
Exemplo n.º 11
0
 private void CallManager_CurrentCallsChanged(CallManager sender, CallCounts args)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Manager = new CallManager(this);
     ButtonSet(false, false, false);
 }