Inheritance: IVoIPClient
Exemplo n.º 1
0
        /// <summary>
        /// Set up the UI to present options for an established SIP call, i.e. hide the cancel
        /// button and display they hangup button.
        /// </summary>
        private void SIPCallAnswered(SIPClient client)
        {
            _mediaManager.StartAudio();

            if (client == _sipClients[0])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_callButton.Visibility     = Visibility.Collapsed;
                    m_cancelButton.Visibility   = Visibility.Collapsed;
                    m_byeButton.Visibility      = Visibility.Visible;
                    m_transferButton.Visibility = Visibility.Visible;
                    m_holdButton.Visibility     = Visibility.Visible;

                    m_call2ActionsGrid.IsEnabled = true;
                });
            }
            else if (client == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_call2Button.Visibility            = Visibility.Collapsed;
                    m_cancel2Button.Visibility          = Visibility.Collapsed;
                    m_bye2Button.Visibility             = Visibility.Visible;
                    m_transfer2Button.Visibility        = Visibility.Visible;
                    m_hold2Button.Visibility            = Visibility.Visible;
                    m_attendedTransferButton.Visibility = Visibility.Visible;
                });
            }
        }
Exemplo n.º 2
0
        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility      = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility    = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall  += SIPCallIncoming;
            _sipClient.CallAnswer    += SIPCallAnswered;
            _sipClient.CallEnded     += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // If a STUN server hostname has been specified start the STUN client to lookup and periodically update the public IP address of the host machine.
            if (!SIPSoftPhoneState.STUNServerHostname.IsNullOrBlank())
            {
                _stunClient = new SoftphoneSTUNClient(SIPSoftPhoneState.STUNServerHostname);
                _stunClient.PublicIPAddressDetected += (ip) =>
                {
                    SIPSoftPhoneState.PublicIPAddress = ip;
                    UIHelper.DoOnUIThread(this, delegate
                    {
                        publicIPAddress.Content = $"Public IP: {ip}";
                    });
                };
                _stunClient.Run();
            }

            Initialise();
        }
Exemplo n.º 3
0
        /// <summary>
        /// When on a call key pad presses will send a DTMF RTP event to the remote
        /// call party.
        /// </summary>
        /// <param name="sender">The button that was pressed.</param>
        /// <param name="e"></param>
        private async void KeyPadButton_Click(object sender, RoutedEventArgs e)
        {
            Button keyButton  = sender as Button;
            char   keyPressed = (keyButton.Content as string).ToCharArray()[0];

            SIPClient client = GetActiveCall();

            if (client == null)
            {
                SetStatusText(m_signallingStatus, $"Key pressed {keyPressed} but no active SIP client to send DTMF to.");
            }
            else
            {
                SetStatusText(m_signallingStatus, $"Key pressed {keyPressed}.");

                if (keyPressed >= 48 && keyPressed <= 57)
                {
                    await client.SendDTMF((byte)(keyPressed - 48));
                }
                else if (keyPressed == '*')
                {
                    await client.SendDTMF((byte)10);
                }
                else if (keyPressed == '#')
                {
                    await client.SendDTMF((byte)11);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Answer an incoming call on the SipClient
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        private async Task AnswerCallAsync(SIPClient client)
        {
            bool result = await client.Answer();

            if (result)
            {
                SIPCallAnswered(client);
            }
            else
            {
                ResetToCallStartState(client);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// The button to place an outgoing call.
        /// </summary>
        private async void CallButton_Click(object sender, RoutedEventArgs e)
        {
            SIPClient client = (sender == m_callButton) ? _sipClients[0] : _sipClients[1];

            if (client == _sipClients[0] && m_uriEntryTextBox.Text.IsNullOrBlank())
            {
                SetStatusText(m_signallingStatus, "No call destination was specified.");
            }
            else if (client == _sipClients[1] && m_uriEntry2TextBox.Text.IsNullOrBlank())
            {
                SetStatusText(m_signallingStatus, "No call destination was specified.");
            }
            else
            {
                string callDestination = null;

                if (client == _sipClients[0])
                {
                    callDestination = m_uriEntryTextBox.Text;

                    SetStatusText(m_signallingStatus, $"calling {callDestination}.");

                    m_callButton.Visibility   = Visibility.Collapsed;
                    m_cancelButton.Visibility = Visibility.Visible;
                    m_byeButton.Visibility    = Visibility.Collapsed;
                }
                else if (client == _sipClients[1])
                {
                    // Put the first call on hold.
                    if (_sipClients[0].IsCallActive)
                    {
                        //_sipClients[0].PutOnHold(_onHoldAudioScopeGL);
                        await _sipClients[0].PutOnHold();
                        m_holdButton.Visibility    = Visibility.Collapsed;
                        m_offHoldButton.Visibility = Visibility.Visible;
                    }

                    callDestination = m_uriEntry2TextBox.Text;

                    SetStatusText(m_signallingStatus, $"calling {callDestination}.");

                    m_call2Button.Visibility   = Visibility.Collapsed;
                    m_cancel2Button.Visibility = Visibility.Visible;
                    m_bye2Button.Visibility    = Visibility.Collapsed;
                }

                // Start SIP call.
                await client.Call(callDestination);
            }
        }
Exemplo n.º 6
0
        private async Task Initialize()
        {
            await _sipTransportManager.InitialiseSIP();

            for (int i = 0; i < SIP_CLIENT_COUNT; i++)
            {
                var mediaSessionFactory = new RTPMediaSessionManager(_mediaManager, _musicOnHold);
                var sipClient           = new SIPClient(_sipTransportManager.SIPTransport, mediaSessionFactory);

                sipClient.CallAnswer        += SIPCallAnswered;
                sipClient.CallEnded         += ResetToCallStartState;
                sipClient.StatusMessage     += (client, message) => { SetStatusText(m_signallingStatus, message); };
                sipClient.RemotePutOnHold   += RemotePutOnHold;
                sipClient.RemoteTookOffHold += RemoteTookOffHold;

                _sipClients.Add(sipClient);
            }

            string listeningEndPoints = null;

            foreach (var sipChannel in _sipTransportManager.SIPTransport.GetSIPChannels())
            {
                SIPEndPoint sipChannelEP = sipChannel.ListeningSIPEndPoint.CopyOf();
                sipChannelEP.ChannelID = null;
                listeningEndPoints    += (listeningEndPoints == null) ? sipChannelEP.ToString() : $", {sipChannelEP}";
            }

            listeningEndPoint.Content = $"Listening on: {listeningEndPoints}";

            _sipRegistrationClient = new SIPRegistrationUserAgent(
                _sipTransportManager.SIPTransport,
                null,
                null,
                new SIPURI(m_sipUsername, m_sipServer, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
                m_sipUsername,
                m_sipPassword,
                null,
                m_sipServer,
                new SIPURI(m_sipUsername, IPAddress.Any.ToString(), null),
                180,
                null,
                null,
                (message) => { logger.Debug(message); });

            _sipRegistrationClient.Start();
        }
Exemplo n.º 7
0
        /// <summary>
        /// We are taking the remote call party off hold.
        /// </summary>
        private void OffHoldButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SIPClient client = (sender == m_offHoldButton) ? _sipClients[0] : _sipClients[1];

            if (client == _sipClients[0])
            {
                m_holdButton.Visibility    = Visibility.Visible;
                m_offHoldButton.Visibility = Visibility.Collapsed;
            }
            else if (client == _sipClients[1])
            {
                m_hold2Button.Visibility    = Visibility.Visible;
                m_offHold2Button.Visibility = Visibility.Collapsed;
            }

            client.TakeOffHold();
        }
Exemplo n.º 8
0
        /// <summary>
        /// We are taking the remote call party off hold.
        /// </summary>
        private void OffHoldButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SIPClient client = (sender == m_offHoldButton) ? _sipClients[0] : _sipClients[1];

            if (client == _sipClients[0])
            {
                m_holdButton.Visibility    = Visibility.Visible;
                m_offHoldButton.Visibility = Visibility.Collapsed;
                //_sipClients[0].MediaSession.OnHoldAudioScopeSampleReady -= _onHoldAudioScope.ProcessSample;
            }
            else if (client == _sipClients[1])
            {
                m_hold2Button.Visibility    = Visibility.Visible;
                m_offHold2Button.Visibility = Visibility.Collapsed;
            }

            client.TakeOffHold();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Reset the UI elements to their initial state at the end of a call.
        /// </summary>
        private void ResetToCallStartState(SIPClient sipClient)
        {
            if (sipClient == null || sipClient == _sipClients[0])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_callButton.Visibility     = Visibility.Visible;
                    m_cancelButton.Visibility   = Visibility.Collapsed;
                    m_byeButton.Visibility      = Visibility.Collapsed;
                    m_answerButton.Visibility   = Visibility.Collapsed;
                    m_rejectButton.Visibility   = Visibility.Collapsed;
                    m_redirectButton.Visibility = Visibility.Collapsed;
                    m_transferButton.Visibility = Visibility.Collapsed;
                    m_holdButton.Visibility     = Visibility.Collapsed;
                    m_offHoldButton.Visibility  = Visibility.Collapsed;
                    _client0Video.Visibility    = Visibility.Collapsed;
                    SetStatusText(m_signallingStatus, "Ready");

                    //if (m_useAudioScope && _sipClients?.Count > 0 && sipClient == _sipClients[0] && sipClient.MediaSession != null)
                    //{
                    //    sipClient.MediaSession.OnAudioScopeSampleReady -= _audioScope0.ProcessSample;
                    //}
                });
            }

            if (sipClient == null || sipClient == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_call2Button.Visibility            = Visibility.Visible;
                    m_cancel2Button.Visibility          = Visibility.Collapsed;
                    m_bye2Button.Visibility             = Visibility.Collapsed;
                    m_answer2Button.Visibility          = Visibility.Collapsed;
                    m_reject2Button.Visibility          = Visibility.Collapsed;
                    m_redirect2Button.Visibility        = Visibility.Collapsed;
                    m_transfer2Button.Visibility        = Visibility.Collapsed;
                    m_hold2Button.Visibility            = Visibility.Collapsed;
                    m_offHold2Button.Visibility         = Visibility.Collapsed;
                    m_attendedTransferButton.Visibility = Visibility.Collapsed;
                    _client1Video.Visibility            = Visibility.Collapsed;
                    SetStatusText(m_signallingStatus, "Ready");
                });
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// The remote call party has taken us off hold.
        /// </summary>
        private void RemoteTookOffHold(SIPClient sipClient)
        {
            SetStatusText(m_signallingStatus, "Taken off hold by remote party.");

            if (sipClient == _sipClients[0])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_holdButton.Visibility = Visibility.Visible;
                });
            }
            else if (sipClient == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_hold2Button.Visibility = Visibility.Visible;
                });
            }
        }
Exemplo n.º 11
0
        private SIPRegistrationUserAgent _sipRegistrationClient;   // Can be used to register with an external SIP provider if incoming calls are required.

        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility      = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility    = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall  += SIPCallIncoming;
            _sipClient.CallAnswer    += SIPCallAnswered;
            _sipClient.CallEnded     += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Set up the Gingle client.
            _gingleClient                = new GingleClient();
            _gingleClient.CallEnded     += ResetToCallStartState;
            _gingleClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Lookup and periodically check the public IP address of the host machine.
            _stunClient = new SoftphoneSTUNClient();

            // Comment this out if you don't want the app to register with your SIP server.
            _sipRegistrationClient = new SIPRegistrationUserAgent(
                _sipClient.SIPClientTransport,
                null,
                null,
                new SIPURI(m_sipUsername, m_sipServer, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
                m_sipUsername,
                m_sipPassword,
                null,
                m_sipServer,
                new SIPURI(m_sipUsername, _sipClient.SIPClientTransport.GetDefaultSIPEndPoint().GetIPEndPoint().ToString(), null),
                180,
                null,
                null,
                (message) => { logger.Debug(message); });
            _sipRegistrationClient.Start();

            //videoElement.NewVideoSample += new EventHandler<WPFMediaKit.DirectShow.MediaPlayers.VideoSampleArgs>(videoElement_NewVideoSample);
        }
Exemplo n.º 12
0
        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall += SIPCallIncoming;
            _sipClient.CallAnswer += SIPCallAnswered;
            _sipClient.CallEnded += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Set up the Gingle client.
            _gingleClient = new GingleClient();
            _gingleClient.CallEnded += ResetToCallStartState;
            _gingleClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Lookup and periodically check the public IP address of the host machine.
            _stunClient = new SoftphoneSTUNClient();

            // Comment this out if you don't want the app to register with your SIP server.
            _sipRegistrationClient = new SIPRegistrationUserAgent(
                _sipClient.SIPClientTransport,
                null,
                null,
                new SIPURI(m_sipUsername, m_sipServer, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
                m_sipUsername,
                m_sipPassword,
                null,
                m_sipServer,
                new SIPURI(m_sipUsername, _sipClient.SIPClientTransport.GetDefaultSIPEndPoint().GetIPEndPoint().ToString(), null),
                180,
                null,
                null,
                (message) => { logger.Debug(message); });
            _sipRegistrationClient.Start();

            //videoElement.NewVideoSample += new EventHandler<WPFMediaKit.DirectShow.MediaPlayers.VideoSampleArgs>(videoElement_NewVideoSample);
        }
Exemplo n.º 13
0
        /// <summary>
        /// The remote call party put us on hold.
        /// </summary>
        private void RemotePutOnHold(SIPClient sipClient)
        {
            // We can't put them on hold if they've already put us on hold.
            SetStatusText(m_signallingStatus, "Put on hold by remote party.");

            if (sipClient == _sipClients[0])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_holdButton.Visibility = Visibility.Collapsed;
                });
            }
            else if (sipClient == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_hold2Button.Visibility = Visibility.Collapsed;
                });
            }
        }
Exemplo n.º 14
0
        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility      = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility    = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall  += SIPCallIncoming;
            _sipClient.CallAnswer    += SIPCallAnswered;
            _sipClient.CallEnded     += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Lookup and periodically check the public IP address of the host machine.
            _stunClient = new SoftphoneSTUNClient();

            Initialise();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Reset the UI elements to their initial state at the end of a call.
        /// </summary>
        private void ResetToCallStartState(SIPClient sipClient)
        {
            if (sipClient == null || sipClient == _sipClients[0])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_callButton.Visibility     = Visibility.Visible;
                    m_cancelButton.Visibility   = Visibility.Collapsed;
                    m_byeButton.Visibility      = Visibility.Collapsed;
                    m_answerButton.Visibility   = Visibility.Collapsed;
                    m_rejectButton.Visibility   = Visibility.Collapsed;
                    m_redirectButton.Visibility = Visibility.Collapsed;
                    m_transferButton.Visibility = Visibility.Collapsed;
                    m_holdButton.Visibility     = Visibility.Collapsed;
                    m_offHoldButton.Visibility  = Visibility.Collapsed;
                    _client0Video.Visibility    = Visibility.Collapsed;
                    SetStatusText(m_signallingStatus, "Ready");
                });
            }

            if (sipClient == null || sipClient == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_call2Button.Visibility            = Visibility.Visible;
                    m_cancel2Button.Visibility          = Visibility.Collapsed;
                    m_bye2Button.Visibility             = Visibility.Collapsed;
                    m_answer2Button.Visibility          = Visibility.Collapsed;
                    m_reject2Button.Visibility          = Visibility.Collapsed;
                    m_redirect2Button.Visibility        = Visibility.Collapsed;
                    m_transfer2Button.Visibility        = Visibility.Collapsed;
                    m_hold2Button.Visibility            = Visibility.Collapsed;
                    m_offHold2Button.Visibility         = Visibility.Collapsed;
                    m_attendedTransferButton.Visibility = Visibility.Collapsed;
                    _client1Video.Visibility            = Visibility.Collapsed;
                    SetStatusText(m_signallingStatus, "Ready");
                });
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initialises the SIP clients and transport.
        /// </summary>
        private async Task Initialize()
        {
            await _sipTransportManager.InitialiseSIP();

            for (int i = 0; i < SIP_CLIENT_COUNT; i++)
            {
                var sipClient = new SIPClient(_sipTransportManager.SIPTransport);

                sipClient.CallAnswer        += SIPCallAnswered;
                sipClient.CallEnded         += ResetToCallStartState;
                sipClient.StatusMessage     += (client, message) => { SetStatusText(m_signallingStatus, message); };
                sipClient.RemotePutOnHold   += RemotePutOnHold;
                sipClient.RemoteTookOffHold += RemoteTookOffHold;

                _sipClients.Add(sipClient);
            }

            string listeningEndPoints = null;

            foreach (var sipChannel in _sipTransportManager.SIPTransport.GetSIPChannels())
            {
                SIPEndPoint sipChannelEP = sipChannel.ListeningSIPEndPoint.CopyOf();
                sipChannelEP.ChannelID = null;
                listeningEndPoints    += (listeningEndPoints == null) ? sipChannelEP.ToString() : $", {sipChannelEP}";
            }

            listeningEndPoint.Content = $"Listening on: {listeningEndPoints}";

            _sipRegistrationClient = new SIPRegistrationUserAgent(
                _sipTransportManager.SIPTransport,
                m_sipUsername,
                m_sipPassword,
                m_sipServer,
                REGISTRATION_EXPIRY);

            _sipRegistrationClient.Start();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Answer an incoming call on the SipClient
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        private async Task AnswerCallAsync(SIPClient client)
        {
            await client.Answer();

            _mediaManager.StartAudio();

            if (client == _sipClients[0])
            {
                m_answerButton.Visibility   = Visibility.Collapsed;
                m_rejectButton.Visibility   = Visibility.Collapsed;
                m_redirectButton.Visibility = Visibility.Collapsed;
                m_byeButton.Visibility      = Visibility.Visible;
                m_transferButton.Visibility = Visibility.Visible;
                m_holdButton.Visibility     = Visibility.Visible;

                m_call2ActionsGrid.IsEnabled = true;
            }
            else if (client == _sipClients[1])
            {
                // Put the first call on hold.
                if (_sipClients[0].IsCallActive)
                {
                    _sipClients[0].PutOnHold();
                    m_holdButton.Visibility    = Visibility.Collapsed;
                    m_offHoldButton.Visibility = Visibility.Visible;
                }

                m_answer2Button.Visibility          = Visibility.Collapsed;
                m_reject2Button.Visibility          = Visibility.Collapsed;
                m_redirect2Button.Visibility        = Visibility.Collapsed;
                m_bye2Button.Visibility             = Visibility.Visible;
                m_transfer2Button.Visibility        = Visibility.Visible;
                m_hold2Button.Visibility            = Visibility.Visible;
                m_attendedTransferButton.Visibility = Visibility.Visible;
            }
        }
Exemplo n.º 18
0
        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility      = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility    = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall  += SIPCallIncoming;
            _sipClient.CallAnswer    += SIPCallAnswered;
            _sipClient.CallEnded     += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Lookup and periodically check the public IP address of the host machine.
            _stunClient = new SoftphoneSTUNClient();

            // Uncomment this if you want the app to register with your SIP server.
            //_sipRegistrationClient = new SIPRegistrationUserAgent(
            //    _sipClient.SIPClientTransport,
            //    null,
            //    null,
            //    new SIPURI(m_sipUsername, m_sipServer, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
            //    m_sipUsername,
            //    m_sipPassword,
            //    null,
            //    m_sipServer,
            //    new SIPURI(m_sipUsername, _sipClient.SIPClientTransport.GetDefaultSIPEndPoint().GetIPEndPoint().ToString(), null),
            //    180,
            //    null,
            //    null,
            //    (message) => { logger.Debug(message); });
            //_sipRegistrationClient.Start();
        }
Exemplo n.º 19
0
        private SoftphoneSTUNClient _stunClient; // STUN client to periodically check the public IP address.

        #endregion Fields

        #region Constructors

        public SoftPhone()
        {
            InitializeComponent();

            // Do some UI initialisation.
            m_uasGrid.Visibility = Visibility.Collapsed;
            m_cancelButton.Visibility = Visibility.Collapsed;
            m_byeButton.Visibility = Visibility.Collapsed;

            // Set up the SIP client. It can receive calls and initiate outgoing calls.
            _sipClient = new SIPClient();
            _sipClient.IncomingCall += SIPCallIncoming;
            _sipClient.CallAnswer += SIPCallAnswered;
            _sipClient.CallEnded += ResetToCallStartState;
            _sipClient.StatusMessage += (message) => { SetStatusText(m_signallingStatus, message); };

            // Lookup and periodically check the public IP address of the host machine.
            _stunClient = new SoftphoneSTUNClient();

            // Uncomment this if you want the app to register with your SIP server.
            //_sipRegistrationClient = new SIPRegistrationUserAgent(
            //    _sipClient.SIPClientTransport,
            //    null,
            //    null,
            //    new SIPURI(m_sipUsername, m_sipServer, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
            //    m_sipUsername,
            //    m_sipPassword,
            //    null,
            //    m_sipServer,
            //    new SIPURI(m_sipUsername, _sipClient.SIPClientTransport.GetDefaultSIPEndPoint().GetIPEndPoint().ToString(), null),
            //    180,
            //    null,
            //    null,
            //    (message) => { logger.Debug(message); });
            //_sipRegistrationClient.Start();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Set up the UI to present options for an established SIP call, i.e. hide the cancel
        /// button and display they hangup button.
        /// </summary>
        private void SIPCallAnswered(SIPClient client)
        {
            if (client == _sipClients[0])
            {
                if (_sipClients[1].IsCallActive && !_sipClients[1].IsOnHold)
                {
                    _sipClients[1].PutOnHold();
                }

                Dispatcher.DoOnUIThread(() =>
                {
                    m_answerButton.Visibility   = Visibility.Collapsed;
                    m_rejectButton.Visibility   = Visibility.Collapsed;
                    m_redirectButton.Visibility = Visibility.Collapsed;
                    m_callButton.Visibility     = Visibility.Collapsed;
                    m_cancelButton.Visibility   = Visibility.Collapsed;
                    m_byeButton.Visibility      = Visibility.Visible;
                    m_transferButton.Visibility = Visibility.Visible;
                    m_holdButton.Visibility     = Visibility.Visible;

                    m_call2ActionsGrid.IsEnabled = true;

                    if (_sipClients[0].MediaSession.HasVideo)
                    {
                        _sipClients[0].MediaSession.OnVideoSampleReady += (sample, width, height, stride) => VideoSampleReady(sample, width, height, stride, _client0WriteableBitmap, _client0Video);
                        _client0Video.Visibility = Visibility.Visible;
                    }
                });
            }
            else if (client == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_answer2Button.Visibility          = Visibility.Collapsed;
                    m_reject2Button.Visibility          = Visibility.Collapsed;
                    m_redirect2Button.Visibility        = Visibility.Collapsed;
                    m_call2Button.Visibility            = Visibility.Collapsed;
                    m_cancel2Button.Visibility          = Visibility.Collapsed;
                    m_bye2Button.Visibility             = Visibility.Visible;
                    m_transfer2Button.Visibility        = Visibility.Visible;
                    m_hold2Button.Visibility            = Visibility.Visible;
                    m_attendedTransferButton.Visibility = Visibility.Visible;

                    if (_sipClients[1].MediaSession.HasVideo)
                    {
                        _sipClients[1].MediaSession.OnVideoSampleReady += (sample, width, height, stride) => VideoSampleReady(sample, width, height, stride, _client1WriteableBitmap, _client1Video);
                        _client1Video.Visibility = Visibility.Visible;
                    }
                });

                if (_sipClients[0].IsCallActive)
                {
                    if (!_sipClients[0].IsOnHold)
                    {
                        _sipClients[0].PutOnHold();
                    }

                    Dispatcher.DoOnUIThread(() =>
                    {
                        m_holdButton.Visibility             = Visibility.Collapsed;
                        m_offHoldButton.Visibility          = Visibility.Visible;
                        m_attendedTransferButton.Visibility = Visibility.Visible;
                    });
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// The button to place an outgoing call.
        /// </summary>
        private void CallButton_Click(object sender, RoutedEventArgs e)
        {
            SIPClient client = (sender == m_callButton) ? _sipClients[0] : _sipClients[1];

            if (client == _sipClients[0] && m_uriEntryTextBox.Text.IsNullOrBlank())
            {
                SetStatusText(m_signallingStatus, "No call destination was specified.");
            }
            else if (client == _sipClients[1] && m_uriEntry2TextBox.Text.IsNullOrBlank())
            {
                SetStatusText(m_signallingStatus, "No call destination was specified.");
            }
            else if (m_uriEntryTextBox.Text == VIDEO_LOOPBACK_CALL_DESTINATION)
            {
                if (_localVideoMode == null)
                {
                    LocalVideoError("Please start the local video and try again.");
                }
                else
                {
                    SetStatusText(m_signallingStatus, "Running video loopback test...");

                    m_callButton.Visibility   = Visibility.Collapsed;
                    m_cancelButton.Visibility = Visibility.Collapsed;
                    m_byeButton.Visibility    = Visibility.Visible;

                    _mediaManager.RunLoopbackTest();
                }
            }
            else
            {
                string callDestination = null;

                if (client == _sipClients[0])
                {
                    callDestination = m_uriEntryTextBox.Text;

                    SetStatusText(m_signallingStatus, $"calling {callDestination}.");

                    m_callButton.Visibility   = Visibility.Collapsed;
                    m_cancelButton.Visibility = Visibility.Visible;
                    m_byeButton.Visibility    = Visibility.Collapsed;
                }
                else if (client == _sipClients[1])
                {
                    // Put the first call on hold.
                    if (_sipClients[0].IsCallActive)
                    {
                        _sipClients[0].PutOnHold();
                        m_holdButton.Visibility    = Visibility.Collapsed;
                        m_offHoldButton.Visibility = Visibility.Visible;
                    }

                    callDestination = m_uriEntry2TextBox.Text;

                    SetStatusText(m_signallingStatus, $"calling {callDestination}.");

                    m_call2Button.Visibility   = Visibility.Collapsed;
                    m_cancel2Button.Visibility = Visibility.Visible;
                    m_bye2Button.Visibility    = Visibility.Collapsed;
                }

                // Start SIP call.
                Task.Run(() => client.Call(callDestination));
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Answer an incoming call on the SipClient
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        private async Task AnswerCallAsync(SIPClient client)
        {
            await client.Answer();

            SIPCallAnswered(client);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Set up the UI to present options for an established SIP call, i.e. hide the cancel
        /// button and display they hangup button.
        /// </summary>
        private async void SIPCallAnswered(SIPClient client)
        {
            if (client == _sipClients[0])
            {
                if (_sipClients[1].IsCallActive && !_sipClients[1].IsOnHold)
                {
                    //_sipClients[1].PutOnHold(_onHoldAudioScopeGL);
                    await _sipClients[1].PutOnHold();
                }

                Dispatcher.DoOnUIThread(() =>
                {
                    m_answerButton.Visibility   = Visibility.Collapsed;
                    m_rejectButton.Visibility   = Visibility.Collapsed;
                    m_redirectButton.Visibility = Visibility.Collapsed;
                    m_callButton.Visibility     = Visibility.Collapsed;
                    m_cancelButton.Visibility   = Visibility.Collapsed;
                    m_byeButton.Visibility      = Visibility.Visible;
                    m_transferButton.Visibility = Visibility.Visible;
                    m_holdButton.Visibility     = Visibility.Visible;

                    m_call2ActionsGrid.IsEnabled = true;

                    if (_sipClients[0].MediaSession.HasVideo)
                    {
                        _sipClients[0].MediaSession.OnVideoSinkSample += (sample, width, height, stride, pixelFormat) => VideoSampleReady(sample, width, height, stride, pixelFormat, _client0WriteableBitmap, _client0Video);
                        _client0Video.Visibility = Visibility.Visible;
                    }

                    //if (m_useAudioScope)
                    //{
                    //    _sipClients[0].MediaSession.OnAudioScopeSampleReady += _audioScope0.ProcessSample;
                    //}
                });
            }
            else if (client == _sipClients[1])
            {
                Dispatcher.DoOnUIThread(() =>
                {
                    m_answer2Button.Visibility          = Visibility.Collapsed;
                    m_reject2Button.Visibility          = Visibility.Collapsed;
                    m_redirect2Button.Visibility        = Visibility.Collapsed;
                    m_call2Button.Visibility            = Visibility.Collapsed;
                    m_cancel2Button.Visibility          = Visibility.Collapsed;
                    m_bye2Button.Visibility             = Visibility.Visible;
                    m_transfer2Button.Visibility        = Visibility.Visible;
                    m_hold2Button.Visibility            = Visibility.Visible;
                    m_attendedTransferButton.Visibility = Visibility.Visible;

                    if (_sipClients[1].MediaSession.HasVideo)
                    {
                        _sipClients[1].MediaSession.OnVideoSinkSample += (sample, width, height, stride, pixelFormat) => VideoSampleReady(sample, width, height, stride, pixelFormat, _client1WriteableBitmap, _client1Video);
                        _client1Video.Visibility = Visibility.Visible;
                    }
                });

                if (_sipClients[0].IsCallActive)
                {
                    if (!_sipClients[0].IsOnHold)
                    {
                        //_sipClients[0].PutOnHold(_onHoldAudioScopeGL);
                        await _sipClients[0].PutOnHold();
                    }

                    Dispatcher.DoOnUIThread(() =>
                    {
                        m_holdButton.Visibility             = Visibility.Collapsed;
                        m_offHoldButton.Visibility          = Visibility.Visible;
                        m_attendedTransferButton.Visibility = Visibility.Visible;
                    });
                }
            }
        }