From 7c6cedd90ac26d6b18fd518f25421b2b71c74993 Mon Sep 17 00:00:00 2001 From: KGT1 Date: Fri, 12 Sep 2025 22:15:00 +0200 Subject: Allow non-admin users to subscribe to their own Sessions (#13767) --- .../Net/BasePeriodicWebSocketListener.cs | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'MediaBrowser.Controller/Net') diff --git a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs index 4757bfa303..1e0d77fe51 100644 --- a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs +++ b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs @@ -80,6 +80,16 @@ namespace MediaBrowser.Controller.Net /// Task{`1}. protected abstract Task GetDataToSend(); + /// + /// Gets the data to send for a specific connection. + /// + /// The connection. + /// Task{`1}. + protected virtual Task GetDataToSendForConnection(IWebSocketConnection connection) + { + return GetDataToSend(); + } + /// /// Processes the message. /// @@ -174,17 +184,11 @@ namespace MediaBrowser.Controller.Net continue; } - var data = await GetDataToSend().ConfigureAwait(false); - if (data is null) - { - continue; - } - IEnumerable GetTasks() { foreach (var tuple in tuples) { - yield return SendDataInternal(data, tuple); + yield return SendDataForConnectionAsync(tuple); } } @@ -198,12 +202,19 @@ namespace MediaBrowser.Controller.Net } } - private async Task SendDataInternal(TReturnDataType data, (IWebSocketConnection Connection, CancellationTokenSource CancellationTokenSource, TStateType State) tuple) + private async Task SendDataForConnectionAsync((IWebSocketConnection Connection, CancellationTokenSource CancellationTokenSource, TStateType State) tuple) { try { var (connection, cts, state) = tuple; var cancellationToken = cts.Token; + + var data = await GetDataToSendForConnection(connection).ConfigureAwait(false); + if (data is null) + { + return; + } + await connection.SendAsync( new OutboundWebSocketMessage { MessageType = Type, Data = data }, cancellationToken).ConfigureAwait(false); -- cgit v1.2.3