Fix websockets
This commit is contained in:
parent
c0b95dbc79
commit
e47d121985
|
@ -85,6 +85,11 @@ namespace Emby.Server.Implementations.SocketSharp
|
|||
if (dispose)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
if (_webSocket.State == WebSocketState.Open)
|
||||
{
|
||||
_webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closed by client",
|
||||
CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
|
|
|
@ -76,18 +76,23 @@ using Microsoft.Extensions.Logging;
|
|||
Endpoint = endpoint
|
||||
});
|
||||
|
||||
var buffer = WebSocket.CreateClientBuffer(4096, 4096);
|
||||
WebSocketReceiveResult result;
|
||||
var message = new List<byte>();
|
||||
|
||||
do
|
||||
{
|
||||
var buffer = WebSocket.CreateServerBuffer(4096);
|
||||
result = await webSocketContext.ReceiveAsync(buffer, _disposeCancellationToken);
|
||||
socket.OnReceiveBytes(buffer.Array);
|
||||
message.AddRange(buffer.Array.Take(result.Count));
|
||||
} while (!result.EndOfMessage && result.MessageType != WebSocketMessageType.Close);
|
||||
|
||||
if (result.EndOfMessage)
|
||||
{
|
||||
socket.OnReceiveBytes(message.ToArray());
|
||||
message.Clear();
|
||||
}
|
||||
} while (socket.State == WebSocketState.Open && result.MessageType != WebSocketMessageType.Close);
|
||||
|
||||
|
||||
await webSocketContext.CloseAsync(result.CloseStatus ?? WebSocketCloseStatus.NormalClosure,
|
||||
result.CloseStatusDescription, _disposeCancellationToken);
|
||||
socket.Dispose();
|
||||
|
|
|
@ -80,12 +80,7 @@ namespace MediaBrowser.Controller.Net
|
|||
|
||||
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
protected virtual bool SendOnTimer => false;
|
||||
|
||||
protected virtual void ParseMessageParams(string[] values)
|
||||
{
|
||||
|
||||
}
|
||||
protected bool SendOnTimer => false;
|
||||
|
||||
/// <summary>
|
||||
/// Starts sending messages over a web socket
|
||||
|
@ -98,11 +93,6 @@ namespace MediaBrowser.Controller.Net
|
|||
var dueTimeMs = long.Parse(vals[0], UsCulture);
|
||||
var periodMs = long.Parse(vals[1], UsCulture);
|
||||
|
||||
if (vals.Length > 2)
|
||||
{
|
||||
ParseMessageParams(vals.Skip(2).ToArray());
|
||||
}
|
||||
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
Logger.LogDebug("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);
|
||||
|
@ -250,6 +240,7 @@ namespace MediaBrowser.Controller.Net
|
|||
{
|
||||
Logger.LogDebug("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name);
|
||||
|
||||
connection.Item1.Dispose();
|
||||
var timer = connection.Item3;
|
||||
|
||||
if (timer != null)
|
||||
|
|
Loading…
Reference in New Issue
Block a user