Ejemplo n.º 1
0
        /// <summary>
        /// This will be called when an incoming call received.
        /// </summary>
        private void SoftPhone_IncomingCall(object sender, VoIPEventArgs <IPhoneCall> e)
        {
            IPhoneCall call = e.Item;

            SubscribeToCallEvents(call);

            // automatically rejected for some reason
            if (call.CallState == CallState.Error)
            {
                CallHistory.Add(call);
                return;
            }

            // add to call container
            PhoneCalls.Add(call);

            // if no call is in progress, select the incoming call as current call and attach the audio to hear the ringtone
            if (SelectedCall == null)
            {
                SelectedCall = call;
                MediaHandlers.AttachAudio(call);
            }

            // raise IncomingCall event
            OnIncomingCall(call);
        }
        public SoftphoneEngine()
        {
            _sync = new object();

            // set license here

            PhoneLines = new ObservableList<IPhoneLine>();
            PhoneCalls = new ObservableList<IPhoneCall>();
            LogEntries = new ObservableList<LogEntry>();
            InstantMessages = new ObservableList<string>();
            CallHistory = new CallHistory();
            CallTypes = new List<CallType> { CallType.Audio, CallType.AudioVideo };

            // enable file logging
            InitLogger();

            // create softphone
            MinPort = 20000;
            MaxPort = 20500;
            //LocalIP = SoftPhoneFactory.GetLocalIP();
            InitSoftphone(false);

            // create media
            MediaHandlers = new MediaHandlers();
            MediaHandlers.Init();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Disposes the softphone engine. Hangs up calls, unregisters phone lines and disposes the media handlers.
        /// </summary>
        public void Dispose()
        {
            lock (_sync)
            {
                PhoneCalls.Clear();

                // unregister phone lines
                foreach (IPhoneLine line in PhoneLines)
                {
                    if (line.RegState == RegState.RegistrationSucceeded)
                    {
                        softPhone.UnregisterPhoneLine(line);
                    }

                    UnsubscribeFromLineEvents(line);
                    line.Dispose();
                }
                PhoneLines.Clear();

                // dispose media
                MediaHandlers.Dispose();

                // close softphone
                softPhone.Close();
            }
        }
Ejemplo n.º 4
0
        public SoftphoneEngine()
        {
            _sync = new object();


            // set license here

            PhoneLines      = new ObservableList <IPhoneLine>();
            PhoneCalls      = new ObservableList <IPhoneCall>();
            LogEntries      = new ObservableList <LogEntry>();
            InstantMessages = new ObservableList <string>();
            CallHistory     = new CallHistory();
            CallTypes       = new List <CallType> {
                CallType.Audio, CallType.AudioVideo
            };

            _subs = new ConcurrentDictionary <IPhoneLine, ISIPSubscription>();

            // enable file logging
            InitLogger();

            // create softphone
            MinPort = 20000;
            MaxPort = 20500;
            //LocalIP = SoftPhoneFactory.GetLocalIP();
            InitSoftphone(false);

            // create media
            MediaHandlers = new MediaHandlers();
            MediaHandlers.Init();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Starts the DTMF signalling.
        /// </summary>
        public void StartDtmfSignal(DtmfNamedEvents signal)
        {
            MediaHandlers.StartDtmf(signal);

            if (SelectedCall == null)
            {
                return;
            }

            SelectedCall.StartDTMFSignal(signal);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Stops the DTMF singalling.
        /// </summary>
        internal void StopDtmfSignal(DtmfNamedEvents signal)
        {
            MediaHandlers.StopDtmf(signal);

            if (SelectedCall == null)
            {
                return;
            }

            SelectedCall.StopDTMFSignal(signal);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This will be called when an error occurred during the call.
        /// </summary>
        private void Call_CallErrorOccured(object sender, VoIPEventArgs <CallError> e)
        {
            IPhoneCall call = sender as IPhoneCall;

            if (sender == null)
            {
                return;
            }

            MediaHandlers.DetachAudio();
            MediaHandlers.DetachVideo();
            DisposeCall(call);

            OnPhoneCallStateChanged(call);
        }
Ejemplo n.º 8
0
        private void CheckStopRingtone()
        {
            bool stopRinging = true;

            foreach (var phoneCall in PhoneCalls)
            {
                if (phoneCall.IsIncoming && phoneCall.CallState.IsRinging())
                {
                    stopRinging = false;
                    break;
                }
            }

            if (stopRinging)
            {
                MediaHandlers.StopRingtone();
            }
        }
Ejemplo n.º 9
0
        private void StartCall(IPhoneCall call)
        {
            lock (_sync)
            {
                if (call == null)
                {
                    return;
                }

                SubscribeToCallEvents(call);
                call.Start();
                MediaHandlers.LoadSpeechToText();
                PhoneCalls.Add(call);

                if (SelectedCall == null)
                {
                    SelectedCall = call;
                }
            }
        }
Ejemplo n.º 10
0
        public SoftphoneEngine()
        {
            // set license here

            PhoneLines      = new ObservableList <IPhoneLine>();
            PhoneCalls      = new ObservableList <IPhoneCall>();
            InstantMessages = new ObservableList <string>();
            CallHistory     = new CallHistory();
            CallTypes       = new List <CallType> {
                CallType.Audio, CallType.AudioVideo
            };

            // create softphone
            MinPort = 20000;
            MaxPort = 20500;
            //LocalIP = SoftPhoneFactory.GetLocalIP();
            InitSoftphone(false);

            // create media
            MediaHandlers = new MediaHandlers();
            MediaHandlers.Init();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This will be called when the state of a call has changed.
        /// </summary>
        private void Call_CallStateChanged(object sender, VoIPEventArgs <CallState> e)
        {
            IPhoneCall call = sender as IPhoneCall;

            if (call == null)
            {
                return;
            }

            CallState state = e.Item;

            OnPhoneCallStateChanged(call);
            CheckStopRingback();
            CheckStopRingtone();

            // start ringtones
            if (state.IsRinging())
            {
                if (call.IsIncoming)
                {
                    MediaHandlers.StartRingtone();
                }
                else
                {
                    MediaHandlers.StartRingback();
                }

                return;
            }

            // call has been answered
            if (state == CallState.Answered)
            {
                return;
            }

            // attach media to the selected call when the remote party sends media data
            if (state.IsRemoteMediaCommunication())
            {
                if (SelectedCall.Equals(call))
                {
                    MediaHandlers.AttachAudio(call);
                    MediaHandlers.AttachAudio(call);
                }
                return;
            }

            // detach media from the selected call in hold state or when the call has ended
            if (state == CallState.LocalHeld || state == CallState.InactiveHeld || state.IsCallEnded())
            {
                if (SelectedCall.Equals(call))
                {
                    MediaHandlers.DetachAudio();
                    MediaHandlers.DetachVideo();
                }
            }

            // call has ended, clean up
            if (state.IsCallEnded())
            {
                DisposeCall(call);

                CallHistory.Add(call);
                PhoneCalls.Remove(call);
                return;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This will be called when the other party stopped DTMF signaling.
        /// </summary>
        private void Call_DtmfReceived(object sender, VoIPEventArgs <DtmfInfo> e)
        {
            DtmfSignal signal = e.Item.Signal;

            MediaHandlers.StopDtmf(signal.Signal);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This will be called when the other party started DTMF signaling.
        /// </summary>
        private void Call_DtmfStarted(object sender, VoIPEventArgs <DtmfInfo> e)
        {
            int signal = e.Item.Signal.Signal;

            MediaHandlers.StartDtmf(signal);
        }