/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) { System.Net.WebSockets.WebSocketMessageType nativeType; if (!Enum.TryParse(type.ToString(), true, out nativeType)) { _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); } return(WebSocket.SendAsync(new ArraySegment <byte>(bytes), nativeType, true, cancellationToken)); }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public async Task SendAsync(byte[] bytes, MediaBrowser.Model.Net.WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken = default(CancellationToken)) { await _sendResource.WaitAsync(cancellationToken).ConfigureAwait(false); try { WebSocketMessageType nativeType; if (!Enum.TryParse(type.ToString(), true, out nativeType)) { _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); } var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token); await _client.SendAsync(new ArraySegment <byte>(bytes), nativeType, true, linkedTokenSource.Token).ConfigureAwait(false); } finally { _sendResource.Release(); } }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) { System.Net.WebSockets.WebSocketMessageType nativeType; if (!Enum.TryParse(type.ToString(), true, out nativeType)) { _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); } var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token); return WebSocket.SendAsync(new ArraySegment<byte>(bytes), nativeType, true, linkedTokenSource.Token); }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public Task SendAsync(byte[] bytes, MediaBrowser.Model.Net.WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken = default(CancellationToken)) { return(Task.Run(() => _socket.Send(bytes, 0, bytes.Length), cancellationToken)); }