public async Task <IActionResult> ChatAsync(string channelName, ChatRequest request) { await _webSocketIo.Broadcast.In(channelName).SendDataAsync( WebSocketIoResponse.CreateEvent(_packet, "chat.received", request.Message)); return(Ok()); }
/// <summary> /// 클라이언트에게 데이터를 전송합니다. /// </summary> /// <param name="webSocketIos"><see cref="IWebSocketIo"/> 목록입니다.</param> /// <param name="response">응답 패킷 입니다.</param> /// <param name="cancellationToken"><see cref="CancellationToken"/> 입니다.</param> /// <returns></returns> public static async Task SendDataAsync(this IEnumerable <IWebSocketIo> webSocketIos, WebSocketIoResponse response, CancellationToken cancellationToken = default(CancellationToken)) { foreach (var webSocketIo in webSocketIos) { await SendDataAsync(webSocketIo, response, true, cancellationToken); } }
public async Task <IActionResult> JoinAsync(string channelName) { _webSocketIo.Disconnecting += WebSocketIoOnDisconnecting; _webSocketIo.Leaved += WebSocketIoOnLeaved; await _webSocketIo.JoinAsync(channelName); await _webSocketIo.Broadcast.In(channelName).SendDataAsync( WebSocketIoResponse.CreateEvent(_packet, "chat.joined", $"Joined {_webSocketIo.SocketId} in {channelName}.")); return(Ok()); }
/// <inheritdoc cref="SendDataAsync(WebSocketIoResponse, CancellationToken)"/> public Task SendDataAsync(WebSocketIoResponse response, CancellationToken cancellationToken = default(CancellationToken)) { return(Socket.SendDataAsync(response.ToJson(), true, cancellationToken)); }