Beispiel #1
1
        public void CallState(LinphoneCall call, LinphoneCallState state, string message)
        {
            WriteLog("CallState: {0} | {1}", state, message);
            switch (state)
            {
            case LinphoneCallState.IncomingReceived:
                this.UIThreadInvoke(() => AcceptCall(call, message));
                break;

            case LinphoneCallState.OutgoingRinging:
                this.UIThreadInvoke(() => WriteLog("Ringing"));
                break;

            case LinphoneCallState.Connected:
                this.UIThreadInvoke(() => WriteLog("Talking"));
                this.UIThreadInvoke(() => this.btnCall.Text = "Hangup");
                break;

            case LinphoneCallState.CallEnd:
                this.UIThreadInvoke(() => WriteLog("Call ended"));
                this.UIThreadInvoke(() => this.btnCall.Text = "Call");
                break;

            default:
                break;
            }
        }
Beispiel #2
0
 public void CallState(LinphoneCall call, LinphoneCallState state, string message)
 {
     Console.WriteLine("CallState: {0} | {1}", state, message);
     if (state == LinphoneCallState.IncomingReceived)
     {
         this.Lc.AcceptCall(call);
     }
 }
 public void CallState(LinphoneCall call, LinphoneCallState state, string message)
 {
     WriteLog("CallState: {0} | {1}", state, message);
     if (state == LinphoneCallState.IncomingReceived)
     {
         this.Lc.AcceptCall(call);
     }
 }
Beispiel #4
0
        private CallState GetNewCallState(IntPtr call, LinphoneCallState callState,
                                          ref CallType newCallType, ref string from, ref string to, bool recordEnable)
        {
            CallState newCallState;

            switch (callState)
            {
            case LinphoneCallState.LinphoneCallIncomingReceived:
            case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                newCallState = CallState.Loading;
                newCallType  = CallType.Incoming;
                MarshalingExtensions.TryConvert(CallModule.linphone_call_get_remote_address_as_string(call), out from);
                to = Identity;
                break;

            case LinphoneCallState.LinphoneCallConnected:
            case LinphoneCallState.LinphoneCallResuming:
            case LinphoneCallState.LinphoneCallStreamsRunning:
            case LinphoneCallState.LinphoneCallPausedByRemote:
            case LinphoneCallState.LinphoneCallUpdatedByRemote:
                newCallState = CallState.Active;
                break;

            case LinphoneCallState.LinphoneCallPaused:
            case LinphoneCallState.LinphoneCallPausing:
                newCallState = CallState.Hold;
                break;

            case LinphoneCallState.LinphoneCallOutgoingInit:
            case LinphoneCallState.LinphoneCallOutgoingProgress:
            case LinphoneCallState.LinphoneCallOutgoingRinging:
            case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                newCallState = CallState.Loading;
                newCallType  = CallType.Outcoming;
                from         = Identity;
                MarshalingExtensions.TryConvert(CallModule.linphone_call_get_remote_address_as_string(call), out to);
                break;

            case LinphoneCallState.LinphoneCallError:
                newCallState = CallState.Error;
                break;

            case LinphoneCallState.LinphoneCallReleased:
            case LinphoneCallState.LinphoneCallEnd:
                newCallState = CallState.Completed;
                if (recordEnable)
                {
                    GenericModules.linphone_call_stop_recording(call);
                }
                break;

            default:
                throw new NotImplementedException("Sorry, that feature not implemented!");
                break;
            }

            return(newCallState);
        }
Beispiel #5
0
        public void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState callState, string message)
        {
            if (LinphoneCore.IsNonZero() && IsRunning)
            {
                var    newCallState = CallState.None;
                var    newCallType = CallType.None;
                string from, to, recordFile;

                from = to = recordFile = null;
                IntPtr callParams = CallModule.linphone_call_get_params(call);

                bool recordEnable = MarshalingExtensions.TryConvert(CallModule.linphone_call_params_get_record_file(callParams), out recordFile);

                newCallState = GetNewCallState(call, callState, ref newCallType, ref from, ref to, recordEnable);

                UpdateCallReferences(call, newCallState, newCallType, callState, from, to, recordFile);
            }
        }
Beispiel #6
0
        private void UpdateCallReferences(IntPtr call, CallState newCallState, CallType newCallType,
                                          LinphoneCallState callState, string from, string to, string recordFile)
        {
            IntPtr       callref   = CallModule.linphone_call_ref(call);
            LinphoneCall existCall = null;

            if (callref.IsNonZero())
            {
                if (Calls.TryGetValue(callref, out existCall))
                {
                    if (existCall.State != newCallState)
                    {
                        existCall.State = newCallState;
                        CallStateChangedEvent?.Invoke(existCall);
                    }
                }
                else
                {
                    existCall = new LinphoneCall()
                    {
                        State           = newCallState,
                        Type            = newCallType,
                        From            = from,
                        To              = to,
                        RecordFile      = recordFile,
                        LinphoneCallPtr = callref
                    };

                    Calls.TryAdd(callref, existCall);
                    CallStateChangedEvent?.Invoke(existCall);
                }
            }

            if (callState == LinphoneCallState.LinphoneCallReleased)
            {
                CallModule.linphone_call_unref(existCall.LinphoneCallPtr);
                Calls.TryRemove(callref, out existCall);
                return;
            }
        }
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void CallState(LinphoneCall call, LinphoneCallState state, string message)
 {
 }
Beispiel #8
0
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void CallState(LinphoneCall call, LinphoneCallState state, string message)
        {
            if (BaseModel.UIDispatcher == null)
            {
                return;
            }
            if (state == LinphoneCallState.OutgoingProgress)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Outgoing progress\r\n");
                    LookupForContact(call);

                    if (CallListener != null && LinphoneCore.CallsNb > 0)
                    {
                        string sipAddress = call.RemoteAddress.AsStringUriOnly();
                        CallListener.NewCallStarted(sipAddress);
                    }
                });
            }
            else if (state == LinphoneCallState.IncomingReceived)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Incoming received\r\n");
                    if (false) //TODO: Find a proper way to let the user choose between the two.
                    {
                        BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/IncomingCall.xaml?sip=" + Utils.ReplacePlusInUri(call.RemoteAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute));
                        //Remove the current page from the back stack to avoid duplicating him after
                        BaseModel.CurrentPage.NavigationService.RemoveBackEntry();
                    }

                    LookupForContact(call);
                });
            }
            else if (state == LinphoneCallState.Connected)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Connected\r\n");
                    if (CallListener != null)
                    {
                        string sipAddress = call.RemoteAddress.AsStringUriOnly();
                        CallListener.NewCallStarted(sipAddress);
                    }
                });
            }
            else if (state == LinphoneCallState.CallEnd || state == LinphoneCallState.Error)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg(String.Format("[LinphoneManager] Call ended: {0}\r\n", message));
                    if (CallListener != null)
                    {
                        CallListener.CallEnded(call);
                    }
                    string text;
                    switch (call.Reason)
                    {
                    case Reason.LinphoneReasonNone:
                    case Reason.LinphoneReasonNotAnswered:
                        break;

                    case Reason.LinphoneReasonDeclined:
                        if (call.Direction == CallDirection.Outgoing)
                        {
                            text = ResourceManager.GetString("CallErrorDeclined", CultureInfo.CurrentCulture);
                            ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                        }
                        break;

                    case Reason.LinphoneReasonNotFound:
                        text = ResourceManager.GetString("CallErrorNotFound", CultureInfo.CurrentCulture);
                        ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                        break;

                    case Reason.LinphoneReasonBusy:
                        text = ResourceManager.GetString("CallErrorBusy", CultureInfo.CurrentCulture);
                        ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                        break;

                    case Reason.LinphoneReasonNotAcceptable:
                        ShowCallError(ResourceManager.GetString("CallErrorNotAcceptable", CultureInfo.CurrentCulture));
                        break;

                    case Reason.LinphoneReasonIOError:
                        ShowCallError(ResourceManager.GetString("CallErrorIOError", CultureInfo.CurrentCulture));
                        break;

                    default:
                        ShowCallError(ResourceManager.GetString("CallErrorUnknown", CultureInfo.CurrentCulture));
                        break;
                    }
                });
            }
            else if (state == LinphoneCallState.Paused || state == LinphoneCallState.PausedByRemote)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call paused\r\n");
                    bool pausedByRemote = state == LinphoneCallState.PausedByRemote;
                    if (CallListener != null)
                    {
                        CallListener.PauseStateChanged(call, !pausedByRemote, pausedByRemote);
                    }
                });
            }
            else if (state == LinphoneCallState.StreamsRunning)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call running\r\n");
                    if (CallListener != null)
                    {
                        CallListener.PauseStateChanged(call, false, false);
                    }
                });
            }
            else if (state == LinphoneCallState.Released)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call released\r\n");
                });
            }
            else if (state == LinphoneCallState.UpdatedByRemote)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Boolean videoAdded = false;
                    VideoPolicy policy = LinphoneManager.Instance.LinphoneCore.VideoPolicy;
                    LinphoneCallParams remoteParams = call.RemoteParams;
                    LinphoneCallParams localParams  = call.GetCurrentParamsCopy();
                    if (remoteParams.VideoEnabled && !localParams.VideoEnabled && !LinphoneManager.Instance.LinphoneCore.InConference)
                    {
                        if (policy.AutomaticallyAccept)
                        {
                            localParams.VideoEnabled = true;
                            LinphoneManager.Instance.LinphoneCore.AcceptCallUpdate(call, localParams);
                        }
                        else
                        {
                            videoAdded = true;
                        }
                    }
                    else
                    {
                        LinphoneManager.Instance.LinphoneCore.AcceptCallUpdate(call, localParams);
                    }

                    if (CallListener != null)
                    {
                        CallListener.CallUpdatedByRemote(call, videoAdded);
                    }
                });
            }

            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                if (CallStateChanged != null)
                {
                    CallStateChanged(call, state);
                }
            });
        }
        // TODO: Add OnCallStateChanged and OnChatMessageStateChanged.
        void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message)
        {
            if (linphoneCore == IntPtr.Zero || !running)
            {
                return;
            }
            #if (TRACE)
            Console.WriteLine("OnCallStateChanged: {0}", cstate);
            #endif

            Call.State    newstate  = Call.State.Idle;
            Call.CallType newtype   = Call.CallType.None;
            string        from      = "";
            string        to        = "";
            string        peer_name = nameFromAddress(linphone_call_get_remote_address(call));
            IntPtr        addressStringPtr;

            // detecting direction, state and source-destination data by state
            switch (cstate)
            {
            case LinphoneCallState.LinphoneCallIncomingReceived:
                newstate         = Call.State.IncomingRinging;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                    to   = this.identity;
                }
                break;

            case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                newstate         = Call.State.IncomingEarlyMedia;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                    to   = this.identity;
                }
                break;

            case LinphoneCallState.LinphoneCallConnected:
                newstate = Call.State.Connected;
                break;

            case LinphoneCallState.LinphoneCallStreamsRunning:
                newstate = Call.State.StreamsRunning;
                break;

            case LinphoneCallState.LinphoneCallPausedByRemote:
                newstate = Call.State.PausedByRemote;
                break;

            case LinphoneCallState.LinphoneCallUpdatedByRemote:
                newstate = Call.State.UpdatedByRemote;
                break;

            case LinphoneCallState.LinphoneCallOutgoingInit:
                newstate         = Call.State.OutgoingStart;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = this.identity;
                    to   = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                break;

            case LinphoneCallState.LinphoneCallOutgoingProgress:
                newstate = Call.State.InProgress;
                break;

            case LinphoneCallState.LinphoneCallOutgoingRinging:
                newstate = Call.State.OutgoingRinging;
                break;

            case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                newstate         = Call.State.OutgoingEarlyMedia;
                newtype          = Call.CallType.Outcoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = this.identity;
                    to   = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                break;

            case LinphoneCallState.LinphoneCallError:
                newstate = Call.State.Error;
                break;

            case LinphoneCallState.LinphoneCallReleased:
                newstate = Call.State.Released;

                break;

            case LinphoneCallState.LinphoneCallEnd:
                newstate = Call.State.Ended;
                //hangupCall(call);
                if (linphone_call_params_get_record_file(calls_default_params) != IntPtr.Zero)
                {
                    linphone_call_stop_recording(call);
                }
                break;

            default:
                break;
            }

            //Change the calls state or create a new call if it doesn't exist yet
            LinphoneCall existCall = FindCall(call);
            if (existCall == null)
            {
                existCall           = new LinphoneCall();
                existCall.state     = newstate;
                existCall.call_type = newtype;
                existCall.from      = from;
                existCall.to        = to;
                existCall.ptr       = call;
                existCall.peer_name = peer_name;

                calls.Add(existCall);

                if ((CallStateChangedEvent != null))
                {
                    CallStateChangedEvent(existCall);
                }
            }
            else
            {
                if (existCall.state != newstate)
                {
                    existCall.state = newstate;
                    CallStateChangedEvent(existCall);
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="call"></param>
        /// <param name="state"></param>
        public void CallStateChanged(LinphoneCall call, LinphoneCallState state)
        {
            Logger.Dbg("[InCall] Call state changed: " + state.ToString());
            if (state == LinphoneCallState.StreamsRunning || state == LinphoneCallState.Connected)
            {
                buttons.pause.IsEnabled = true;
                buttons.microphone.IsEnabled = true;
                buttons_landscape.pause.IsEnabled = true;
                buttons_landscape.microphone.IsEnabled = true;
                buttons.pauseImg.Opacity = BUTTON_ENABLED_OPACITY;
                buttons.microImg.Opacity = BUTTON_ENABLED_OPACITY;
                buttons_landscape.pauseImg.Opacity = BUTTON_ENABLED_OPACITY;
                buttons_landscape.microImg.Opacity = BUTTON_ENABLED_OPACITY;

                bool isVideoAvailable = LinphoneManager.Instance.IsVideoAvailable;
                buttons.video.IsEnabled = isVideoAvailable;
                buttons_landscape.video.IsEnabled = isVideoAvailable;
                buttons.videoImg.Opacity = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons.camera.IsEnabled = isVideoAvailable;
                buttons_landscape.camera.IsEnabled = isVideoAvailable;
                buttons.cameraImg.Opacity = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;

                bool isVideoEnabled = call.GetCurrentParamsCopy().VideoEnabled;
                buttons.video.IsChecked = isVideoEnabled;
                buttons_landscape.video.IsChecked = isVideoEnabled;
            }
            else if (state == LinphoneCallState.PausedByRemote)
            {
                buttons.pause.IsEnabled = false;
                buttons.microphone.IsEnabled = false;
                buttons.video.IsEnabled = false;
                buttons.camera.IsEnabled = false;
                buttons.pauseImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons.microImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons.videoImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons.cameraImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.pause.IsEnabled = false;
                buttons_landscape.microphone.IsEnabled = false;
                buttons_landscape.video.IsEnabled = false;
                buttons_landscape.camera.IsEnabled = false;
                buttons_landscape.pauseImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.microImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity = BUTTON_DISABLED_OPACITY;
            }
            else if (state == LinphoneCallState.Paused)
            {
                buttons.microphone.IsEnabled = false;
                buttons.video.IsEnabled = false;
                buttons.camera.IsEnabled = false;
                buttons.microImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons.videoImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons.cameraImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.microphone.IsEnabled = false;
                buttons_landscape.video.IsEnabled = false;
                buttons_landscape.camera.IsEnabled = false;
                buttons_landscape.microImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity = BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity = BUTTON_DISABLED_OPACITY;
            }
            else if (state == LinphoneCallState.Error || state == LinphoneCallState.CallEnd)
            {
                oneSecondTimer.Stop();
            }

            AudioEndpointChanged(null, null);
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="call"></param>
        /// <param name="state"></param>
        public void CallStateChanged(LinphoneCall call, LinphoneCallState state)
        {
            Logger.Dbg("[InCall] Call state changed: " + state.ToString());
            if (state == LinphoneCallState.StreamsRunning || state == LinphoneCallState.Connected)
            {
                buttons.pause.IsEnabled                = true;
                buttons.microphone.IsEnabled           = true;
                buttons_landscape.pause.IsEnabled      = true;
                buttons_landscape.microphone.IsEnabled = true;
                buttons.pauseImg.Opacity               = BUTTON_ENABLED_OPACITY;
                buttons.microImg.Opacity               = BUTTON_ENABLED_OPACITY;
                buttons_landscape.pauseImg.Opacity     = BUTTON_ENABLED_OPACITY;
                buttons_landscape.microImg.Opacity     = BUTTON_ENABLED_OPACITY;

                bool isVideoAvailable = LinphoneManager.Instance.IsVideoAvailable;
                buttons.video.IsEnabled             = isVideoAvailable;
                buttons_landscape.video.IsEnabled   = isVideoAvailable;
                buttons.videoImg.Opacity            = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity  = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons.camera.IsEnabled            = isVideoAvailable;
                buttons_landscape.camera.IsEnabled  = isVideoAvailable;
                buttons.cameraImg.Opacity           = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity = isVideoAvailable ? BUTTON_ENABLED_OPACITY : BUTTON_DISABLED_OPACITY;

                bool isVideoEnabled = call.GetCurrentParamsCopy().VideoEnabled;
                buttons.video.IsChecked           = isVideoEnabled;
                buttons_landscape.video.IsChecked = isVideoEnabled;
            }
            else if (state == LinphoneCallState.PausedByRemote)
            {
                buttons.pause.IsEnabled                = false;
                buttons.microphone.IsEnabled           = false;
                buttons.video.IsEnabled                = false;
                buttons.camera.IsEnabled               = false;
                buttons.pauseImg.Opacity               = BUTTON_DISABLED_OPACITY;
                buttons.microImg.Opacity               = BUTTON_DISABLED_OPACITY;
                buttons.videoImg.Opacity               = BUTTON_DISABLED_OPACITY;
                buttons.cameraImg.Opacity              = BUTTON_DISABLED_OPACITY;
                buttons_landscape.pause.IsEnabled      = false;
                buttons_landscape.microphone.IsEnabled = false;
                buttons_landscape.video.IsEnabled      = false;
                buttons_landscape.camera.IsEnabled     = false;
                buttons_landscape.pauseImg.Opacity     = BUTTON_DISABLED_OPACITY;
                buttons_landscape.microImg.Opacity     = BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity     = BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity    = BUTTON_DISABLED_OPACITY;
            }
            else if (state == LinphoneCallState.Paused)
            {
                buttons.microphone.IsEnabled           = false;
                buttons.video.IsEnabled                = false;
                buttons.camera.IsEnabled               = false;
                buttons.microImg.Opacity               = BUTTON_DISABLED_OPACITY;
                buttons.videoImg.Opacity               = BUTTON_DISABLED_OPACITY;
                buttons.cameraImg.Opacity              = BUTTON_DISABLED_OPACITY;
                buttons_landscape.microphone.IsEnabled = false;
                buttons_landscape.video.IsEnabled      = false;
                buttons_landscape.camera.IsEnabled     = false;
                buttons_landscape.microImg.Opacity     = BUTTON_DISABLED_OPACITY;
                buttons_landscape.videoImg.Opacity     = BUTTON_DISABLED_OPACITY;
                buttons_landscape.cameraImg.Opacity    = BUTTON_DISABLED_OPACITY;
            }
            else if (state == LinphoneCallState.Error || state == LinphoneCallState.CallEnd)
            {
                oneSecondTimer.Stop();
            }

            AudioEndpointChanged(null, null);
        }
Beispiel #12
0
        void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message)
        {
            if (linphoneCore == IntPtr.Zero || !running) return;
            #if (TRACE)
            Console.WriteLine("OnCallStateChanged: {0}", cstate);
            #endif

            Call.CallState newstate = Call.CallState.None;
            Call.CallType newtype = Call.CallType.None;
            string from = "";
            string to = "";
            IntPtr addressStringPtr;

            // detecting direction, state and source-destination data by state
            switch (cstate) {
                case LinphoneCallState.LinphoneCallIncomingReceived:
                case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                    newstate = Call.CallState.Loading;
                    newtype = Call.CallType.Incoming;
                    addressStringPtr = linphone_call_get_remote_address_as_string(call);
                    if (addressStringPtr != IntPtr.Zero) from = Marshal.PtrToStringAnsi(addressStringPtr);
                    to = identity;
                    break;

                case LinphoneCallState.LinphoneCallConnected:
                case LinphoneCallState.LinphoneCallStreamsRunning:
                case LinphoneCallState.LinphoneCallPausedByRemote:
                case LinphoneCallState.LinphoneCallUpdatedByRemote:
                    newstate = Call.CallState.Active;
                    break;

                case LinphoneCallState.LinphoneCallOutgoingInit:
                case LinphoneCallState.LinphoneCallOutgoingProgress:
                case LinphoneCallState.LinphoneCallOutgoingRinging:
                case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                    newstate = Call.CallState.Loading;
                    newtype = Call.CallType.Outcoming;
                    addressStringPtr = linphone_call_get_remote_address_as_string(call);
                    if (addressStringPtr != IntPtr.Zero) to = Marshal.PtrToStringAnsi(addressStringPtr);
                    from = this.identity;
                    break;

                case LinphoneCallState.LinphoneCallError:
                    newstate = Call.CallState.Error;
                    break;

                case LinphoneCallState.LinphoneCallReleased:
                case LinphoneCallState.LinphoneCallEnd:
                    newstate = Call.CallState.Completed;
                    if (linphone_call_params_get_record_file (callsDefaultParams) != IntPtr.Zero)
                        linphone_call_stop_recording (call);
                    break;

                default:
                    break;
            }

            LinphoneCall existCall = FindCall (call);

            if (existCall == null) {
                existCall = new LinphoneCall ();
                existCall.SetCallState (newstate);
                existCall.SetCallType (newtype);
                existCall.SetFrom (from);
                existCall.SetTo (to);
                existCall.LinphoneCallPtr = call;

                calls.Add (existCall);

                if ((CallStateChangedEvent != null))
                    CallStateChangedEvent (existCall);
            } else {
                if (existCall.GetState () != newstate) {
                    existCall.SetCallState (newstate);
                    CallStateChangedEvent (existCall);
                }
            }
        }
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void CallState(LinphoneCall call, LinphoneCallState state, string message)
        {
            if (BaseModel.UIDispatcher == null) return;
            if (state == LinphoneCallState.OutgoingProgress)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Outgoing progress\r\n");
                    LookupForContact(call);

                    if (CallListener != null && LinphoneCore.CallsNb > 0)
                    {
                        string sipAddress = call.RemoteAddress.AsStringUriOnly();
                        CallListener.NewCallStarted(sipAddress);
                    }
                });
            }
            else if (state == LinphoneCallState.IncomingReceived)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Incoming received\r\n"); 
                    if (false) //TODO: Find a proper way to let the user choose between the two.
                    {
                        BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/IncomingCall.xaml?sip=" + Utils.ReplacePlusInUri(call.RemoteAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute));
                        //Remove the current page from the back stack to avoid duplicating him after
                        BaseModel.CurrentPage.NavigationService.RemoveBackEntry();
                    }

                    LookupForContact(call);
                });
            }
            else if (state == LinphoneCallState.Connected)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Connected\r\n");
                    if (CallListener != null)
                    {
                        string sipAddress = call.RemoteAddress.AsStringUriOnly();
                        CallListener.NewCallStarted(sipAddress);
                    }
                });
            }
            else if (state == LinphoneCallState.CallEnd || state == LinphoneCallState.Error)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg(String.Format("[LinphoneManager] Call ended: {0}\r\n", message));
                    if (CallListener != null)
                        CallListener.CallEnded(call);
                    string text;
                    switch (call.Reason)
                    {
                        case Reason.LinphoneReasonNone:
                        case Reason.LinphoneReasonNotAnswered:
                            break;
                        case Reason.LinphoneReasonDeclined:
                            if (call.Direction == CallDirection.Outgoing)
                            {
                                text = ResourceManager.GetString("CallErrorDeclined", CultureInfo.CurrentCulture);
                                ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                            }
                            break;
                        case Reason.LinphoneReasonNotFound:
                            text = ResourceManager.GetString("CallErrorNotFound", CultureInfo.CurrentCulture);
                            ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                            break;
                        case Reason.LinphoneReasonBusy:
                            text = ResourceManager.GetString("CallErrorBusy", CultureInfo.CurrentCulture);
                            ShowCallError(text.Replace("#address#", call.RemoteAddress.UserName));
                            break;
                        case Reason.LinphoneReasonNotAcceptable:
                            ShowCallError(ResourceManager.GetString("CallErrorNotAcceptable", CultureInfo.CurrentCulture));
                            break;
                        case Reason.LinphoneReasonIOError:
                            ShowCallError(ResourceManager.GetString("CallErrorIOError", CultureInfo.CurrentCulture));
                            break;
                        default:
                            ShowCallError(ResourceManager.GetString("CallErrorUnknown", CultureInfo.CurrentCulture));
                            break;
                    }
                });
            }
            else if (state == LinphoneCallState.Paused || state == LinphoneCallState.PausedByRemote)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call paused\r\n");
                    bool pausedByRemote = state == LinphoneCallState.PausedByRemote;
                    if (CallListener != null)
                        CallListener.PauseStateChanged(call, !pausedByRemote, pausedByRemote);
                });
            }
            else if (state == LinphoneCallState.StreamsRunning)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call running\r\n");
                    if (CallListener != null)
                        CallListener.PauseStateChanged(call, false, false);
                });
            }
            else if (state == LinphoneCallState.Released)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Logger.Msg("[LinphoneManager] Call released\r\n");
                });
            }
            else if (state == LinphoneCallState.UpdatedByRemote)
            {
                BaseModel.UIDispatcher.BeginInvoke(() =>
                {
                    Boolean videoAdded = false;
                    VideoPolicy policy = LinphoneManager.Instance.LinphoneCore.VideoPolicy;
                    LinphoneCallParams remoteParams = call.RemoteParams;
                    LinphoneCallParams localParams = call.GetCurrentParamsCopy();
                    if (remoteParams.VideoEnabled && !localParams.VideoEnabled && !LinphoneManager.Instance.LinphoneCore.InConference)
                    {
                        if (policy.AutomaticallyAccept)
                        {
                            localParams.VideoEnabled = true;
                            LinphoneManager.Instance.LinphoneCore.AcceptCallUpdate(call, localParams);
                        }
                        else
                        {
                            videoAdded = true;
                        }
                    }
                    else
                    {
                        LinphoneManager.Instance.LinphoneCore.AcceptCallUpdate(call, localParams);
                    }

                    if (CallListener != null)
                        CallListener.CallUpdatedByRemote(call, videoAdded);
                });
            }

            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                if (CallStateChanged != null)
                {
                    CallStateChanged(call, state);
                }
            });
        }
Beispiel #14
0
 public void CallState(LinphoneCall call, LinphoneCallState state, string message)
 {
     WriteLog("CallState: {0} | {1}", state, message);
     switch (state)
     {
         case LinphoneCallState.IncomingReceived:
             this.UIThreadInvoke(() => AcceptCall(call, message));
             break;
         case LinphoneCallState.OutgoingRinging:
             this.UIThreadInvoke(() => WriteLog("Ringing"));
             break;
         case LinphoneCallState.Connected:                    
             this.UIThreadInvoke(() => WriteLog("Talking"));
             this.UIThreadInvoke(() => this.btnCall.Text = "Hangup");
             break;
         case LinphoneCallState.CallEnd:
             this.UIThreadInvoke(() => WriteLog("Call ended"));
             this.UIThreadInvoke(() => this.btnCall.Text = "Call" );
             break;
         default:
             break;
     }
 }
Beispiel #15
0
        void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message)
        {
            if (linphoneCore == IntPtr.Zero || !running)
            {
                return;
            }
            #if (TRACE)
            Console.WriteLine("OnCallStateChanged: {0}", cstate);
            #endif

            Call.CallState newstate = Call.CallState.None;
            Call.CallType  newtype  = Call.CallType.None;
            string         from     = "";
            string         to       = "";
            IntPtr         addressStringPtr;

            // detecting direction, state and source-destination data by state
            switch (cstate)
            {
            case LinphoneCallState.LinphoneCallIncomingReceived:
            case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                newstate         = Call.CallState.Loading;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                to = identity;
                break;

            case LinphoneCallState.LinphoneCallConnected:
            case LinphoneCallState.LinphoneCallStreamsRunning:
            case LinphoneCallState.LinphoneCallPausedByRemote:
            case LinphoneCallState.LinphoneCallUpdatedByRemote:
                newstate = Call.CallState.Active;
                break;

            case LinphoneCallState.LinphoneCallOutgoingInit:
            case LinphoneCallState.LinphoneCallOutgoingProgress:
            case LinphoneCallState.LinphoneCallOutgoingRinging:
            case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                newstate         = Call.CallState.Loading;
                newtype          = Call.CallType.Outcoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    to = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                from = this.identity;
                break;

            case LinphoneCallState.LinphoneCallError:
                newstate = Call.CallState.Error;
                break;

            case LinphoneCallState.LinphoneCallReleased:
            case LinphoneCallState.LinphoneCallEnd:
                newstate = Call.CallState.Completed;
                if (linphone_call_params_get_record_file(callsDefaultParams) != IntPtr.Zero)
                {
                    linphone_call_stop_recording(call);
                }
                break;

            default:
                break;
            }

            LinphoneCall existCall = FindCall(call);

            if (existCall == null)
            {
                existCall = new LinphoneCall();
                existCall.SetCallState(newstate);
                existCall.SetCallType(newtype);
                existCall.SetFrom(from);
                existCall.SetTo(to);
                existCall.LinphoneCallPtr = call;

                calls.Add(existCall);

                if ((CallStateChangedEvent != null))
                {
                    CallStateChangedEvent(existCall);
                }
            }
            else
            {
                if (existCall.GetState() != newstate)
                {
                    existCall.SetCallState(newstate);
                    CallStateChangedEvent(existCall);
                }
            }
        }
		private void OnCallStateChanged(IntPtr lc, IntPtr callPtr, LinphoneCallState cstate, string message)
		{
			if (linphoneCore == IntPtr.Zero) return;

			LOG.Info(string.Format( "OnCallStateChanged: State - {0}, CallPtr - {1}, Message: {2}", cstate, callPtr, message));

			var newstate = VATRPCallState.None;
			var direction = LinphoneCallDir.LinphoneCallIncoming;
			string remoteParty = "";
			IntPtr addressStringPtr;
		    bool removeCall = false;
			// detecting direction, state and source-destination data by state
			switch (cstate)
			{
				case LinphoneCallState.LinphoneCallIncomingReceived:
				case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
					newstate = cstate == LinphoneCallState.LinphoneCallIncomingReceived
						? VATRPCallState.InProgress
						: VATRPCallState.EarlyMedia;
					addressStringPtr = LinphoneAPI.linphone_call_get_remote_address_as_string(callPtr);
			        if (addressStringPtr != IntPtr.Zero)
			        {
			            identity = Marshal.PtrToStringAnsi(addressStringPtr);
                        LinphoneAPI.ortp_free(addressStringPtr);
			        }
					remoteParty = identity;
					break;

                case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
				case LinphoneCallState.LinphoneCallConnected:
					newstate = VATRPCallState.Connected;
					break;
				case LinphoneCallState.LinphoneCallStreamsRunning:
                    newstate = VATRPCallState.StreamsRunning;
					break;
				case LinphoneCallState.LinphoneCallPausedByRemote:
                    newstate = VATRPCallState.RemotePaused;
			        break;
				case LinphoneCallState.LinphoneCallPausing:
                    newstate = VATRPCallState.LocalPausing;
					break;
                case LinphoneCallState.LinphoneCallPaused:
                    newstate = VATRPCallState.LocalPaused;
                    break;
                case LinphoneCallState.LinphoneCallResuming:
                    newstate = VATRPCallState.LocalResuming;
			        break;
				case LinphoneCallState.LinphoneCallOutgoingInit:
				case LinphoneCallState.LinphoneCallOutgoingProgress:
				case LinphoneCallState.LinphoneCallOutgoingRinging:
                    newstate = cstate != LinphoneCallState.LinphoneCallOutgoingRinging
						? VATRPCallState.Trying
						: VATRPCallState.Ringing;
					direction = LinphoneCallDir.LinphoneCallOutgoing;
					addressStringPtr = LinphoneAPI.linphone_call_get_remote_address_as_string(callPtr);
			        if (addressStringPtr != IntPtr.Zero)
			        {
			            remoteParty = Marshal.PtrToStringAnsi(addressStringPtr);
                        LinphoneAPI.ortp_free(addressStringPtr);
			        }
					break;

				case LinphoneCallState.LinphoneCallError:
                    string linphoneLibraryVersion = VATRP.LinphoneWrapper.LinphoneAPI.linphone_core_get_version_asString();
                    LOG.Info("OnCallStateChanged: CallState=LinphoneCallError .LinphoneLib Version: " + linphoneLibraryVersion);
					newstate = VATRPCallState.Error;
			        removeCall = true;
					break;

				case LinphoneCallState.LinphoneCallEnd:
					newstate = VATRPCallState.Closed;
                    removeCall = true;
					break;
				case LinphoneCallState.LinphoneCallReleased:
			        if ((_declinedCallsList != null) && _declinedCallsList.Contains(callPtr))
			        {
                        LOG.Info("   trying to remove callPtr from declinedCallList");
			            _declinedCallsList.Remove(callPtr);
                    }
                    LOG.Info("   calling linphone_call_unref");
                    try
                    {
                        LinphoneAPI.linphone_call_unref(callPtr);
                        LOG.Info("   passed unref");
                    }
                    catch (Exception ex)
                    {
                        LOG.Error("LinphoneService.OnCallStateChanged: Exception occured while calling linphone_call_unref. Details: " + ex.Message);
                    }
			        return;
			}

		    lock (callLock)
		    {
		        VATRPCall call = FindCall(callPtr);

		        if (call == null)
		        {
		            if (_declinedCallsList.Contains(callPtr))
		                return;

		            if (GetActiveCallsCount > 1)
		            {
                        callPtr = LinphoneAPI.linphone_call_ref(callPtr);
                        var cmd = new DeclineCallCommand(callPtr, LinphoneReason.LinphoneReasonBusy);
		                commandQueue.Enqueue(cmd);
                        _declinedCallsList.Add(callPtr);
		                return;
		            }

		            if (!removeCall)
		            {
		                LOG.Info("Call not found. Adding new call into list. ID - " + callPtr + " Calls count: " +
		                         callsList.Count);
                        callPtr = LinphoneAPI.linphone_call_ref(callPtr);
		                call = new VATRPCall(callPtr) {CallState = newstate, CallDirection = direction};
		                CallParams from = direction == LinphoneCallDir.LinphoneCallIncoming ? call.From : call.To;
		                CallParams to = direction == LinphoneCallDir.LinphoneCallIncoming ? call.To : call.From;

		                if (
		                    !VATRPCall.ParseSipAddressEx(remoteParty, out from.DisplayName, out from.Username,
		                        out from.HostAddress,
		                        out from.HostPort))
		                    from.Username = "******";

		                if (
		                    !VATRPCall.ParseSipAddressEx(remoteParty, out to.DisplayName, out to.Username, out to.HostAddress,
		                        out to.HostPort))
		                    to.Username = "******";

		                IntPtr chatPtr = LinphoneAPI.linphone_call_get_chat_room(callPtr);

		                if (chatPtr != IntPtr.Zero)
		                {
		                    VATRPContact contact;
		                    var contactAddress = string.Empty;
		                    if (direction == LinphoneCallDir.LinphoneCallIncoming)
		                    {
		                        contactAddress = string.Format("{0}@{1}", from.Username, from.HostAddress);
		                        contact = new VATRPContact(new ContactID(contactAddress, chatPtr))
		                        {
		                            DisplayName = from.DisplayName,
		                            Fullname = from.Username,
		                            SipUsername = from.Username
		                        };
		                    }
		                    else
		                    {
		                        contactAddress = string.Format("{0}@{1}", to.Username, to.HostAddress);
		                        contact = new VATRPContact(new ContactID(contactAddress, chatPtr))
		                        {
		                            DisplayName = to.DisplayName,
		                            Fullname = to.Username,
		                            SipUsername = to.Username
		                        };
		                    }
		                    contact.RegistrationName = contactAddress;
                            call.ChatRoom = manager.ChatService.InsertRttChat(contact, chatPtr, callPtr);
		                    var loggedContact = manager.ContactService.FindLoggedInContact();
		                    if (loggedContact != null)
		                        call.ChatRoom.AddContact(loggedContact);
		                }

		                callsList.Add(call);
		            }
		        }

		        if (call != null)
		        {
		            call.LinphoneMessage = message;
		            call.CallState = newstate;

                    if (call.CallState == VATRPCallState.Error || call.CallState == VATRPCallState.Closed)
		            {
		                IntPtr errorReason = LinphoneAPI.linphone_call_get_error_info(callPtr);
		                if (errorReason != IntPtr.Zero)
		                {
                            call.SipErrorCode = LinphoneAPI.linphone_error_info_get_protocol_code(errorReason);
		                }
		            }
                    if (CallStateChangedEvent != null)
                        CallStateChangedEvent(call);
		            if (removeCall)
		            {
		                callsList.Remove(call);
		                LOG.Info(string.Format("Call removed from list. Call - {0}. Total calls in list: {1}", callPtr,
		                    callsList.Count));
		            }
		        }
		    }
		}
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void CallState(LinphoneCall call, LinphoneCallState state, string message)
 {
 }