示例#1
0
        /// <summary>
        /// Method called when the page is displayed.
        /// Searches for a matching contact using the current call address or number and display information if found.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs nee)
        {
            base.OnNavigatedTo(nee);
            this.ViewModel.MuteListener  = this;
            this.ViewModel.PauseListener = this;
            this.ViewModel.CallUpdatedByRemoteListener = this;
            LinphoneManager.Instance.CallStateChanged += CallStateChanged;
            AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;

            if (NavigationContext.QueryString.ContainsKey("sip"))
            {
                String          calledNumber = NavigationContext.QueryString["sip"];
                LinphoneAddress address      = LinphoneManager.Instance.LinphoneCore.InterpretURL(calledNumber);
                calledNumber = String.Format("{0}@{1}", address.UserName, address.Domain);
                // While we dunno if the number matches a contact one, we consider it won't and we display the phone number as username
                Contact.Text = calledNumber;

                if (calledNumber != null && calledNumber.Length > 0)
                {
                    ContactManager cm = ContactManager.Instance;
                    cm.ContactFound += cm_ContactFound;
                    cm.FindContact(calledNumber);
                }
            }

            ApplicationSettingsManager settings = new ApplicationSettingsManager();

            settings.Load();

            // Callback CallStateChanged set too late when call is incoming, so trigger it manually
            if (LinphoneManager.Instance.LinphoneCore.CallsNb > 0)
            {
                LinphoneCall call = (LinphoneCall)LinphoneManager.Instance.LinphoneCore.Calls[0];
                if (call.State == LinphoneCallState.StreamsRunning)
                {
                    CallStateChanged(call, LinphoneCallState.StreamsRunning);
                    if (settings.VideoActiveWhenGoingToBackground)
                    {
                        LinphoneManager.Instance.LinphoneCore.VideoPolicy.AutomaticallyAccept = settings.VideoAutoAcceptWhenGoingToBackground;
                        LinphoneCallParams callParams = call.GetCurrentParamsCopy();
                        callParams.VideoEnabled = true;
                        LinphoneManager.Instance.LinphoneCore.UpdateCall(call, callParams);
                    }
                }
                else if (call.State == LinphoneCallState.UpdatedByRemote)
                {
                    // The call was updated by the remote party while we were in background
                    LinphoneManager.Instance.CallState(call, call.State, "call updated while in background");
                }
            }

            settings.VideoActiveWhenGoingToBackground = false;
            settings.Save();

            oneSecondTimer          = new DispatcherTimer();
            oneSecondTimer.Interval = TimeSpan.FromSeconds(1);
            oneSecondTimer.Tick    += timerTick;
            oneSecondTimer.Start();
        }
示例#2
0
 /// <summary>
 /// Enables disables video.
 /// </summary>
 /// <param name="enable">Wether to enable or disable video</param>
 /// <returns>true if the operation has been successful, false otherwise</returns>
 public bool EnableVideo(bool enable)
 {
     if (LinphoneCore.InCall)
     {
         LinphoneCall       call       = LinphoneCore.CurrentCall;
         LinphoneCallParams parameters = call.GetCurrentParamsCopy();
         if (enable != parameters.VideoEnabled)
         {
             parameters.VideoEnabled = enable;
             if (enable)
             {
                 // TODO: Handle bandwidth limitation
             }
             LinphoneCore.UpdateCall(call, parameters);
             return(true);
         }
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Method called when the page is leaved.
        /// </summary>
        protected override void OnNavigatedFrom(NavigationEventArgs nee)
        {
            if (((InCallModel)ViewModel).IsVideoActive)
            {
                LinphoneCall call = null;
                try
                {
                    call = (LinphoneCall)LinphoneManager.Instance.LinphoneCore.Calls[0];
                }
                catch (System.ArgumentOutOfRangeException) { }
                if (call != null)
                {
                    ApplicationSettingsManager settings = new ApplicationSettingsManager();
                    settings.Load();
                    settings.VideoActiveWhenGoingToBackground     = true;
                    settings.VideoAutoAcceptWhenGoingToBackground = LinphoneManager.Instance.LinphoneCore.VideoPolicy.AutomaticallyAccept;
                    settings.Save();
                    LinphoneManager.Instance.LinphoneCore.VideoPolicy.AutomaticallyAccept = false;
                    LinphoneCallParams callParams = call.GetCurrentParamsCopy();
                    callParams.VideoEnabled = false;
                    LinphoneManager.Instance.LinphoneCore.UpdateCall(call, callParams);
                }
            }

            oneSecondTimer.Stop();
            if (fadeTimer != null)
            {
                fadeTimer.Dispose();
                fadeTimer = null;
            }

            base.OnNavigatedFrom(nee);
            this.ViewModel.MuteListener  = null;
            this.ViewModel.PauseListener = null;
            LinphoneManager.Instance.CallStateChanged -= CallStateChanged;
            AudioRoutingManager.GetDefault().AudioEndpointChanged -= AudioEndpointChanged;
        }
示例#4
0
 /// <summary>
 /// Called when the call is updated by the remote party.
 /// </summary>
 /// <param name="call">The call that has been updated</param>
 /// <param name="isVideoAdded">A boolean telling whether the remote party added video</param>
 public void CallUpdatedByRemote(LinphoneCall call, bool isVideoAdded)
 {
     if (isVideoAdded)
     {
         Guide.BeginShowMessageBox(AppResources.VideoActivationPopupCaption,
                                   AppResources.VideoActivationPopupContent,
                                   new List <String> {
             "Accept", "Dismiss"
         },
                                   0,
                                   MessageBoxIcon.Alert,
                                   asyncResult =>
         {
             int?res = Guide.EndShowMessageBox(asyncResult);
             LinphoneCallParams parameters = call.GetCurrentParamsCopy();
             if (res == 0)
             {
                 parameters.VideoEnabled = true;
             }
             LinphoneManager.Instance.LinphoneCore.AcceptCallUpdate(call, parameters);
         },
                                   null);
     }
 }
示例#5
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);
                }
            });
        }
示例#6
0
        private void timerTick(Object sender, EventArgs args)
        {
            LinphoneCall call = ((InCallModel)ViewModel).GetCurrentCall();

            if (call == null)
            {
                return;
            }

            startTime = (DateTimeOffset)call.CallStartTimeFromContext;
            DateTimeOffset now     = DateTimeOffset.Now;
            TimeSpan       elapsed = now.Subtract(startTime);
            var            hh      = elapsed.Hours;
            var            ss      = elapsed.Seconds;
            var            mm      = elapsed.Minutes;

            Status.Text = hh.ToString("00") + ":" + mm.ToString("00") + ":" + ss.ToString("00");

            string audioPayloadType       = "";
            string audioDownloadBandwidth = "";
            string audioUploadBandwidth   = "";
            string videoPayloadType       = "";
            string videoDownloadBandwidth = "";
            string videoUploadBandwidth   = "";

            LinphoneCallParams param = call.GetCurrentParamsCopy();

            ((InCallModel)ViewModel).MediaEncryption = param.MediaEncryption.ToString();

            LinphoneCallStats audioStats = null;

            try
            {
                audioStats = call.AudioStats;
            }
            catch { }

            if (audioStats != null)
            {
                audioDownloadBandwidth       = String.Format("{0:0.00}", audioStats.DownloadBandwidth);
                audioUploadBandwidth         = String.Format("{0:0.00}", audioStats.UploadBandwidth);
                ((InCallModel)ViewModel).ICE = audioStats.IceState.ToString();
            }

            PayloadType audiopt = param.UsedAudioCodec;

            if (audiopt != null)
            {
                audioPayloadType = audiopt.MimeType + "/" + audiopt.ClockRate;
            }

            if (param.VideoEnabled)
            {
                LinphoneCallStats videoStats = call.VideoStats;
                if (videoStats != null)
                {
                    videoDownloadBandwidth = String.Format("{0:0.00}", videoStats.DownloadBandwidth);
                    videoUploadBandwidth   = String.Format("{0:0.00}", videoStats.UploadBandwidth);
                }

                PayloadType videopt = param.UsedVideoCodec;
                if (videopt != null)
                {
                    videoPayloadType = videopt.MimeType;
                }
                Windows.Foundation.Size receivedVideoSize = param.ReceivedVideoSize;
                String NewReceivedVideoSize = String.Format("{0}x{1}", receivedVideoSize.Width, receivedVideoSize.Height);
                String OldReceivedVideoSize = ((InCallModel)ViewModel).ReceivedVideoSize;
                if (OldReceivedVideoSize != NewReceivedVideoSize)
                {
                    ((InCallModel)ViewModel).ReceivedVideoSize = String.Format("{0}x{1}", receivedVideoSize.Width, receivedVideoSize.Height);
                    ((InCallModel)ViewModel).IsVideoActive     = false;
                    if (NewReceivedVideoSize != "0x0")
                    {
                        ((InCallModel)ViewModel).IsVideoActive = true;
                    }
                }
                Windows.Foundation.Size sentVideoSize = param.SentVideoSize;
                ((InCallModel)ViewModel).SentVideoSize        = String.Format("{0}x{1}", sentVideoSize.Width, sentVideoSize.Height);
                ((InCallModel)ViewModel).VideoStatsVisibility = Visibility.Visible;
            }
            else
            {
                ((InCallModel)ViewModel).VideoStatsVisibility = Visibility.Collapsed;
            }

            string downloadBandwidth = audioDownloadBandwidth;

            if ((downloadBandwidth != "") && (videoDownloadBandwidth != ""))
            {
                downloadBandwidth += " - ";
            }
            if (videoDownloadBandwidth != "")
            {
                downloadBandwidth += videoDownloadBandwidth;
            }
            ((InCallModel)ViewModel).DownBandwidth = String.Format("{0} kb/s", downloadBandwidth);
            string uploadBandwidth = audioUploadBandwidth;

            if ((uploadBandwidth != "") && (videoUploadBandwidth != ""))
            {
                uploadBandwidth += " - ";
            }
            if (videoUploadBandwidth != "")
            {
                uploadBandwidth += videoUploadBandwidth;
            }
            ((InCallModel)ViewModel).UpBandwidth = String.Format("{0} kb/s", uploadBandwidth);
            string payloadType = audioPayloadType;

            if ((payloadType != "") && (videoPayloadType != ""))
            {
                payloadType += " - ";
            }
            if (videoPayloadType != "")
            {
                payloadType += videoPayloadType;
            }
            ((InCallModel)ViewModel).PayloadType = payloadType;
        }