aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Session
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-03 14:02:23 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-03 14:02:23 -0400
commit16b9d26ab5e52c3c72dd24f17587ca4775ff79dd (patch)
tree4b6ef5582845768caf54144f3372ed603da90b1f /MediaBrowser.Server.Implementations/Session
parentd021e20249c85ab96783e1347d95f826a816ff9b (diff)
fixes #273 - Marking/unmarking Favorite status doesn't cause a library changed notification
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session')
-rw-r--r--MediaBrowser.Server.Implementations/Session/SessionManager.cs62
-rw-r--r--MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs13
-rw-r--r--MediaBrowser.Server.Implementations/Session/WebSocketController.cs55
3 files changed, 123 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
index ac69b0dc5..6bb6edf7a 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
@@ -290,6 +290,7 @@ namespace MediaBrowser.Server.Implementations.Session
var data = _userDataRepository.GetUserData(user.Id, key);
UpdatePlayState(info.Item, data, info.PositionTicks.Value);
+
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
}
@@ -501,7 +502,62 @@ namespace MediaBrowser.Server.Implementations.Session
return session.SessionController.SendPlaystateCommand(command, cancellationToken);
}
- public Task SendRestartRequiredMessage(CancellationToken cancellationToken)
+ /// <summary>
+ /// Sends the restart required message.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendRestartRequiredNotification(CancellationToken cancellationToken)
+ {
+ var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
+
+ var tasks = sessions.Select(session => Task.Run(async () =>
+ {
+ try
+ {
+ await session.SessionController.SendRestartRequiredNotification(cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error in SendRestartRequiredNotification.", ex);
+ }
+
+ }));
+
+ return Task.WhenAll(tasks);
+ }
+
+ /// <summary>
+ /// Sends the server shutdown notification.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendServerShutdownNotification(CancellationToken cancellationToken)
+ {
+ var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
+
+ var tasks = sessions.Select(session => Task.Run(async () =>
+ {
+ try
+ {
+ await session.SessionController.SendServerShutdownNotification(cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error in SendServerShutdownNotification.", ex);
+ }
+
+ }));
+
+ return Task.WhenAll(tasks);
+ }
+
+ /// <summary>
+ /// Sends the server restart notification.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendServerRestartNotification(CancellationToken cancellationToken)
{
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
@@ -509,11 +565,11 @@ namespace MediaBrowser.Server.Implementations.Session
{
try
{
- await session.SessionController.SendRestartRequiredMessage(cancellationToken).ConfigureAwait(false);
+ await session.SessionController.SendServerRestartNotification(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
- _logger.ErrorException("Error in SendRestartRequiredMessage.", ex);
+ _logger.ErrorException("Error in SendServerRestartNotification.", ex);
}
}));
diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
index e90dd8eb9..399cce945 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -84,15 +84,22 @@ namespace MediaBrowser.Server.Implementations.Session
/// Processes the identity message.
/// </summary>
/// <param name="message">The message.</param>
- private void ProcessIdentityMessage(WebSocketMessageInfo message)
+ private async void ProcessIdentityMessage(WebSocketMessageInfo message)
{
- _logger.Debug("Received Identity message");
+ _logger.Debug("Received Identity message: " + message.Data);
var vals = message.Data.Split('|');
var client = vals[0];
var deviceId = vals[1];
var version = vals[2];
+ var deviceName = vals.Length > 3 ? vals[3] : string.Empty;
+
+ if (!string.IsNullOrEmpty(deviceName))
+ {
+ _logger.Debug("Logging session activity");
+ await _sessionManager.LogSessionActivity(client, version, deviceId, deviceName, null).ConfigureAwait(false);
+ }
var session = _sessionManager.Sessions
.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId) &&
@@ -156,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.Session
if (result == null)
{
- _logger.Error("Unable to session based on web socket message");
+ _logger.Error("Unable to find session based on web socket message");
}
return result;
diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
index 46c8f752d..6bbebf156 100644
--- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
+++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
@@ -134,7 +134,7 @@ namespace MediaBrowser.Server.Implementations.Session
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- public Task SendRestartRequiredMessage(CancellationToken cancellationToken)
+ public Task SendRestartRequiredNotification(CancellationToken cancellationToken)
{
var socket = GetActiveSocket();
@@ -145,5 +145,58 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
+
+
+ /// <summary>
+ /// Sends the user data change info.
+ /// </summary>
+ /// <param name="info">The info.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendUserDataChangeInfo(UserDataChangeInfo info, CancellationToken cancellationToken)
+ {
+ var socket = GetActiveSocket();
+
+ return socket.SendAsync(new WebSocketMessage<UserDataChangeInfo>
+ {
+ MessageType = "UserDataChanged",
+ Data = info
+
+ }, cancellationToken);
+ }
+
+ /// <summary>
+ /// Sends the server shutdown notification.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendServerShutdownNotification(CancellationToken cancellationToken)
+ {
+ var socket = GetActiveSocket();
+
+ return socket.SendAsync(new WebSocketMessage<string>
+ {
+ MessageType = "ServerShuttingDown",
+ Data = string.Empty
+
+ }, cancellationToken);
+ }
+
+ /// <summary>
+ /// Sends the server restart notification.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendServerRestartNotification(CancellationToken cancellationToken)
+ {
+ var socket = GetActiveSocket();
+
+ return socket.SendAsync(new WebSocketMessage<string>
+ {
+ MessageType = "ServerRestarting",
+ Data = string.Empty
+
+ }, cancellationToken);
+ }
}
}