diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs
index 1f273a3ee0..4082f56008 100644
--- a/MediaBrowser.Controller/Session/ISessionManager.cs
+++ b/MediaBrowser.Controller/Session/ISessionManager.cs
@@ -180,6 +180,18 @@ namespace MediaBrowser.Controller.Session
/// The cancellation token.
/// Task.
Task SendMessageToUserSessions(string userId, string name, T data, CancellationToken cancellationToken);
+
+ ///
+ /// Sends the message to user device sessions.
+ ///
+ ///
+ /// The device identifier.
+ /// The name.
+ /// The data.
+ /// The cancellation token.
+ /// Task.
+ Task SendMessageToUserDeviceSessions(string deviceId, string name, T data,
+ CancellationToken cancellationToken);
///
/// Sends the restart required message.
diff --git a/MediaBrowser.Controller/Sync/ISyncManager.cs b/MediaBrowser.Controller/Sync/ISyncManager.cs
index 9edc708ee0..dedde2d9e1 100644
--- a/MediaBrowser.Controller/Sync/ISyncManager.cs
+++ b/MediaBrowser.Controller/Sync/ISyncManager.cs
@@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Sync
{
public interface ISyncManager
{
- event EventHandler> SyncJobCreated;
+ event EventHandler> SyncJobCreated;
event EventHandler> SyncJobCancelled;
///
diff --git a/MediaBrowser.Model/ApiClient/IServerEvents.cs b/MediaBrowser.Model/ApiClient/IServerEvents.cs
index 88faad3884..b74d43ee0e 100644
--- a/MediaBrowser.Model/ApiClient/IServerEvents.cs
+++ b/MediaBrowser.Model/ApiClient/IServerEvents.cs
@@ -3,6 +3,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Session;
+using MediaBrowser.Model.Sync;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
using System;
@@ -130,5 +131,9 @@ namespace MediaBrowser.Model.ApiClient
/// Occurs when [session ended].
///
event EventHandler> SessionEnded;
+ ///
+ /// Occurs when [synchronize job created].
+ ///
+ event EventHandler> SyncJobCreated;
}
}
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs
index bc10253058..51e6ddc0ec 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs
@@ -7,7 +7,9 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
+using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Events;
+using MediaBrowser.Model.Sync;
using System;
using System.Threading;
@@ -44,8 +46,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly ITaskManager _taskManager;
private readonly ISessionManager _sessionManager;
+ private readonly ISyncManager _syncManager;
- public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager)
+ public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager, ISyncManager syncManager)
{
_serverManager = serverManager;
_userManager = userManager;
@@ -53,6 +56,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_appHost = appHost;
_taskManager = taskManager;
_sessionManager = sessionManager;
+ _syncManager = syncManager;
}
public void Run()
@@ -70,6 +74,12 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
+ _syncManager.SyncJobCreated += _syncManager_SyncJobCreated;
+ }
+
+ void _syncManager_SyncJobCreated(object sender, GenericEventArgs e)
+ {
+ _sessionManager.SendMessageToUserDeviceSessions(e.Argument.Job.TargetId, "SyncJobCreated", e.Argument, CancellationToken.None);
}
void _installationManager_PackageInstalling(object sender, InstallationEventArgs e)
@@ -178,6 +188,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
+ _syncManager.SyncJobCreated -= _syncManager_SyncJobCreated;
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
index f1616b85e8..4bce7db9f1 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
@@ -2,7 +2,6 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
@@ -11,7 +10,6 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
-using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Session;
@@ -1639,7 +1637,28 @@ namespace MediaBrowser.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error in SendPlaybackStoppedNotification.", ex);
+ _logger.ErrorException("Error sending message", ex);
+ }
+
+ }, cancellationToken));
+
+ return Task.WhenAll(tasks);
+ }
+
+ public Task SendMessageToUserDeviceSessions(string deviceId, string name, T data,
+ CancellationToken cancellationToken)
+ {
+ var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null && string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)).ToList();
+
+ var tasks = sessions.Select(session => Task.Run(async () =>
+ {
+ try
+ {
+ await session.SessionController.SendMessage(name, data, cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error sending message", ex);
}
}, cancellationToken));
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
index 71bc0e46b5..5ead8f02b4 100644
--- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
+++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
@@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Implementations.Sync
private ISyncProvider[] _providers = { };
- public event EventHandler> SyncJobCreated;
+ public event EventHandler> SyncJobCreated;
public event EventHandler> SyncJobCancelled;
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func mediaEncoder, IFileSystem fileSystem, Func subtitleEncoder, IConfigurationManager config)
@@ -103,14 +103,14 @@ namespace MediaBrowser.Server.Implementations.Sync
var target = GetSyncTargets(request.UserId)
.FirstOrDefault(i => string.Equals(request.TargetId, i.Id));
-
+
if (target == null)
{
throw new ArgumentException("Sync target not found.");
}
var jobId = Guid.NewGuid().ToString("N");
-
+
var job = new SyncJob
{
Id = jobId,
@@ -149,26 +149,28 @@ namespace MediaBrowser.Server.Implementations.Sync
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress(), CancellationToken.None)
.ConfigureAwait(false);
- if (SyncJobCreated != null)
- {
- EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs
- {
- Argument = job
-
- }, _logger);
- }
-
jobItemsResult = _repo.GetJobItems(new SyncJobItemQuery
{
Statuses = new List { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting },
JobId = jobId
});
- return new SyncJobCreationResult
+ var returnResult = new SyncJobCreationResult
{
Job = GetJob(jobId),
JobItems = jobItemsResult.Items.ToList()
};
+
+ if (SyncJobCreated != null)
+ {
+ EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs
+ {
+ Argument = returnResult
+
+ }, _logger);
+ }
+
+ return returnResult;
}
public Task UpdateJob(SyncJob job)