From 98e7eeeff933d6f5ba18daecb3931337523dc01b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 5 Sep 2013 17:34:46 -0400 Subject: reduce byte conversions with alchemy web socket --- .../WebSocket/AlchemyWebSocket.cs | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'MediaBrowser.Server.Implementations/WebSocket/AlchemyWebSocket.cs') diff --git a/MediaBrowser.Server.Implementations/WebSocket/AlchemyWebSocket.cs b/MediaBrowser.Server.Implementations/WebSocket/AlchemyWebSocket.cs index 0b6b14566..958201625 100644 --- a/MediaBrowser.Server.Implementations/WebSocket/AlchemyWebSocket.cs +++ b/MediaBrowser.Server.Implementations/WebSocket/AlchemyWebSocket.cs @@ -3,7 +3,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; using System; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -42,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.WebSocket UserContext = context; context.SetOnDisconnect(OnDisconnected); - context.SetOnReceive(OnReceive); + context.SetOnReceive(OnReceiveContext); _logger.Info("Client connected from {0}", context.ClientAddress); } @@ -50,7 +49,7 @@ namespace MediaBrowser.Server.Implementations.WebSocket /// /// The _disconnected /// - private bool _disconnected = false; + private bool _disconnected; /// /// Gets or sets the state. /// @@ -73,25 +72,13 @@ namespace MediaBrowser.Server.Implementations.WebSocket /// Called when [receive]. /// /// The context. - private void OnReceive(UserContext context) + private void OnReceiveContext(UserContext context) { - if (OnReceiveDelegate != null) + if (OnReceive != null) { var json = context.DataFrame.ToString(); - if (!string.IsNullOrWhiteSpace(json)) - { - try - { - var bytes = Encoding.UTF8.GetBytes(json); - - OnReceiveDelegate(bytes); - } - catch (Exception ex) - { - _logger.ErrorException("Error processing web socket message", ex); - } - } + OnReceive(json); } } @@ -128,6 +115,12 @@ namespace MediaBrowser.Server.Implementations.WebSocket /// Gets or sets the receive action. /// /// The receive action. - public Action OnReceiveDelegate { get; set; } + public Action OnReceiveBytes { get; set; } + + /// + /// Gets or sets the on receive. + /// + /// The on receive. + public Action OnReceive { get; set; } } } -- cgit v1.2.3