Esempio n. 1
0
        /// <summary>
        /// Broadcasts a message to all conntected userIds.
        /// </summary>
        /// <returns>The users message async.</returns>
        /// <param name="userIds">User identifiers.</param>
        /// <param name="command">Command.</param>
        /// <param name="content">Content.</param>
        /// <param name="cancellationToken"></param>
        public async Task BroadcastUsersMessageAsync(IEnumerable <string> userIds, EClientCommand command, object content, CancellationToken cancellationToken)
        {
            var sendMessage = new ClientMessage(command, content);

            foreach (var userId in userIds)
            {
                await _browserContext.Clients.User(userId).SendAsync("Command", sendMessage, cancellationToken: cancellationToken);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Broadcast a message to a specific browser client.
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="command"></param>
        /// <param name="content"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task BroadcastClientMessageAsync(string connectionId, EClientCommand command, object content, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(connectionId))
            {
                _logger.LogWarning($"BroadcastClientMessage failed due to empty client id.  The command was: {command}.");
                return(Task.CompletedTask);
            }

            var sendMessage = new ClientMessage(command, content);

            return(_browserContext.Clients.Client(connectionId).SendAsync("Command", sendMessage, cancellationToken: cancellationToken));
        }
Esempio n. 3
0
 /// <summary>
 /// Broadcasts the hub message async.
 /// </summary>
 /// <returns>The hub message async.</returns>
 /// <param name="hubKey">Hub key.</param>
 /// <param name="command">Command.</param>
 /// <param name="content">Content.</param>
 /// <param name="cancellationToken"></param>
 public async Task BroadcastHubMessageAsync(long hubKey, EClientCommand command, object content, CancellationToken cancellationToken)
 {
     var sendMessage = new ClientMessage(command, content);
     await _browserContext.Clients.Group(hubKey.ToString()).SendAsync("Command", sendMessage, cancellationToken: cancellationToken);
 }
Esempio n. 4
0
 public ClientMessage(EClientCommand command, object value)
 {
     Command = command;
     Value   = value;
 }