Ejemplo n.º 1
0
 /// <summary>
 /// Start the auto answer recorder.
 /// </summary>
 /// <param name="recordFilename">The path and filename where the conversation is to be recorded to. Currently ".wav" is supported on all platforms.</param>
 public void StartAutoAnswerRecorder(string recordFilename)
 {
     if (_recorderAutoAnswer == null)
     {
         try
         {
             // If audio device exists.
             if (_audioMedias.Count > 0)
             {
                 // Create the recorder.
                 _recorderAutoAnswer = new AudioMediaRecorder();
                 _recorderAutoAnswer.CreateRecorder(recordFilename, 0, 0, 0);
                 _recorderAutoAnswer.Start(_audioMedias[0]);
             }
             else
             {
                 // No audio media device has been captured.
                 throw new Exception("No audio media has been detected.");
             }
         }
         catch (Exception)
         {
             try
             {
                 _recorderAutoAnswer.Dispose();
             }
             catch { }
             _recorderAutoAnswer = null;
             throw;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Notify application when call state has changed.
        /// Application may then query the call info to get the
        /// detail call states by calling getInfo() function.
        /// </summary>
        /// <param name="sender">The current sender.</param>
        /// <param name="e">The event parameter.</param>
        private void _call_OnCallState(object sender, OnCallStateParam e)
        {
            Nequeo.Net.PjSip.CallInfo ci = e.Info;
            if (ci != null)
            {
                _info = null;
                try
                {
                    // Create the call info.
                    _info                 = new CallInfoParam();
                    _info.CallID          = ci.Id;
                    _info.Guid            = _guid;
                    _info.Contact         = ci.RemoteContact;
                    _info.FromTo          = ci.RemoteUri;
                    _info.Date            = DateTime.Now;
                    _info.ConnectDuration = new TimeSpan(0, 0, 0, ci.ConnectDuration.Seconds, ci.ConnectDuration.Milliseconds);
                    _info.TotalDuration   = new TimeSpan(0, 0, 0, ci.TotalDuration.Seconds, ci.TotalDuration.Milliseconds);
                }
                catch { _info = null; }

                Param.CallStateParam callState = new CallStateParam();
                callState.CallID   = ci.Id;
                callState.State    = ci.State;
                callState.CallInfo = _info;

                try
                {
                    // Handle the event.
                    OnCallState?.Invoke(this, callState);

                    // Set the contact name.
                    _info.ContactName = callState.ContactName;
                }
                catch { }

                // If call is disconnected.
                if ((ci.State == InviteSessionState.PJSIP_INV_STATE_DISCONNECTED) ||
                    (ci.State == InviteSessionState.PJSIP_INV_STATE_NULL))
                {
                    // If current call.
                    if (e.CurrentCall != null)
                    {
                        try
                        {
                            // Cleanup the call.
                            e.CurrentCall.Dispose();
                            e.CurrentCall = null;
                        }
                        catch { }
                    }

                    // If recoder.
                    if (_recorder != null)
                    {
                        try
                        {
                            // Stop the recorder.
                            AudioMedia audioMedia = _mediaManager.GetCaptureDeviceMedia();
                            _recorder.Stop(audioMedia);
                        }
                        catch { }

                        try
                        {
                            // Cleanup the recoder.
                            _recorder.Dispose();
                            _recorder = null;
                        }
                        catch { }
                    }

                    // If auto answer recoder.
                    if (_recorderAutoAnswer != null)
                    {
                        try
                        {
                            // Cleanup the recoder.
                            _recorderAutoAnswer.Dispose();
                            _recorderAutoAnswer = null;
                        }
                        catch { }
                    }

                    // If sound player.
                    if (_player != null)
                    {
                        try
                        {
                            // Cleanup the recoder.
                            _player.Dispose();
                            _player = null;
                        }
                        catch { }
                    }

                    // If video window.
                    if (_videoWindow != null)
                    {
                        try
                        {
                            _hasVideo = false;

                            // Cleanup the video window.
                            _videoWindow.Dispose();
                            _videoWindow = null;
                        }
                        catch { }
                    }

                    // Cleanup the audio media.
                    if (_audioMedias != null)
                    {
                        _audioMedias.Clear();
                        _audioMedias = null;
                    }
                }

                // If call is disconnected.
                if ((ci.State == InviteSessionState.PJSIP_INV_STATE_DISCONNECTED) ||
                    (ci.State == InviteSessionState.PJSIP_INV_STATE_NULL))
                {
                    try
                    {
                        // Handle the event.
                        OnCallDisconnected?.Invoke(this, _info);
                    }
                    catch { }
                }
            }
        }