diff --git a/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs b/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs
index eab903db8e..66c5cc334b 100644
--- a/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs
+++ b/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs
@@ -21,7 +21,7 @@ namespace Emby.Server.Implementations.SocketSharp
/// Gets or sets the web socket.
///
/// The web socket.
- private WebSocket WebSocket { get; set; }
+ private readonly WebSocket _webSocket;
private TaskCompletionSource _taskCompletionSource = new TaskCompletionSource();
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
@@ -30,45 +30,14 @@ namespace Emby.Server.Implementations.SocketSharp
public SharpWebSocket(WebSocket socket, ILogger logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
- WebSocket = socket ?? throw new ArgumentNullException(nameof(socket));
+ _webSocket = socket ?? throw new ArgumentNullException(nameof(socket));
}
- public Task StartReceive()
- {
- return _taskCompletionSource.Task;
- }
-
- private void OnSocketError(object sender, SocketHttpListener.ErrorEventArgs e)
- {
- _logger.LogError("Error in SharpWebSocket: {Message}", e.Message ?? string.Empty);
-
- // Closed?.Invoke(this, EventArgs.Empty);
- }
-
- private void OnSocketClose(object sender, SocketHttpListener.CloseEventArgs e)
- {
- _taskCompletionSource.TrySetResult(true);
-
- Closed?.Invoke(this, EventArgs.Empty);
- }
-
- private void OnSocketMessage(SocketHttpListener.MessageEventArgs e)
- {
- if (OnReceiveBytes != null)
- {
- OnReceiveBytes(e.RawData);
- }
- }
-
- public Task ConnectAsServerAsync()
- {
- return Task.CompletedTask;
- }
///
/// Gets or sets the state.
///
/// The state.
- public WebSocketState State => WebSocket.State;
+ public WebSocketState State => _webSocket.State;
///
/// Sends the async.
@@ -79,7 +48,7 @@ namespace Emby.Server.Implementations.SocketSharp
/// Task.
public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken)
{
- return WebSocket.SendAsync(new ArraySegment(bytes), WebSocketMessageType.Binary, endOfMessage, cancellationToken);
+ return _webSocket.SendAsync(new ArraySegment(bytes), WebSocketMessageType.Binary, endOfMessage, cancellationToken);
}
///
@@ -91,7 +60,7 @@ namespace Emby.Server.Implementations.SocketSharp
/// Task.
public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken)
{
- return WebSocket.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(text)), WebSocketMessageType.Text, endOfMessage, cancellationToken);
+ return _webSocket.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(text)), WebSocketMessageType.Text, endOfMessage, cancellationToken);
}
///
@@ -117,9 +86,6 @@ namespace Emby.Server.Implementations.SocketSharp
if (dispose)
{
_cancellationTokenSource.Cancel();
-
- // TODO
- // WebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "bye", CancellationToken.None).GetAwaiter().GetResult();
}
_disposed = true;
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
index 6e5190efdb..7a6144fb23 100644
--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
@@ -71,7 +71,6 @@ using Microsoft.Extensions.Logging;
var webSocketContext = await ctx.WebSockets.AcceptWebSocketAsync(null).ConfigureAwait(false);
var socket = new SharpWebSocket(webSocketContext, _logger);
- await socket.ConnectAsServerAsync().ConfigureAwait(false);
WebSocketConnected(new WebSocketConnectEventArgs
{