public async Task <IActionResult> NotifyEntityUpdate(string userId, [FromBody] RealtimeEntityUpdateMessage message) { _logger.LogDebug($"UserId: {userId}\nMessage: {message.Channel}"); await _hub.SendUserAsync(userId, message.Channel, new object[] { message }); return(Ok(message)); }
public async Task <ActionResult <ChatViewModel> > Initialise([FromBody] ChatViewModel message) { var chatUser = await _userManager.FindByEmailAsync(_chatSettings.CurrentChatUser); if (chatUser != null) { var chat = _mapper.Map <ChatMessage>(message); chat.FromUser = _applicationUser; chat.ToUser = chatUser; if (chat.FromUser != null) { _chatRepository.AddOrUpdate(chat); await _unitOfWork.CompleteAsync(); } else { // it's an anonymous chat, we don't need to save item chat.Id = System.Guid.NewGuid(); } var filledMessage = _mapper.Map <ChatViewModel>(chat); filledMessage.FromUserName = _applicationUser == null ? message.FromUserName : _applicationUser.GetBestGuessName(); //send push message to whoever is registered as admin await _subscriptionStore.ForEachSubscriptionAsync(chatUser.Id, (PushSubscription subscription) => { _notificationService.SendNotificationAsync( subscription, new PushMessage("New SUPPORT Request") { Urgency = PushMessageUrgency.High, Topic = "NewSupport" }, _appSettings.SiteUrl); }); if (await _supportChatService.InitiateSupportRequest(filledMessage)) { await _hub.SendUserAsync(filledMessage.ToUserId, "support-message", new object[] { filledMessage }); return(Ok(filledMessage)); } } return(StatusCode(503)); }
public async Task <IActionResult> Realtime([FromBody] string message) { await _hub.SendUserAsync(User.Identity.Name, "Send", new string[] { $"User {User.Identity.Name}: {message}" }); await _hub.SendAllAsync("Send", new string[] { $"All: {message}" }); return(Ok(message)); }
public async Task <bool> SendProcessUpdate(string userId, string channelName, object data) { try { await _hub.SendUserAsync( userId, channelName, //userId, new object[] { data }); return(true); } catch (Exception) { return(false); } }
private async Task _notifyHubs() { var newEntities = _context.ChangeTracker.Entries() .Where(e => e.State == EntityState.Added) .Where(e => e.Entity is IHubNotifyEntity) .Select(e => e.Entity as IHubNotifyEntity); foreach (var entity in newEntities) { var method = entity?.GetHubMethodName(); if (!string.IsNullOrEmpty(method)) { _logger.LogDebug($"Notifying {method} hub of update to {entity}"); var user = entity.UserIdForRealtime(_context); if (!string.IsNullOrEmpty(user)) { var payload = entity?.SerialiseForHub(); await _hub.SendUserAsync( user, method, new object[] { payload }); } } } }
public Task SendCoreAsync(string method, object?[] args, CancellationToken cancellationToken = default) { return(_lifetimeManager.SendUserAsync(_userId, method, args, cancellationToken)); }
public override Task SendUserAsync(string userId, string methodName, object[] args) { return(_wrappedHubLifetimeManager.SendUserAsync(userId, methodName, args)); }
public override Task SendUserAsync(string userId, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedHubLifetimeManager.SendUserAsync(userId, methodName, args, cancellationToken)); }
private static async Task InvokeMethod(HubLifetimeManager <TestHub> serviceLifetimeManager, string methodName) { switch (methodName) { case "SendAllAsync": await serviceLifetimeManager.SendAllAsync(TestMethod, TestArgs); break; case "SendAllExceptAsync": await serviceLifetimeManager.SendAllExceptAsync(TestMethod, TestArgs, TestConnectionIds); break; case "SendConnectionAsync": await serviceLifetimeManager.SendConnectionAsync(TestConnectionIds[0], TestMethod, TestArgs); break; case "SendConnectionsAsync": await serviceLifetimeManager.SendConnectionsAsync(TestConnectionIds, TestMethod, TestArgs); break; case "SendGroupAsync": await serviceLifetimeManager.SendGroupAsync(TestGroups[0], TestMethod, TestArgs); break; case "SendGroupsAsync": await serviceLifetimeManager.SendGroupsAsync(TestGroups, TestMethod, TestArgs); break; case "SendGroupExceptAsync": await serviceLifetimeManager.SendGroupExceptAsync(TestGroups[0], TestMethod, TestArgs, TestConnectionIds); break; case "SendUserAsync": await serviceLifetimeManager.SendUserAsync(TestUsers[0], TestMethod, TestArgs); break; case "SendUsersAsync": await serviceLifetimeManager.SendUsersAsync(TestUsers, TestMethod, TestArgs); break; case "AddToGroupAsync": await serviceLifetimeManager.AddToGroupAsync(TestConnectionIds[0], TestGroups[0]); break; case "RemoveFromGroupAsync": await serviceLifetimeManager.RemoveFromGroupAsync(TestConnectionIds[0], TestGroups[0]); break; default: break; } }
public RabbitMQService(IBus bus, HubLifetimeManager <AudioProcessingHub> audioProcessingHub, HubLifetimeManager <UserUpdatesHub> userUpdateHub, IServiceScopeFactory serviceScopeFactory, ILogger <RabbitMQService> logger) { _bus = bus; _audioProcessingHub = audioProcessingHub; _userUpdateHub = userUpdateHub; _logger = logger; _subscriber = new AutoSubscriber(_bus, "_applications_subscriptionId_prefix"); _subscriber.Subscribe(new[] { Assembly.GetExecutingAssembly() }); try { _bus.PubSub.Subscribe <RealtimeUpdateMessage>( "podnoms_message_realtimeupdate", message => { _logger.LogInformation( $"(RabbitMQService) Consuming: {message.Message}\n\tUser: {message.UserId}"); _userUpdateHub.SendUserAsync( message.UserId, message.ChannelName, new object[] { message }); }); _bus.PubSub.Subscribe <ProcessingUpdateMessage>( "podnoms_message_audioprocessing", message => { _logger.LogInformation( $"(RabbitMQService) Consuming: {message.Data}\n\tUser: {message.UserId}"); _audioProcessingHub.SendUserAsync( message.UserId, message.ChannelName, new[] { message.Data }); }); _bus.PubSub.Subscribe <NotifyUserMessage>( "podnoms_message_notifyuser", message => { _logger.LogDebug($"(RabbitMQService) Consuming: {message.Body}"); using var scope = serviceScopeFactory.CreateScope(); var service = scope.ServiceProvider.GetRequiredService <INotifyJobCompleteService>(); service.NotifyUser( message.UserId, message.Title, message.Body, message.Target, message.Image, NotificationOptions.UploadCompleted); } ); _bus.PubSub.Subscribe <CustomNotificationMessage>( "podnoms_message_customnotification", message => { _logger.LogDebug($"(RabbitMQService) Consuming: {message.Body}"); using var scope = serviceScopeFactory.CreateScope(); var service = scope.ServiceProvider.GetRequiredService <INotifyJobCompleteService>(); service.SendCustomNotifications( message.PodcastId, "YOU NEED TO CHANGE THIS", "PodNoms", $"{message.Title} has finished processing", message.Url); } ); } catch (Exception e) { _logger.LogError("Unable to start realtime queue listeners"); _logger.LogError(e.Message); } }
public Task SendCoreAsync(string method, object[] args) { return(_lifetimeManager.SendUserAsync(_userId, method, args)); }