aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Session
diff options
context:
space:
mode:
authoroledfish <88390729+oledfish@users.noreply.github.com>2022-01-16 21:33:18 -0300
committerGitHub <noreply@github.com>2022-01-16 21:33:18 -0300
commit3b075a58027be4a2a3bdf662c70934f6cafafe87 (patch)
treeb4c226f25f843c3f2685c92e1edc3b3999716d34 /Emby.Server.Implementations/Session
parent86a5e72a65df638df2cde349ccd2ad8c5d40f88c (diff)
parentef0708d876434a99ec647473c37295fab45a35fb (diff)
Merge branch 'jellyfin:master' into additional-episode-orders
Diffstat (limited to 'Emby.Server.Implementations/Session')
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs12
-rw-r--r--Emby.Server.Implementations/Session/SessionWebSocketListener.cs37
2 files changed, 27 insertions, 22 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index 4111590c8..6c679ea20 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -60,7 +60,7 @@ namespace Emby.Server.Implementations.Session
/// <summary>
/// The active connections.
/// </summary>
- private readonly ConcurrentDictionary<string, SessionInfo> _activeConnections = new (StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, SessionInfo> _activeConnections = new(StringComparer.OrdinalIgnoreCase);
private Timer _idleTimer;
@@ -741,6 +741,8 @@ namespace Emby.Server.Implementations.Session
/// <summary>
/// Used to report playback progress for an item.
/// </summary>
+ /// <param name="info">The playback progress info.</param>
+ /// <param name="isAutomated">Whether this is an automated update.</param>
/// <returns>Task.</returns>
public async Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated)
{
@@ -1199,16 +1201,18 @@ namespace Emby.Server.Implementations.Session
}
/// <inheritdoc />
- public async Task SendSyncPlayCommand(SessionInfo session, SendCommand command, CancellationToken cancellationToken)
+ public async Task SendSyncPlayCommand(string sessionId, SendCommand command, CancellationToken cancellationToken)
{
CheckDisposed();
+ var session = GetSession(sessionId);
await SendMessageToSession(session, SessionMessageType.SyncPlayCommand, command, cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc />
- public async Task SendSyncPlayGroupUpdate<T>(SessionInfo session, GroupUpdate<T> command, CancellationToken cancellationToken)
+ public async Task SendSyncPlayGroupUpdate<T>(string sessionId, GroupUpdate<T> command, CancellationToken cancellationToken)
{
CheckDisposed();
+ var session = GetSession(sessionId);
await SendMessageToSession(session, SessionMessageType.SyncPlayGroupUpdate, command, cancellationToken).ConfigureAwait(false);
}
@@ -1288,7 +1292,7 @@ namespace Emby.Server.Implementations.Session
{
["ItemId"] = command.ItemId,
["ItemName"] = command.ItemName,
- ["ItemType"] = command.ItemType
+ ["ItemType"] = command.ItemType.ToString()
}
};
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index 2a14a8c7b..a085ee546 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Net;
@@ -50,16 +51,10 @@ namespace Emby.Server.Implementations.Session
/// </summary>
private readonly object _webSocketsLock = new object();
- /// <summary>
- /// The _session manager.
- /// </summary>
private readonly ISessionManager _sessionManager;
-
- /// <summary>
- /// The _logger.
- /// </summary>
private readonly ILogger<SessionWebSocketListener> _logger;
private readonly ILoggerFactory _loggerFactory;
+ private readonly IAuthorizationContext _authorizationContext;
/// <summary>
/// The KeepAlive cancellation token.
@@ -72,14 +67,17 @@ namespace Emby.Server.Implementations.Session
/// <param name="logger">The logger.</param>
/// <param name="sessionManager">The session manager.</param>
/// <param name="loggerFactory">The logger factory.</param>
+ /// <param name="authorizationContext">The authorization context.</param>
public SessionWebSocketListener(
ILogger<SessionWebSocketListener> logger,
ISessionManager sessionManager,
- ILoggerFactory loggerFactory)
+ ILoggerFactory loggerFactory,
+ IAuthorizationContext authorizationContext)
{
_logger = logger;
_sessionManager = sessionManager;
_loggerFactory = loggerFactory;
+ _authorizationContext = authorizationContext;
}
/// <inheritdoc />
@@ -97,9 +95,9 @@ namespace Emby.Server.Implementations.Session
=> Task.CompletedTask;
/// <inheritdoc />
- public async Task ProcessWebSocketConnectedAsync(IWebSocketConnection connection)
+ public async Task ProcessWebSocketConnectedAsync(IWebSocketConnection connection, HttpContext httpContext)
{
- var session = await GetSession(connection.QueryString, connection.RemoteEndPoint.ToString()).ConfigureAwait(false);
+ var session = await GetSession(httpContext, connection.RemoteEndPoint?.ToString()).ConfigureAwait(false);
if (session != null)
{
EnsureController(session, connection);
@@ -107,25 +105,28 @@ namespace Emby.Server.Implementations.Session
}
else
{
- _logger.LogWarning("Unable to determine session based on query string: {0}", connection.QueryString);
+ _logger.LogWarning("Unable to determine session based on query string: {0}", httpContext.Request.QueryString);
}
}
- private Task<SessionInfo> GetSession(IQueryCollection queryString, string remoteEndpoint)
+ private async Task<SessionInfo> GetSession(HttpContext httpContext, string remoteEndpoint)
{
- if (queryString == null)
+ var authorizationInfo = await _authorizationContext.GetAuthorizationInfo(httpContext)
+ .ConfigureAwait(false);
+
+ if (!authorizationInfo.IsAuthenticated)
{
return null;
}
- var token = queryString["api_key"];
- if (string.IsNullOrWhiteSpace(token))
+ var deviceId = authorizationInfo.DeviceId;
+ if (httpContext.Request.Query.TryGetValue("deviceId", out var queryDeviceId))
{
- return null;
+ deviceId = queryDeviceId;
}
- var deviceId = queryString["deviceId"];
- return _sessionManager.GetSessionByAuthenticationToken(token, deviceId, remoteEndpoint);
+ return await _sessionManager.GetSessionByAuthenticationToken(authorizationInfo.Token, deviceId, remoteEndpoint)
+ .ConfigureAwait(false);
}
private void EnsureController(SessionInfo session, IWebSocketConnection connection)