Use IEventManager in SessionManager

This commit is contained in:
Patrick Barron 2020-08-15 15:55:31 -04:00
parent 816c80525a
commit adabb4b842

View File

@ -18,6 +18,8 @@ using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Events.Session;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Security;
@ -40,25 +42,16 @@ namespace Emby.Server.Implementations.Session
/// </summary> /// </summary>
public class SessionManager : ISessionManager, IDisposable public class SessionManager : ISessionManager, IDisposable
{ {
/// <summary>
/// The user data repository.
/// </summary>
private readonly IUserDataManager _userDataManager; private readonly IUserDataManager _userDataManager;
/// <summary>
/// The logger.
/// </summary>
private readonly ILogger<SessionManager> _logger; private readonly ILogger<SessionManager> _logger;
private readonly IEventManager _eventManager;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IMusicManager _musicManager; private readonly IMusicManager _musicManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IImageProcessor _imageProcessor; private readonly IImageProcessor _imageProcessor;
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
private readonly IAuthenticationRepository _authRepo; private readonly IAuthenticationRepository _authRepo;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
@ -75,6 +68,7 @@ namespace Emby.Server.Implementations.Session
public SessionManager( public SessionManager(
ILogger<SessionManager> logger, ILogger<SessionManager> logger,
IEventManager eventManager,
IUserDataManager userDataManager, IUserDataManager userDataManager,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IUserManager userManager, IUserManager userManager,
@ -87,6 +81,7 @@ namespace Emby.Server.Implementations.Session
IMediaSourceManager mediaSourceManager) IMediaSourceManager mediaSourceManager)
{ {
_logger = logger; _logger = logger;
_eventManager = eventManager;
_userDataManager = userDataManager; _userDataManager = userDataManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_userManager = userManager; _userManager = userManager;
@ -209,6 +204,8 @@ namespace Emby.Server.Implementations.Session
} }
} }
_eventManager.Publish(new SessionStartedEventArgs(info));
EventHelper.QueueEventIfNotNull( EventHelper.QueueEventIfNotNull(
SessionStarted, SessionStarted,
this, this,
@ -230,6 +227,8 @@ namespace Emby.Server.Implementations.Session
}, },
_logger); _logger);
_eventManager.Publish(new SessionEndedEventArgs(info));
info.Dispose(); info.Dispose();
} }
@ -667,12 +666,7 @@ namespace Emby.Server.Implementations.Session
} }
} }
// Nothing to save here var eventArgs = new PlaybackProgressEventArgs
// Fire events to inform plugins
EventHelper.QueueEventIfNotNull(
PlaybackStart,
this,
new PlaybackProgressEventArgs
{ {
Item = libraryItem, Item = libraryItem,
Users = users, Users = users,
@ -682,7 +676,16 @@ namespace Emby.Server.Implementations.Session
ClientName = session.Client, ClientName = session.Client,
DeviceId = session.DeviceId, DeviceId = session.DeviceId,
Session = session Session = session
}, };
await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
// Nothing to save here
// Fire events to inform plugins
EventHelper.QueueEventIfNotNull(
PlaybackStart,
this,
eventArgs,
_logger); _logger);
StartIdleCheckTimer(); StartIdleCheckTimer();
@ -750,9 +753,7 @@ namespace Emby.Server.Implementations.Session
} }
} }
PlaybackProgress?.Invoke( var eventArgs = new PlaybackProgressEventArgs
this,
new PlaybackProgressEventArgs
{ {
Item = libraryItem, Item = libraryItem,
Users = users, Users = users,
@ -766,7 +767,11 @@ namespace Emby.Server.Implementations.Session
PlaySessionId = info.PlaySessionId, PlaySessionId = info.PlaySessionId,
IsAutomated = isAutomated, IsAutomated = isAutomated,
Session = session Session = session
}); };
await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
PlaybackProgress?.Invoke(this, eventArgs);
if (!isAutomated) if (!isAutomated)
{ {
@ -943,10 +948,7 @@ namespace Emby.Server.Implementations.Session
} }
} }
EventHelper.QueueEventIfNotNull( var eventArgs = new PlaybackStopEventArgs
PlaybackStopped,
this,
new PlaybackStopEventArgs
{ {
Item = libraryItem, Item = libraryItem,
Users = users, Users = users,
@ -958,8 +960,11 @@ namespace Emby.Server.Implementations.Session
ClientName = session.Client, ClientName = session.Client,
DeviceId = session.DeviceId, DeviceId = session.DeviceId,
Session = session Session = session
}, };
_logger);
await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, eventArgs, _logger);
} }
private bool OnPlaybackStopped(User user, BaseItem item, long? positionTicks, bool playbackFailed) private bool OnPlaybackStopped(User user, BaseItem item, long? positionTicks, bool playbackFailed)