/// <returns>A SolidColorBrush (PhoneAccentBrush or PhoneSubtleBrush).</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string          sipAddress = (string)value;
            LinphoneAddress addr       = LinphoneManager.Instance.LinphoneCore.InterpretURL(sipAddress);

            return(addr.UserName);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the calls' history.
        /// </summary>
        /// <returns>A list of CallLogs, each one representing a type of calls (All, Missed, ...)</returns>
        public List <CallLog> GetCallsHistory()
        {
            _history = new List <CallLog>();

            if (LinphoneCore.CallLogs != null)
            {
                foreach (LinphoneCallLog log in LinphoneCore.CallLogs)
                {
                    string from = log.From.DisplayName;
                    if (from.Length == 0)
                    {
                        LinphoneAddress fromAddress = log.From;
                        from = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain);
                    }

                    string to = log.To.DisplayName;
                    if (to.Length == 0)
                    {
                        LinphoneAddress toAddress = log.To;
                        to = String.Format("{0}@{1}", toAddress.UserName, toAddress.Domain);
                    }

                    bool    isMissed  = log.Status == LinphoneCallStatus.Missed;
                    long    startDate = log.StartDate;
                    CallLog callLog   = new CallLog(log, from, to, log.Direction == CallDirection.Incoming, isMissed, startDate);
                    _history.Add(callLog);
                }
            }

            return(_history);
        }
Esempio n. 3
0
        private void GetMessagesAndDisplayConversationsList()
        {
            _conversations       = new ObservableCollection <Conversation>();
            _sortedConversations = new ObservableCollection <Conversation>();
            foreach (LinphoneChatRoom conversation in LinphoneManager.Instance.LinphoneCore.ChatRooms)
            {
                if (conversation.HistorySize > 0)
                {
                    LinphoneAddress peerAddress = conversation.PeerAddress;
                    string          address     = String.Format("{0}@{1}", peerAddress.UserName, peerAddress.Domain);
                    string          name        = peerAddress.DisplayName;
                    if (name == null || name.Length <= 0)
                    {
                        name = peerAddress.UserName;
                    }
                    _conversations.Add(new Conversation(address, name, conversation.History));
                    ContactManager.Instance.FindContact(address);
                }
            }

            _sortedConversations = new ObservableCollection <Conversation>();
            foreach (var i in _conversations.OrderByDescending(g => g.Messages.Last().Time).ToList())
            {
                _sortedConversations.Add(i);
            }
            ((ChatsModel)ViewModel).Conversations = _sortedConversations;
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        /// <summary>
        /// Searches if there is a contact for whom the phone number of the email address is stored.
        /// </summary>
        /// <param name="numberOrAddress"></param>
        public void FindContact(String numberOrAddress)
        {
            LinphoneAddress address = LinphoneManager.Instance.LinphoneCore.InterpretURL(numberOrAddress);
            string          addressWithoutScheme = String.Format("{0}@{1}", address.UserName, address.Domain);
            string          username             = address.UserName;

            if (IsPhoneNumber(username))
            {
                FindContactByNumber(username, addressWithoutScheme);
            }
            FindContactByEmail(addressWithoutScheme, addressWithoutScheme);
        }
Esempio n. 6
0
        private void CreateChatRoom(LinphoneAddress sipAddress)
        {
            this.sipAddress = sipAddress;
            ContactManager.Instance.FindContact(String.Format("{0}@{1}", sipAddress.UserName, sipAddress.Domain));
            ContactName.Text       = sipAddress.UserName;
            ContactName.Visibility = Visibility.Visible;
            NewChat.Visibility     = Visibility.Collapsed;

            try
            {
                chatRoom = LinphoneManager.Instance.LinphoneCore.GetChatRoom(sipAddress);
            }
            catch
            {
                Logger.Err("Can't create chat room for sip address {0}", sipAddress);
                throw;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void ComposingReceived(LinphoneChatRoom room)
        {
            if (BaseModel.UIDispatcher == null)
            {
                return;
            }
            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                if (ComposingListener != null && room != null)
                {
                    string currentListenerSipAddress = ComposingListener.GetSipAddressAssociatedWithDisplayConversation();
                    LinphoneAddress peerAddress      = room.PeerAddress;
                    string roomComposingSipAddress   = String.Format("{0}@{1}", peerAddress.UserName, peerAddress.Domain);

                    if (currentListenerSipAddress != null && roomComposingSipAddress.Equals(currentListenerSipAddress))
                    {
                        ComposingListener.ComposeReceived();
                    }
                }
            });
        }
Esempio n. 8
0
        private void LookupForContact(LinphoneCall call)
        {
            try
            {
                LinphoneAddress remoteAddress = call.RemoteAddress;
                if (remoteAddress.DisplayName.Length == 0)
                {
                    string sipAddress = String.Format("{0}@{1}", remoteAddress.UserName, remoteAddress.Domain);
                    Logger.Msg("[LinphoneManager] Display name null, looking for remote address in contact: " + sipAddress + "\r\n");

                    ContactManager.ContactFound += OnContactFound;
                    ContactManager.FindContact(sipAddress);
                }
                else
                {
                    Logger.Msg("[LinphoneManager] Display name found: " + call.RemoteAddress.DisplayName + "\r\n");
                }
            }
            catch
            {
                Logger.Warn("[LinphoneManager] Exception occured while looking for contact...\r\n");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Method called when the page is displayed.
        /// Check if the uri contains a sip address, if yes, it displays the matching chat history.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            LinphoneManager.Instance.MessageListener   = this;
            LinphoneManager.Instance.ComposingListener = this;

            ContactManager cm = ContactManager.Instance;

            cm.ContactFound += cm_ContactFound;

            MessageBox.TextChanged += MessageBox_TextChanged;

            NewChat.Visibility     = Visibility.Collapsed;
            ContactName.Visibility = Visibility.Visible;
            if (NavigationContext.QueryString.ContainsKey("sip"))
            {
                sipAddress = LinphoneManager.Instance.LinphoneCore.InterpretURL(NavigationContext.QueryString["sip"]);
                CreateChatRoom(sipAddress);
                UpdateComposingMessage();

                if (e.NavigationMode != NavigationMode.Back)
                {
                    chatRoom.MarkAsRead();
                    DisplayPastMessages(chatRoom.History);
                }
            }
            else if (e.NavigationMode != NavigationMode.Back || sipAddress == null)
            {
                ContactName.Visibility = Visibility.Collapsed;
                NewChat.Visibility     = Visibility.Visible;
                NewChatSipAddress.Focus();
            }
            RefreshSendMessageButtonEnabledState();

            scrollToBottom();
        }
Esempio n. 10
0
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void MessageReceived(LinphoneChatMessage message)
        {
            if (BaseModel.UIDispatcher == null)
            {
                return;
            }
            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                LinphoneAddress fromAddress = message.From;
                string sipAddress           = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain);
                Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.Text + "\r\n");

                //Vibrate
                ChatSettingsManager settings = new ChatSettingsManager();
                settings.Load();
                if ((bool)settings.VibrateOnIncomingMessage)
                {
                    VibrationDevice vibrator = VibrationDevice.GetDefault();
                    vibrator.Vibrate(TimeSpan.FromSeconds(1));
                }

                if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
                {
                    MessageListener.MessageReceived(message);
                }
                else
                {
                    DateTime date = new DateTime(message.Time * TimeSpan.TicksPerSecond, DateTimeKind.Utc).AddYears(1969).ToLocalTime();
                    DateTime now  = DateTime.Now;
                    string dateStr;
                    if (now.Year == date.Year && now.Month == date.Month && now.Day == date.Day)
                    {
                        dateStr = String.Format("{0:HH:mm}", date);
                    }
                    else if (now.Year == date.Year)
                    {
                        dateStr = String.Format("{0:ddd d MMM, HH:mm}", date);
                    }
                    else
                    {
                        dateStr = String.Format("{0:ddd d MMM yyyy, HH:mm}", date);
                    }

                    //TODO: Temp hack to remove
                    string url = message.ExternalBodyUrl;
                    url        = url.Replace("\"", "");

                    //Displays the message as a popup
                    if (MessageReceivedNotification != null)
                    {
                        MessageReceivedNotification.Dismiss();
                    }

                    MessageReceivedNotification = new CustomMessageBox()
                    {
                        Title              = dateStr,
                        Caption            = url.Length > 0 ? AppResources.ImageMessageReceived : AppResources.MessageReceived,
                        Message            = url.Length > 0 ? "" : message.Text,
                        LeftButtonContent  = AppResources.Close,
                        RightButtonContent = AppResources.Show
                    };

                    MessageReceivedNotification.Dismissed += (s, e) =>
                    {
                        switch (e.Result)
                        {
                        case CustomMessageBoxResult.RightButton:
                            BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/Chat.xaml?sip=" + Utils.ReplacePlusInUri(message.PeerAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute));
                            break;
                        }
                    };

                    MessageReceivedNotification.Show();
                }
            });
        }
Esempio n. 11
0
        private void CreateChatRoom(LinphoneAddress sipAddress)
        {
            this.sipAddress = sipAddress;
            ContactManager.Instance.FindContact(String.Format("{0}@{1}", sipAddress.UserName, sipAddress.Domain));
            ContactName.Text = sipAddress.UserName;
            ContactName.Visibility = Visibility.Visible;
            NewChat.Visibility = Visibility.Collapsed;

            try
            {
                chatRoom = LinphoneManager.Instance.LinphoneCore.GetChatRoom(sipAddress);
            }
            catch
            {
                Logger.Err("Can't create chat room for sip address {0}", sipAddress);
                throw;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Method called when the page is displayed.
        /// Check if the uri contains a sip address, if yes, it displays the matching chat history.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            LinphoneManager.Instance.MessageListener = this;
            LinphoneManager.Instance.ComposingListener = this;

            ContactManager cm = ContactManager.Instance;
            cm.ContactFound += cm_ContactFound;

            MessageBox.TextChanged += MessageBox_TextChanged;

            NewChat.Visibility = Visibility.Collapsed;
            ContactName.Visibility = Visibility.Visible; 
            if (NavigationContext.QueryString.ContainsKey("sip"))
            {
                sipAddress = LinphoneManager.Instance.LinphoneCore.InterpretURL(NavigationContext.QueryString["sip"]);
                CreateChatRoom(sipAddress);
                UpdateComposingMessage();

                if (e.NavigationMode != NavigationMode.Back)
                {
                    chatRoom.MarkAsRead();
                    DisplayPastMessages(chatRoom.History);
                }
            }
            else if (e.NavigationMode != NavigationMode.Back || sipAddress == null)
            {
                ContactName.Visibility = Visibility.Collapsed; 
                NewChat.Visibility = Visibility.Visible;
                NewChatSipAddress.Focus();
            }
            RefreshSendMessageButtonEnabledState();

            scrollToBottom();
        }