Exemplo n.º 1
0
        public async Task <IActionResult> GetWebSocketIo()
        {
            await _webSocketIo.SendDataAsync("/* This is only websocket response. */", false);

            return(Ok(new
            {
                WebSocketData = "ok"
            }));
        }
        /// <inheritdoc cref="ExecuteResultAsync"/>
        public override Task ExecuteResultAsync(ActionContext context)
        {
            var packet = context.HttpContext.Items["web-socket-io-packet"] as WebSocketIoPacket;

            if (packet == null)
            {
                throw new NullReferenceException(nameof(packet));
            }

            return(_webSocketIo.SendDataAsync(new WebSocketIoResponse(packet.Id, new { }).ToJson()));
        }
 /// <summary>
 /// 클라이언트에게 객체를 전송합니다.
 /// </summary>
 /// <param name="webSocketIo"><see cref="IWebSocketIo"/></param>
 /// <param name="obj">객체 입니다.</param>
 /// <param name="endOfMessage">메시지의 끝인지 아닌지의 여부 입니다.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> 입니다.</param>
 public static Task SendDataAsync(this IWebSocketIo webSocketIo, object obj, bool endOfMessage = true,
                                  CancellationToken cancellationToken = default(CancellationToken))
 {
     return(webSocketIo.SendDataAsync(obj, endOfMessage, cancellationToken));
 }