Fix code issues
This commit is contained in:
parent
e4838b0faa
commit
e42bfc92f3
|
@ -223,7 +223,7 @@ namespace Emby.Server.Implementations.HttpServer
|
||||||
|
|
||||||
if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))
|
if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
SendKeepAliveResponse();
|
await SendKeepAliveResponse();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -231,10 +231,10 @@ namespace Emby.Server.Implementations.HttpServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendKeepAliveResponse()
|
private Task SendKeepAliveResponse()
|
||||||
{
|
{
|
||||||
LastKeepAliveDate = DateTime.UtcNow;
|
LastKeepAliveDate = DateTime.UtcNow;
|
||||||
SendAsync(new WebSocketMessage<string>
|
return SendAsync(new WebSocketMessage<string>
|
||||||
{
|
{
|
||||||
MessageType = "KeepAlive"
|
MessageType = "KeepAlive"
|
||||||
}, CancellationToken.None);
|
}, CancellationToken.None);
|
||||||
|
|
|
@ -87,13 +87,13 @@ namespace Emby.Server.Implementations.Session
|
||||||
httpServer.WebSocketConnected += OnServerManagerWebSocketConnected;
|
httpServer.WebSocketConnected += OnServerManagerWebSocketConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnServerManagerWebSocketConnected(object sender, GenericEventArgs<IWebSocketConnection> e)
|
private async void OnServerManagerWebSocketConnected(object sender, GenericEventArgs<IWebSocketConnection> e)
|
||||||
{
|
{
|
||||||
var session = GetSession(e.Argument.QueryString, e.Argument.RemoteEndPoint.ToString());
|
var session = GetSession(e.Argument.QueryString, e.Argument.RemoteEndPoint.ToString());
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
EnsureController(session, e.Argument);
|
EnsureController(session, e.Argument);
|
||||||
KeepAliveWebSocket(e.Argument);
|
await KeepAliveWebSocket(e.Argument);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -158,7 +158,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
/// Adds a WebSocket to the KeepAlive watchlist.
|
/// Adds a WebSocket to the KeepAlive watchlist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webSocket">The WebSocket to monitor.</param>
|
/// <param name="webSocket">The WebSocket to monitor.</param>
|
||||||
private void KeepAliveWebSocket(IWebSocketConnection webSocket)
|
private async Task KeepAliveWebSocket(IWebSocketConnection webSocket)
|
||||||
{
|
{
|
||||||
lock (_webSocketsLock)
|
lock (_webSocketsLock)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
// Notify WebSocket about timeout
|
// Notify WebSocket about timeout
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SendForceKeepAlive(webSocket).Wait();
|
await SendForceKeepAlive(webSocket);
|
||||||
}
|
}
|
||||||
catch (WebSocketException exception)
|
catch (WebSocketException exception)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Class is not thread-safe, external locking is required when accessing methods.
|
/// Class is not thread-safe, external locking is required when accessing methods.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class SyncPlayController : ISyncPlayController, IDisposable
|
public class SyncPlayController : ISyncPlayController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to filter the sessions of a group.
|
/// Used to filter the sessions of a group.
|
||||||
|
@ -65,8 +65,6 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsGroupEmpty() => _group.IsEmpty();
|
public bool IsGroupEmpty() => _group.IsEmpty();
|
||||||
|
|
||||||
private bool _disposed = false;
|
|
||||||
|
|
||||||
public SyncPlayController(
|
public SyncPlayController(
|
||||||
ISessionManager sessionManager,
|
ISessionManager sessionManager,
|
||||||
ISyncPlayManager syncPlayManager)
|
ISyncPlayManager syncPlayManager)
|
||||||
|
@ -75,36 +73,6 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
_syncPlayManager = syncPlayManager;
|
_syncPlayManager = syncPlayManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Releases unmanaged and optionally managed resources.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (_disposed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_disposed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: use this somewhere
|
|
||||||
private void CheckDisposed()
|
|
||||||
{
|
|
||||||
if (_disposed)
|
|
||||||
{
|
|
||||||
throw new ObjectDisposedException(GetType().Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts DateTime to UTC string.
|
/// Converts DateTime to UTC string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -518,6 +486,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
var runTimeTicks = _group.PlayingItem.RunTimeTicks ?? 0;
|
var runTimeTicks = _group.PlayingItem.RunTimeTicks ?? 0;
|
||||||
ticks = ticks > runTimeTicks ? runTimeTicks : ticks;
|
ticks = ticks > runTimeTicks ? runTimeTicks : ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ticks;
|
return ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +510,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
PlayingItemName = _group.PlayingItem.Name,
|
PlayingItemName = _group.PlayingItem.Name,
|
||||||
PlayingItemId = _group.PlayingItem.Id.ToString(),
|
PlayingItemId = _group.PlayingItem.Id.ToString(),
|
||||||
PositionTicks = _group.PositionTicks,
|
PositionTicks = _group.PositionTicks,
|
||||||
Participants = _group.Participants.Values.Select(session => session.Session.UserName).Distinct().ToList().AsReadOnly()
|
Participants = _group.Participants.Values.Select(session => session.Session.UserName).Distinct().ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,6 +374,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Session in other group already!");
|
throw new InvalidOperationException("Session in other group already!");
|
||||||
}
|
}
|
||||||
|
|
||||||
_sessionToGroupMap[session.Id] = group;
|
_sessionToGroupMap[session.Id] = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ namespace MediaBrowser.Api.SyncPlay
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both null and empty strings mean that client isn't playing anything
|
// Both null and empty strings mean that client isn't playing anything
|
||||||
if (!String.IsNullOrEmpty(request.PlayingItemId) && !Guid.TryParse(request.PlayingItemId, out playingItemId))
|
if (!string.IsNullOrEmpty(request.PlayingItemId) && !Guid.TryParse(request.PlayingItemId, out playingItemId))
|
||||||
{
|
{
|
||||||
Logger.LogError("JoinGroup: {0} is not a valid format for PlayingItemId. Ignoring request.", request.PlayingItemId);
|
Logger.LogError("JoinGroup: {0} is not a valid format for PlayingItemId. Ignoring request.", request.PlayingItemId);
|
||||||
return;
|
return;
|
||||||
|
@ -217,7 +217,7 @@ namespace MediaBrowser.Api.SyncPlay
|
||||||
var currentSession = GetSession(_sessionContext);
|
var currentSession = GetSession(_sessionContext);
|
||||||
var filterItemId = Guid.Empty;
|
var filterItemId = Guid.Empty;
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(request.FilterItemId) && !Guid.TryParse(request.FilterItemId, out filterItemId))
|
if (!string.IsNullOrEmpty(request.FilterItemId) && !Guid.TryParse(request.FilterItemId, out filterItemId))
|
||||||
{
|
{
|
||||||
Logger.LogWarning("ListGroups: {0} is not a valid format for FilterItemId. Ignoring filter.", request.FilterItemId);
|
Logger.LogWarning("ListGroups: {0} is not a valid format for FilterItemId. Ignoring filter.", request.FilterItemId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@ namespace MediaBrowser.Controller.SyncPlay
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default ping value used for sessions.
|
/// Default ping value used for sessions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly long DefaulPing = 500;
|
public long DefaulPing { get; } = 500;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the group identifier.
|
/// Gets or sets the group identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The group identifier.</value>
|
/// <value>The group identifier.</value>
|
||||||
public readonly Guid GroupId = Guid.NewGuid();
|
public Guid GroupId { get; } = Guid.NewGuid();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the playing item.
|
/// Gets or sets the playing item.
|
||||||
|
@ -51,7 +52,7 @@ namespace MediaBrowser.Controller.SyncPlay
|
||||||
/// Gets the participants.
|
/// Gets the participants.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The participants, or members of the group.</value>
|
/// <value>The participants, or members of the group.</value>
|
||||||
public readonly Dictionary<string, GroupMember> Participants =
|
public Dictionary<string, GroupMember> Participants { get; } =
|
||||||
new Dictionary<string, GroupMember>(StringComparer.OrdinalIgnoreCase);
|
new Dictionary<string, GroupMember>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -85,7 +86,6 @@ namespace MediaBrowser.Controller.SyncPlay
|
||||||
/// Removes the session from the group.
|
/// Removes the session from the group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
|
|
||||||
public void RemoveSession(SessionInfo session)
|
public void RemoveSession(SessionInfo session)
|
||||||
{
|
{
|
||||||
if (!ContainsSession(session.Id.ToString()))
|
if (!ContainsSession(session.Id.ToString()))
|
||||||
|
@ -153,6 +153,7 @@ namespace MediaBrowser.Controller.SyncPlay
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user