Fix web sockets closing ungracefully

pull/7732/head
luke brown 3 years ago
parent 39196bb5e2
commit 4b563f4d7e

@ -889,6 +889,11 @@ namespace Emby.Dlna.PlayTo
return Task.CompletedTask;
}
public void CloseAllWebSockets(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
private class StreamParams
{
private MediaSourceInfo _mediaSource;

@ -231,6 +231,15 @@ namespace Emby.Server.Implementations.HttpServer
CancellationToken.None);
}
/// <summary>
/// Gracefully closes the socket.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
public void CloseSocket(CancellationToken cancellationToken)
{
_socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "System Shutdown", cancellationToken);
}
/// <inheritdoc />
public void Dispose()
{

@ -1363,9 +1363,26 @@ namespace Emby.Server.Implementations.Session
{
CheckDisposed();
CloseAllWebSockets(cancellationToken);
return SendMessageToSessions(Sessions, SessionMessageType.ServerShuttingDown, string.Empty, cancellationToken);
}
/// <summary>
/// Gracefully closes all web sockets in all sessions.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
private void CloseAllWebSockets(CancellationToken cancellationToken)
{
foreach (var session in Sessions)
{
foreach (var sessionController in session.SessionControllers)
{
sessionController.CloseAllWebSockets(cancellationToken);
}
}
}
/// <summary>
/// Sends the server restart notification.
/// </summary>

@ -88,6 +88,18 @@ namespace Emby.Server.Implementations.Session
cancellationToken);
}
/// <summary>
/// Gracefully closes all web sockets.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
public void CloseAllWebSockets(CancellationToken cancellationToken)
{
foreach (var socket in _sockets)
{
socket.CloseSocket(cancellationToken);
}
}
/// <inheritdoc />
public void Dispose()
{

@ -58,5 +58,11 @@ namespace MediaBrowser.Controller.Net
Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
Task ProcessAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gracefully closes the socket.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void CloseSocket(CancellationToken cancellationToken);
}
}

@ -33,5 +33,11 @@ namespace MediaBrowser.Controller.Session
/// <param name="cancellationToken">CancellationToken for operation.</param>
/// <returns>A task.</returns>
Task SendMessage<T>(SessionMessageType name, Guid messageId, T data, CancellationToken cancellationToken);
/// <summary>
/// Gracefully closes all web sockets.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void CloseAllWebSockets(CancellationToken cancellationToken);
}
}

Loading…
Cancel
Save