mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-13 13:46:24 +00:00
reduce byte conversions with alchemy web socket
This commit is contained in:
@@ -186,7 +186,10 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||
/// <param name="e">The <see cref="WebSocketConnectEventArgs" /> instance containing the event data.</param>
|
||||
void HttpServer_WebSocketConnected(object sender, WebSocketConnectEventArgs e)
|
||||
{
|
||||
var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger) { OnReceive = ProcessWebSocketMessageReceived };
|
||||
var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger)
|
||||
{
|
||||
OnReceive = ProcessWebSocketMessageReceived
|
||||
};
|
||||
|
||||
_webSocketConnections.Add(connection);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_socket = socket;
|
||||
_socket.OnReceiveDelegate = OnReceiveInternal;
|
||||
_socket.OnReceiveBytes = OnReceiveInternal;
|
||||
_socket.OnReceive = OnReceiveInternal;
|
||||
RemoteEndPoint = remoteEndPoint;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -127,6 +128,34 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReceiveInternal(string message)
|
||||
{
|
||||
LastActivityDate = DateTime.UtcNow;
|
||||
|
||||
if (OnReceive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var stub = (WebSocketMessage<object>)_jsonSerializer.DeserializeFromString(message, typeof(WebSocketMessage<object>));
|
||||
|
||||
var info = new WebSocketMessageInfo
|
||||
{
|
||||
MessageType = stub.MessageType,
|
||||
Data = stub.Data == null ? null : stub.Data.ToString()
|
||||
};
|
||||
|
||||
info.Connection = this;
|
||||
|
||||
OnReceive(info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error processing web socket message", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message asynchronously.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user