Exemplo n.º 1
0
        /// <summary>
        /// Utility method. Sends broadcast message to clients other than sender
        /// </summary>
        /// <param name="broadcastMessage">Broadcast message to send</param>
        /// <returns>
        /// An Async Task of bool result.
        /// true - Callback was success
        /// false - Callback was failure
        /// </returns>
        private async Task <bool> SendBroadCastMessage(Message broadcastMessage)
        {
            //  Create a client ack
            var clientAck = _clientAckHandler.CreateClientAck(broadcastMessage);

            //  Send notification first and do not block for result
            _ = _notificationHandler.SendBroadcastNotification(broadcastMessage);

            //  Broadcast to all other users
            try
            {
                await Clients.AllExcept(_userHandler.GetUserSession(broadcastMessage.Sender).ConnectionId)
                .SendAsync("receiveBroadcastMessage",
                           broadcastMessage.MessageId,
                           broadcastMessage.Sender,
                           broadcastMessage.Receiver,
                           broadcastMessage.Payload,
                           broadcastMessage.IsImage,
                           CSharpDateTimeToJavaLong(broadcastMessage.SendTime),
                           clientAck.ClientAckId);
            } catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(false);
            }

            return(true);
        }