Пример #1
0
        public async Task SendAllNotifyAsync(string methodName, object result)
        {
            // create the method invocation descriptor.
            InvocationDescriptor invocationDescriptor = new InvocationDescriptor {
                Id = 0, MethodName = methodName, Params = result
            };

            var message = new Message()
            {
                MessageType = MessageType.MethodInvocation,
                Data        = JsonConvert.SerializeObject(invocationDescriptor)
            };

            foreach (var pair in WebSocketConnectionManager.GetAll())
            {
                try
                {
                    if (pair.Value.WebSocket.State == WebSocketState.Open)
                    {
                        await SendMessageAsync(pair.Value, message).ConfigureAwait(false);
                    }
                }
                catch (WebSocketException e)
                {
                    if (e.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
                    {
                        await OnDisconnected(pair.Value);
                    }
                }
            }
        }
Пример #2
0
 public async Task InvokeClientMethodToAllAsync(string methodName, object[] arguments)
 {
     foreach (var pair in WebSocketConnectionManager.GetAll())
     {
         try
         {
             if (pair.Value.WebSocket.State == WebSocketState.Open)
             {
                 await InvokeClientMethodAsync(pair.Key, methodName, arguments).ConfigureAwait(false);
             }
         }
         catch (WebSocketException e)
         {
             if (e.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
             {
                 await OnDisconnected(pair.Value);
             }
         }
     }
 }
Пример #3
0
 public async Task SendMessageToAllAsync(Message message)
 {
     foreach (var pair in WebSocketConnectionManager.GetAll())
     {
         try
         {
             if (pair.Value.WebSocket.State == WebSocketState.Open)
             {
                 await SendMessageAsync(pair.Value, message).ConfigureAwait(false);
             }
         }
         catch (WebSocketException e)
         {
             if (e.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
             {
                 await OnDisconnected(pair.Value);
             }
         }
     }
 }