Fix code issues

This commit is contained in:
gion
2020-05-26 11:37:52 +02:00
parent e4838b0faa
commit e42bfc92f3
6 changed files with 19 additions and 48 deletions

View File

@@ -223,7 +223,7 @@ namespace Emby.Server.Implementations.HttpServer
if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))
{
SendKeepAliveResponse();
await SendKeepAliveResponse();
}
else
{
@@ -231,10 +231,10 @@ namespace Emby.Server.Implementations.HttpServer
}
}
private void SendKeepAliveResponse()
private Task SendKeepAliveResponse()
{
LastKeepAliveDate = DateTime.UtcNow;
SendAsync(new WebSocketMessage<string>
return SendAsync(new WebSocketMessage<string>
{
MessageType = "KeepAlive"
}, CancellationToken.None);

View File

@@ -87,13 +87,13 @@ namespace Emby.Server.Implementations.Session
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());
if (session != null)
{
EnsureController(session, e.Argument);
KeepAliveWebSocket(e.Argument);
await KeepAliveWebSocket(e.Argument);
}
else
{
@@ -149,7 +149,7 @@ namespace Emby.Server.Implementations.Session
/// <param name="e">The event arguments.</param>
private void OnWebSocketClosed(object sender, EventArgs e)
{
var webSocket = (IWebSocketConnection) sender;
var webSocket = (IWebSocketConnection)sender;
_logger.LogDebug("WebSocket {0} is closed.", webSocket);
RemoveWebSocket(webSocket);
}
@@ -158,7 +158,7 @@ namespace Emby.Server.Implementations.Session
/// Adds a WebSocket to the KeepAlive watchlist.
/// </summary>
/// <param name="webSocket">The WebSocket to monitor.</param>
private void KeepAliveWebSocket(IWebSocketConnection webSocket)
private async Task KeepAliveWebSocket(IWebSocketConnection webSocket)
{
lock (_webSocketsLock)
{
@@ -176,7 +176,7 @@ namespace Emby.Server.Implementations.Session
// Notify WebSocket about timeout
try
{
SendForceKeepAlive(webSocket).Wait();
await SendForceKeepAlive(webSocket);
}
catch (WebSocketException exception)
{

View File

@@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// <remarks>
/// Class is not thread-safe, external locking is required when accessing methods.
/// </remarks>
public class SyncPlayController : ISyncPlayController, IDisposable
public class SyncPlayController : ISyncPlayController
{
/// <summary>
/// Used to filter the sessions of a group.
@@ -65,8 +65,6 @@ namespace Emby.Server.Implementations.SyncPlay
/// <inheritdoc />
public bool IsGroupEmpty() => _group.IsEmpty();
private bool _disposed = false;
public SyncPlayController(
ISessionManager sessionManager,
ISyncPlayManager syncPlayManager)
@@ -75,36 +73,6 @@ namespace Emby.Server.Implementations.SyncPlay
_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>
/// Converts DateTime to UTC string.
/// </summary>
@@ -518,6 +486,7 @@ namespace Emby.Server.Implementations.SyncPlay
var runTimeTicks = _group.PlayingItem.RunTimeTicks ?? 0;
ticks = ticks > runTimeTicks ? runTimeTicks : ticks;
}
return ticks;
}
@@ -541,7 +510,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().ToList().AsReadOnly()
Participants = _group.Participants.Values.Select(session => session.Session.UserName).Distinct().ToList()
};
}
}

View File

@@ -374,6 +374,7 @@ namespace Emby.Server.Implementations.SyncPlay
{
throw new InvalidOperationException("Session in other group already!");
}
_sessionToGroupMap[session.Id] = group;
}