mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-11 12:46:20 +00:00
Fix code issues
This commit is contained in:
@@ -22,17 +22,17 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <summary>
|
||||
/// The timeout in seconds after which a WebSocket is considered to be lost.
|
||||
/// </summary>
|
||||
public readonly int WebSocketLostTimeout = 60;
|
||||
public const int WebSocketLostTimeout = 60;
|
||||
|
||||
/// <summary>
|
||||
/// The keep-alive interval factor; controls how often the watcher will check on the status of the WebSockets.
|
||||
/// </summary>
|
||||
public readonly double IntervalFactor = 0.2;
|
||||
public const float IntervalFactor = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// The ForceKeepAlive factor; controls when a ForceKeepAlive is sent.
|
||||
/// </summary>
|
||||
public readonly double ForceKeepAliveFactor = 0.75;
|
||||
public const float ForceKeepAliveFactor = 0.75f;
|
||||
|
||||
/// <summary>
|
||||
/// The _session manager
|
||||
@@ -213,7 +213,7 @@ namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
_keepAliveCancellationToken = new CancellationTokenSource();
|
||||
// Start KeepAlive watcher
|
||||
var task = RepeatAsyncCallbackEvery(
|
||||
_ = RepeatAsyncCallbackEvery(
|
||||
KeepAliveSockets,
|
||||
TimeSpan.FromSeconds(WebSocketLostTimeout * IntervalFactor),
|
||||
_keepAliveCancellationToken.Token);
|
||||
@@ -241,6 +241,7 @@ namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
webSocket.Closed -= OnWebSocketClosed;
|
||||
}
|
||||
|
||||
_webSockets.Clear();
|
||||
}
|
||||
}
|
||||
@@ -250,8 +251,8 @@ namespace Emby.Server.Implementations.Session
|
||||
/// </summary>
|
||||
private async Task KeepAliveSockets()
|
||||
{
|
||||
IEnumerable<IWebSocketConnection> inactive;
|
||||
IEnumerable<IWebSocketConnection> lost;
|
||||
List<IWebSocketConnection> inactive;
|
||||
List<IWebSocketConnection> lost;
|
||||
|
||||
lock (_webSocketsLock)
|
||||
{
|
||||
@@ -261,8 +262,8 @@ namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
var elapsed = (DateTime.UtcNow - i.LastKeepAliveDate).TotalSeconds;
|
||||
return (elapsed > WebSocketLostTimeout * ForceKeepAliveFactor) && (elapsed < WebSocketLostTimeout);
|
||||
});
|
||||
lost = _webSockets.Where(i => (DateTime.UtcNow - i.LastKeepAliveDate).TotalSeconds >= WebSocketLostTimeout);
|
||||
}).ToList();
|
||||
lost = _webSockets.Where(i => (DateTime.UtcNow - i.LastKeepAliveDate).TotalSeconds >= WebSocketLostTimeout).ToList();
|
||||
}
|
||||
|
||||
if (inactive.Any())
|
||||
@@ -279,7 +280,7 @@ namespace Emby.Server.Implementations.Session
|
||||
catch (WebSocketException exception)
|
||||
{
|
||||
_logger.LogInformation(exception, "Error sending ForceKeepAlive message to WebSocket.");
|
||||
lost = lost.Append(webSocket);
|
||||
lost.Add(webSocket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +289,7 @@ namespace Emby.Server.Implementations.Session
|
||||
if (lost.Any())
|
||||
{
|
||||
_logger.LogInformation("Lost {0} WebSockets.", lost.Count());
|
||||
foreach (var webSocket in lost.ToList())
|
||||
foreach (var webSocket in lost)
|
||||
{
|
||||
// TODO: handle session relative to the lost webSocket
|
||||
RemoveWebSocket(webSocket);
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
session => session.Session
|
||||
).ToArray();
|
||||
default:
|
||||
return new SessionInfo[] { };
|
||||
return Array.Empty<SessionInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
PlayingItemName = _group.PlayingItem.Name,
|
||||
PlayingItemId = _group.PlayingItem.Id.ToString(),
|
||||
PositionTicks = _group.PositionTicks,
|
||||
Participants = _group.Participants.Values.Select(session => session.Session.UserName).Distinct().ToArray()
|
||||
Participants = _group.Participants.Values.Select(session => session.Session.UserName).Distinct().ToList().AsReadOnly()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
/// <summary>
|
||||
/// The groups.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, ISyncPlayController> _groups =
|
||||
new Dictionary<string, ISyncPlayController>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<Guid, ISyncPlayController> _groups =
|
||||
new Dictionary<Guid, ISyncPlayController>();
|
||||
|
||||
/// <summary>
|
||||
/// Lock used for accesing any group.
|
||||
@@ -113,14 +113,22 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
private void OnSessionManagerSessionEnded(object sender, SessionEventArgs e)
|
||||
{
|
||||
var session = e.SessionInfo;
|
||||
if (!IsSessionInGroup(session)) return;
|
||||
if (!IsSessionInGroup(session))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LeaveGroup(session, CancellationToken.None);
|
||||
}
|
||||
|
||||
private void OnSessionManagerPlaybackStopped(object sender, PlaybackStopEventArgs e)
|
||||
{
|
||||
var session = e.Session;
|
||||
if (!IsSessionInGroup(session)) return;
|
||||
if (!IsSessionInGroup(session))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LeaveGroup(session, CancellationToken.None);
|
||||
}
|
||||
|
||||
@@ -193,14 +201,14 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
}
|
||||
|
||||
var group = new SyncPlayController(_sessionManager, this);
|
||||
_groups[group.GetGroupId().ToString()] = group;
|
||||
_groups[group.GetGroupId()] = group;
|
||||
|
||||
group.InitGroup(session, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void JoinGroup(SessionInfo session, string groupId, JoinGroupRequest request, CancellationToken cancellationToken)
|
||||
public void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = _userManager.GetUserById(session.UserId);
|
||||
|
||||
@@ -248,7 +256,11 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
|
||||
if (IsSessionInGroup(session))
|
||||
{
|
||||
if (GetSessionGroup(session).Equals(groupId)) return;
|
||||
if (GetSessionGroup(session).Equals(groupId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LeaveGroup(session, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -282,7 +294,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
if (group.IsGroupEmpty())
|
||||
{
|
||||
_logger.LogInformation("LeaveGroup: removing empty group {0}.", group.GetGroupId());
|
||||
_groups.Remove(group.GetGroupId().ToString(), out _);
|
||||
_groups.Remove(group.GetGroupId(), out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user