public IAsyncAction ServerRelayAsync(RelayMessage message) { return(Task.Run(async() => { await ClientConfirmationAsync(Confirmation.For(message)); if (message.Tag == RelayMessageTags.InstantMessage) { await SignaledInstantMessages.AddAsync(message); } var shownUserId = await _foregroundChannel.GetShownUserIdAsync(); if (message.Tag == RelayMessageTags.InstantMessage && !ReceivedPushNotifications.IsReceived(message.Id) && !(shownUserId != null && shownUserId.Equals(message.FromUserId)) && (DateTimeOffset.UtcNow.Subtract(message.SentDateTimeUtc).TotalMinutes < 10)) { ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload); } _foregroundChannel?.OnSignaledRelayMessagesUpdatedAsync(); // Handle call tags if (message.Tag == RelayMessageTags.Call) { await _callChannel.OnIncomingCallAsync(message); } else if (message.Tag == RelayMessageTags.CallAnswer) { await _callChannel.OnOutgoingCallAcceptedAsync(message); } else if (message.Tag == RelayMessageTags.CallReject) { await _callChannel.OnOutgoingCallRejectedAsync(message); } else if (message.Tag == RelayMessageTags.SdpOffer) { await _callChannel.OnSdpOfferAsync(message); } else if (message.Tag == RelayMessageTags.SdpAnswer) { await _callChannel.OnSdpAnswerAsync(message); } else if (message.Tag == RelayMessageTags.IceCandidate) { await _callChannel.OnIceCandidateAsync(message); } else if (message.Tag == RelayMessageTags.CallHangup) { await _callChannel.OnRemoteHangupAsync(message); } }).AsAsyncAction()); }
public async void Run(IBackgroundTaskInstance taskInstance) { using (new BackgroundTaskDeferralWrapper(taskInstance.GetDeferral())) { try { var rawNotification = (RawNotification)taskInstance.TriggerDetails; var rawContent = rawNotification.Content; var serializedParameter = rawContent.Substring(rawContent.IndexOf(" ", StringComparison.CurrentCultureIgnoreCase) + 1); var type = typeof(RelayMessage); var message = (RelayMessage)JsonConvert.DeserializeObject(serializedParameter, type); if (message == null) { return; } var isTimeout = (DateTimeOffset.UtcNow - message.SentDateTimeUtc).TotalSeconds > 60; if (message.Tag == RelayMessageTags.Call) { if (isTimeout) { return; } ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), $"Missed call at {message.SentDateTimeUtc.ToLocalTime()}."); } else if (message.Tag == RelayMessageTags.InstantMessage) { if (isTimeout || await SignaledInstantMessages.IsReceivedAsync(message.Id)) { return; } ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload); ReceivedPushNotifications.Add(message.Id); await SignaledInstantMessages.AddAsync(message); } } catch (Exception) { } } }
public void ServerRelay(RelayMessage message) { ClientConfirmation(Confirmation.For(message)); SignaledRelayMessages.Add(message); var shownUserId = _foregroundChannel.GetShownUserId(); if (message.Tag == RelayMessageTags.InstantMessage && !SignaledRelayMessages.IsPushNotificationReceived(message.Id) && !(shownUserId != null && shownUserId.Equals(message.FromUserId)) && (DateTimeOffset.UtcNow.Subtract(message.SentDateTimeUtc).TotalMinutes < 10)) { ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload); } _foregroundChannel?.OnSignaledRelayMessagesUpdated(); // Handle Voip tags if (message.Tag == RelayMessageTags.VoipCall) { _voipChannel.OnIncomingCall(message); } else if (message.Tag == RelayMessageTags.VoipAnswer) { _voipChannel.OnOutgoingCallAccepted(message); } else if (message.Tag == RelayMessageTags.VoipReject) { _voipChannel.OnOutgoingCallRejected(message); } else if (message.Tag == RelayMessageTags.SdpOffer) { _voipChannel.OnSdpOffer(message); } else if (message.Tag == RelayMessageTags.SdpAnswer) { _voipChannel.OnSdpAnswer(message); } else if (message.Tag == RelayMessageTags.IceCandidate) { _voipChannel.OnIceCandidate(message); } else if (message.Tag == RelayMessageTags.VoipHangup) { _voipChannel.OnRemoteHangup(message); } }