aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgion <oancaionutandrei@gmail.com>2020-05-26 11:37:52 +0200
committergion <oancaionutandrei@gmail.com>2020-05-26 11:37:52 +0200
commite42bfc92f3e072a3d51dddce06bc90587e06791c (patch)
treeb436044e5886e310f8f5f1e466af13c042c90fda
parente4838b0faa2dafec9382abe8e00bd18be624a030 (diff)
Fix code issues
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketConnection.cs6
-rw-r--r--Emby.Server.Implementations/Session/SessionWebSocketListener.cs10
-rw-r--r--Emby.Server.Implementations/SyncPlay/SyncPlayController.cs37
-rw-r--r--Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs1
-rw-r--r--MediaBrowser.Api/SyncPlay/SyncPlayService.cs4
-rw-r--r--MediaBrowser.Controller/SyncPlay/GroupInfo.cs9
6 files changed, 19 insertions, 48 deletions
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
index 1f5a7d177..0680c5ffe 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
@@ -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);
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index 3af18f681..e7b4b0ec3 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -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)
{
diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayController.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayController.cs
index c7bd242a7..d430d4d16 100644
--- a/Emby.Server.Implementations/SyncPlay/SyncPlayController.cs
+++ b/Emby.Server.Implementations/SyncPlay/SyncPlayController.cs
@@ -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()
};
}
}
diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
index 93cec1304..1f76dd4e3 100644
--- a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
+++ b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
@@ -374,6 +374,7 @@ namespace Emby.Server.Implementations.SyncPlay
{
throw new InvalidOperationException("Session in other group already!");
}
+
_sessionToGroupMap[session.Id] = group;
}
diff --git a/MediaBrowser.Api/SyncPlay/SyncPlayService.cs b/MediaBrowser.Api/SyncPlay/SyncPlayService.cs
index 8064ea7dc..1e14ea552 100644
--- a/MediaBrowser.Api/SyncPlay/SyncPlayService.cs
+++ b/MediaBrowser.Api/SyncPlay/SyncPlayService.cs
@@ -182,7 +182,7 @@ namespace MediaBrowser.Api.SyncPlay
}
// 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);
return;
@@ -217,7 +217,7 @@ namespace MediaBrowser.Api.SyncPlay
var currentSession = GetSession(_sessionContext);
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);
}
diff --git a/MediaBrowser.Controller/SyncPlay/GroupInfo.cs b/MediaBrowser.Controller/SyncPlay/GroupInfo.cs
index bda49bd1b..28a3ac505 100644
--- a/MediaBrowser.Controller/SyncPlay/GroupInfo.cs
+++ b/MediaBrowser.Controller/SyncPlay/GroupInfo.cs
@@ -16,12 +16,13 @@ namespace MediaBrowser.Controller.SyncPlay
/// <summary>
/// Default ping value used for sessions.
/// </summary>
- public readonly long DefaulPing = 500;
+ public long DefaulPing { get; } = 500;
+
/// <summary>
/// Gets or sets the group identifier.
/// </summary>
/// <value>The group identifier.</value>
- public readonly Guid GroupId = Guid.NewGuid();
+ public Guid GroupId { get; } = Guid.NewGuid();
/// <summary>
/// Gets or sets the playing item.
@@ -51,7 +52,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// Gets the participants.
/// </summary>
/// <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);
/// <summary>
@@ -85,7 +86,6 @@ namespace MediaBrowser.Controller.SyncPlay
/// Removes the session from the group.
/// </summary>
/// <param name="session">The session.</param>
-
public void RemoveSession(SessionInfo session)
{
if (!ContainsSession(session.Id.ToString()))
@@ -153,6 +153,7 @@ namespace MediaBrowser.Controller.SyncPlay
return true;
}
}
+
return false;
}