/// <summary> /// Called when a client has connected to the server. /// </summary> /// <param name="socket">The web-socket of the client.</param> /// <returns>Awaitable Task.</returns> public virtual async Task OnConnected(WebSocket socket) { WebSocketConnectionManager.AddSocket(socket); await SendMessageAsync(socket, new Message() { Data = WebSocketConnectionManager.GetId(socket) }).ConfigureAwait(false); }
/// <summary> /// Called when a client has connected to the server. /// </summary> /// <param name="socket">The web-socket of the client.</param> /// <param name="context">The http context of the client.</param> /// <returns>Awaitable Task.</returns> public virtual async Task OnConnected(WebSocket socket, HttpContext context) { WebSocketConnectionManager.AddSocket(socket); await SendMessageAsync(socket, new Message() { MessageType = MessageType.ConnectionEvent, Data = WebSocketConnectionManager.GetId(socket) }).ConfigureAwait(false); }
public virtual async Task OnResponseAsync(WebSocketConnection socket, string serializedMessage) { var socketId = WebSocketConnectionManager.GetId(socket); var invocationResult = JsonConvert.DeserializeObject <InvocationResult>(serializedMessage, _jsonSerializerSettings); if (_waitingRemoteInvocations.ContainsKey(socketId) && invocationResult.Id > 0) { if (_waitingRemoteInvocations[socketId].ContainsKey(invocationResult.Id)) { _waitingRemoteInvocations[socketId][invocationResult.Id].SetResult(invocationResult); // remove the completion source from the waiting list. } _waitingRemoteInvocations[socketId].Remove(invocationResult.Id); } }
/// <summary> /// Called when a client has disconnected from the server. /// </summary> /// <param name="socket">The web-socket of the client.</param> /// <returns>Awaitable Task.</returns> public virtual async Task OnDisconnected(WebSocket socket) { await WebSocketConnectionManager.RemoveSocket(WebSocketConnectionManager.GetId(socket)).ConfigureAwait(false); }
/// <summary> /// Called when a client has disconnected from the server. /// </summary> /// <param name="socket">The web-socket of the client.</param> /// <returns>Awaitable Task.</returns> public virtual async Task OnDisconnected(WebSocket socket) { await WebSocketConnectionManager.RemoveSocket(WebSocketConnectionManager.GetId(socket)).ConfigureAwait(false); // TODO remove from users list and send user disconnected to all }