diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-05 17:34:46 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-05 17:34:46 -0400 |
| commit | 98e7eeeff933d6f5ba18daecb3931337523dc01b (patch) | |
| tree | 4ff3bec38ad3c9cffa74787aa51aa928ec3e2ab6 /MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs | |
| parent | 44b12c0f9fc81dd10d6f655f341d7df28c5f3e20 (diff) | |
reduce byte conversions with alchemy web socket
Diffstat (limited to 'MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs b/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs new file mode 100644 index 000000000..3667fab07 --- /dev/null +++ b/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs @@ -0,0 +1,47 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Model.Net; +using System; +using System.Threading; +using System.Threading.Tasks; +using IWebSocketConnection = Fleck.IWebSocketConnection; + +namespace MediaBrowser.Server.Implementations.WebSocket +{ + public class FleckWebSocket : IWebSocket + { + private readonly IWebSocketConnection _connection; + + public FleckWebSocket(IWebSocketConnection connection) + { + _connection = connection; + + _connection.OnMessage = OnReceiveData; + } + + public WebSocketState State + { + get { return _connection.IsAvailable ? WebSocketState.Open : WebSocketState.Closed; } + } + + private void OnReceiveData(string data) + { + if (OnReceive != null) + { + OnReceive(data); + } + } + + public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) + { + return Task.Run(() => _connection.Send(bytes)); + } + + public void Dispose() + { + _connection.Close(); + } + + public Action<byte[]> OnReceiveBytes { get; set; } + public Action<string> OnReceive { get; set; } + } +} |
