public void TestCheckVideoCaptureDevicesAvability()
        {
            Softphone            softphoneInstance = null;
            IEnumerable <Device> videoDevs         = null;

            try
            {
                var testAccount = new Account(
                    login: "******",
                    password: "******",
                    host: "192.168.156.2",
                    accountName: "TestUser");

                softphoneInstance = new Softphone(testAccount);

                softphoneInstance.Connect();
                Task.Delay(ConnectionDelay).Wait();

                videoDevs = softphoneInstance.MediaController.GetVideoCaptureDevices();
            }
            finally
            {
                softphoneInstance.Disconnect();
            }
            Assert.IsTrue(videoDevs.Any());
        }
        public void TestSetVideoCaptureDevice()
        {
            Softphone            softphoneInstance = null;
            IEnumerable <Device> videoDevs         = null;
            Device mock = null;

            try
            {
                var testAccount = new Account(
                    login: "******",
                    password: "******",
                    host: "192.168.156.2",
                    accountName: "TestUser");

                softphoneInstance = new Softphone(testAccount);

                softphoneInstance.Connect();
                Task.Delay(ConnectionDelay).Wait();

                videoDevs = softphoneInstance.MediaController.GetVideoCaptureDevices();

                if (videoDevs.Any())
                {
                    mock = videoDevs.FirstOrDefault();
                    softphoneInstance.MediaController.VideoCaptureDevice = mock;
                }
            }
            finally
            {
                softphoneInstance.Disconnect();
            }
            Assert.AreSame(mock, softphoneInstance.MediaController.VideoCaptureDevice);
        }
Пример #3
0
        // Event hendlers for incoming call
        #region IncomingCallEvents

        private void btnAccept_Click(object sender, RoutedEventArgs e)
        {
            if (this.call != null)
            {
                // resume call
                if (this.call.State == Call.CallState.Hold)
                {
                    // discard blur effect to infoPanel
                    if (borderCallNotification.BitmapEffect != null)
                    {
                        borderCallNotification.BitmapEffect = null;
                        borderCallNotification.Background   = null;
                    }
                    // resume
                    Softphone.ResumeCall(this.call);

                    // Play notification
                    LocalAudioPlayer.PlaySound(Properties.Resources.incoming_chat);
                }
                else
                {
                    // receive call
                    Softphone.ReceiveCall(this.call);
                }
            }
        }
Пример #4
0
        public void TestSoftphoneServerConnection()
        {
            Softphone softphoneInstance = null;

            try
            {
                // using office sip for testing
                var testAccount = new Account(
                    login: "******",
                    password: "******",
                    host: "192.168.156.2",
                    accountName: "TestUser");

                softphoneInstance = new Softphone(testAccount);

                softphoneInstance.Connect();

                Task.Delay(ConnectionDelay).Wait();

                Assert.AreEqual(lindotnet.Classes.ConnectState.Connected, softphoneInstance.ConnectState);
            }
            finally
            {
                softphoneInstance.Disconnect();
            }
        }
Пример #5
0
        public void RegisterSipAccount(AccountModel model)
        {
            try
            {
                if (model == null)
                {
                    return;
                }

                if (PhoneLine != null)
                {
                    PhoneLine.RegistrationStateChanged -= phoneLine_RegistrationStateChanged;
                }

                var account = new SIPAccount(model.RegistrationRequired, model.DisplayName, model.UserName, model.RegisterName, model.Password, model.Domain, model.OutboundProxy);
                PhoneLine = Softphone.CreatePhoneLine(account);
                PhoneLine.RegistrationStateChanged += phoneLine_RegistrationStateChanged;
                Softphone.RegisterPhoneLine(PhoneLine);
                Log.Write(string.Format("Registering phone line " + model.UserName));
            }
            catch (Exception exception)
            {
                Log.Write("Error during SIP registration: " + exception.Message);
                MessageBox.Show("Error during SIP registration: " + exception.Message);
            }
        }
Пример #6
0
        /// <summary>
        ///  Нажатие на кнопку соединить\ разъединить
        /// </summary>
        private void btnConnectOrReject_Click(object sender, RoutedEventArgs e)
        {
            switch (Softphone.CurrentLineState)
            {
            case Phone.LineState.Busy:
            {
                // Если введеный номер является номер перевода -> переводим на указанный номер
                if (isTransferNumber(txtPhoneNumber.Text))
                {
                    string text   = txtPhoneNumber.Text;
                    string number = text.Replace("#", "");        // remove all '#'
                    CallTransferTo(number);
                    return;
                }
                // Разрываем активное соединение
                else if (this.call != null)
                {
                    Softphone.TerminateCall(call);
                }
            }
            break;

            case Phone.LineState.Free:
            {
                // Вызов номера
                string phoneNumber = txtPhoneNumber.Text;
                CallTo(phoneNumber);
            }
            break;
            }
        }
Пример #7
0
        public void TestSofpthoneSendMessage()
        {
            Softphone softphoneInstance = null;
            string    mock = "MockMockMock 012456789";

            try
            {
                var testAccount = new Account(
                    login: "******",
                    password: "******",
                    host: "192.168.156.2",
                    accountName: "TestUser");

                softphoneInstance = new Softphone(testAccount);

                softphoneInstance.Connect();

                Task.Delay(ConnectionDelay).Wait();

                if (softphoneInstance.ConnectState == ConnectState.Connected)
                {
                    softphoneInstance.SendMessage(ExampleURI, mock);
                }
                else
                {
                    throw new LinphoneException("Phone not connected!");
                }
            }
            finally
            {
                softphoneInstance.Disconnect();
            }
        }
Пример #8
0
        // Входящий звонок
        private void softphone_IncomingCallEvent(Call incomingCall)
        {
            // Reject incoming call, if we have active
            if (this.call != null)
            {
                Softphone.TerminateCall(incomingCall);

                // write rejected call to base
                RecordToLocalDataBase.Phone      = GetPhone(incomingCall.From);
                RecordToLocalDataBase.TimeStart  = DateTime.Now;
                RecordToLocalDataBase.isRejected = true;

                return;
            }
            ;

            // set flag
            isIncoming = true;
            // Recieve incoming call
            this.call = incomingCall;

            //Echo cancellation
            Softphone.EchoCancellation(this.call, Settings.isEchoOff);

            string phone  = GetPhone(this.call.From);
            string callId = GetCallId(this.call.From);

            InvokeGUIThread(() =>
            {
                dialog = new IncomingDialog();
                // show incoming call dialog
                dialog.Call      = this.call;
                dialog.SoftPhone = Softphone;
                dialog.UpdateTextPanel(phone, callId);

                dialog.Show();

                // change icon to incoming call
                this.txtStatus.Text  = "Занят";
                lblStatusRecord.Text = "Входящий";
                PhoneIcon.SetResourceReference(Image.SourceProperty, "decline");
                StatusIcon.SetResourceReference(Image.SourceProperty, "presence_not_available");
                this.btnConnectOrReject.Background = Brushes.Red;
            });

            // Play Sound
#pragma warning disable CS0103 // The name 'Properties' does not exist in the current context
#pragma warning disable CS0103 // The name 'Properties' does not exist in the current context
            Classes.LocalAudioPlayer.PlaySound(Properties.Resources.signal, true);
#pragma warning restore CS0103 // The name 'Properties' does not exist in the current context
#pragma warning restore CS0103 // The name 'Properties' does not exist in the current context

            // record call info
            RecordToLocalDataBase.Phone     = phone;
            RecordToLocalDataBase.TimeStart = DateTime.Now;

            // Get information about caller
            GetInfoAboutCaller(call.From);
        }
Пример #9
0
 private void btnReject_Click(object sender, RoutedEventArgs e)
 {
     // отклоняем звонок
     if (this.call != null)
     {
         Softphone.TerminateCall(this.call);
     }
 }
Пример #10
0
        public void UnregisterPhoneLine()
        {
            if (PhoneLine == null)
            {
                return;
            }

            Softphone.UnregisterPhoneLine(PhoneLine);
        }
Пример #11
0
        /// <summary>



        private void InitSoftphone()
        {
            mySoftphone = new Softphone();
            mySoftphone.PhoneLineStateChanged += mySoftphone_PhoneLineStateChanged;
            mySoftphone.CallStateChanged      += mySoftphone_CallStateChanged;
            mySoftphone.IncomingCall          += mySoftphone_IncomingCall;

            numberToTransfer = string.Empty;
            numberToCall     = string.Empty;
            exampleSteps     = string.Empty;
        }
Пример #12
0
        private void CallTransferTo(string transferNumber)
        {
            // Если введеный номер не правильный или [object]call == nil -> выход
            if (this.call == null || string.IsNullOrEmpty(transferNumber))
            {
                return;
            }
#warning MakeTransferNatieve
            Softphone.TransferCall(this.call, transferNumber);

            LocalAudioPlayer.PlaySound(Properties.Resources.notification_translate);
        }
Пример #13
0
        public void CreateSoftphoneInstance()
        {
            // using office sip for testing
            var testAccount = new Account(
                login: "******",
                password: "******",
                host: "192.168.156.2",
                accountName: "TestUser");

            var softphoneInstance = new Softphone(testAccount);

            Assert.IsNotNull(softphoneInstance);
        }
Пример #14
0
        private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // hold on call
            if (this.call != null)
            {
                Softphone.TerminateCall(this.call);
            }

            // close all conenctions
            Softphone.Disconnect();

            // application shutdown
            App.Current.Shutdown();
        }
Пример #15
0
        // Звонок принят или исходящий
        private void softphone_CallActiveEvent(Call call)
        {
            if (isIncoming)
            {
                // sound notification off
                Classes.LocalAudioPlayer.StopSound();

                if (dialog != null)
                {
                    dialog.Close();
                }

                // write incoming call to base
                RecordToLocalDataBase.Phone      = GetPhone(call.From);
                RecordToLocalDataBase.TimeStart  = DateTime.Now;
                RecordToLocalDataBase.isRejected = false;
            }
            else
            {
                this.call = call;
                // set outcoming call flag
                isOutcoming = true;

                // Disable echo
                Softphone.EchoCancellation(this.call, Settings.isEchoOff);
                string phone = GetPhone(call.To);

                //show caller info
                GetInfoAboutCaller(call.To);

                InvokeGUIThread(() =>
                {
                    txtStatus.Text       = "Занят";
                    lblStatusRecord.Text = "Исходящий";
                    PhoneIcon.SetResourceReference(System.Windows.Controls.Image.SourceProperty, "decline");
                    StatusIcon.SetResourceReference(Image.SourceProperty, "presence_not_available");
                    btnConnectOrReject.Background = Brushes.Red;
                });

                // set volume
                Softphone.SetSpeakerValue(this.call, (float)volumeSliderValue);

                // db record
                RecordToLocalDataBase.Phone       = phone;
                RecordToLocalDataBase.isOutcoming = true;
                RecordToLocalDataBase.TimeStart   = DateTime.Now;
                //Classes.SQLiteBase.AddRecordToDataBase(RecordToLocalDataBase);
            }
        }
Пример #16
0
        public void StartMonitoring(string sip, string extention, IntPtr handle = default(IntPtr))
        {
            var key = "UDoyMDMzLTEyLTI1LFVQOjIwMzMtMDEtMDEsTUNDOjUwMCxNUEw6NTAwLE1TTEM6NTAwLE1GQzo1MDAsRzcyOTp0cnVlLE1XUEM6NTAwLE1JUEM6NTAwfE" +
                      "xGSTZEMDd6R3NNZlZUU3pHM1Uwb2dXNXlLNkV3SncxcitpZU90Zm9xN2dFV2d5R0tSMlc3dXZFODA2Q0NvaGR1b3V4N1VjY2VaamZMdnRPemtuTk1nPT0=";
            // For user name you can put any user name it wll work.
            var userName = "******";

            LicenseManager.Instance.SetLicense(userName, key);
            _softphone              = new Softphone();
            _softphone.IncomigCall += softphone_IncomigCall;
            _softphone.Register(true, extention, extention, extention, extention, sip.Substring(0, sip.IndexOf(':')), Convert.ToInt32(sip.Substring(sip.IndexOf(':'))));
            SetHookOffTimerInterval(10000);

            LogMessageValue?.Invoke("Monitoring Started Successfully!");
        }
Пример #17
0
        // изменение ползунка с громкостью
        private void volumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            InvokeGUIThread(() =>
            {
                // change graphics
                volumeSliderValue = this.volumeSlider.Value;

                this.volumeSlider.SelectionEnd = volumeSliderValue;
            });

            // set new volume
            if (this.call != null)
            {
                Softphone.SetSpeakerValue(this.call, (float)volumeSliderValue);
            }
        }
Пример #18
0
        private void btnPauseCall_Click(object sender, RoutedEventArgs e)
        {
            // Если удерживаем звонок
            if (this.call != null)
            {
#warning HoldCallDisactieve
                // add call to call stack
                Softphone.HoldCall(this.call);
                //Softphone.HoldCall(this.call);
                Classes.LocalAudioPlayer.PlaySound(Properties.Resources.notification_delayed);
                // apply blur effect to infoPanel
                BlurBitmapEffect effect = new BlurBitmapEffect();
                borderCallNotification.Background = Brushes.LightGray;
                effect.Radius     = 4;
                effect.KernelType = KernelType.Gaussian;
                borderCallNotification.BitmapEffect = effect;
            }
        }
Пример #19
0
        public void StartCall(string dial)
        {
            if (Call != null)
            {
                return;
            }

            var dialParams = new DialParameters(dial)
            {
                CallType = CallType.AudioVideo
            };
            var call = Softphone.CreateCallObject(PhoneLine, dialParams);

            call.CallStateChanged += SingleCall_CallStateChanged;
            ConnectToCall(call);
            call.Start();

            Call = call;
        }
Пример #20
0
        /// <summary>
        /// Вызов номера по телефону
        /// </summary>
        /// <param name="phoneNumber"></param>
        private void CallTo(string phoneNumber)
        {
            if (this.call != null)
            {
                return;
            }

            if (String.IsNullOrEmpty(phoneNumber))
            {
                return;
            }

            // Check phone number
            if (!IsPhoneNumber(phoneNumber))
            {
                MessageBox.Show(string.Concat("Неправильный телефонный номер : '", phoneNumber, "'!"));
                return;
            }

            Softphone.MakeCall(phoneNumber);
        }
Пример #21
0
        public void TestCallToAnotherSoftphone()
        {
            Softphone softphoneInstance = null;
            Call      currentCall       = null;

            try
            {
                // using office sip for testing
                var testAccount = new Account(
                    login: "******",
                    password: "******",
                    host: "192.168.156.2",
                    accountName: "TestUser");

                softphoneInstance = new Softphone(testAccount);

                softphoneInstance.CallActiveEvent += (call) =>
                {
                    Task.Delay(ConnectionDelay).Wait();
                    softphoneInstance.TerminateCall(call);
                    Assert.IsNotNull(call);
                };

                softphoneInstance.Connect();

                Task.Delay(ConnectionDelay).Wait();

                softphoneInstance.MakeCall(ExampleURI);

                Task.Delay(CallTime).Wait();
            }
            finally
            {
                softphoneInstance.Disconnect();
            }
        }
Пример #22
0
 private async void frm_main_Load(object sender, EventArgs e)
 {
     _softphone = new Softphone();
     _softphone.InitializeSoftPhone();
     await InvokeGUIThread(() => { lsLog.DataSource = _softphone._message; });
 }