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,22 +666,26 @@ namespace Emby.Server.Implementations.Session
} }
} }
var eventArgs = new PlaybackProgressEventArgs
{
Item = libraryItem,
Users = users,
MediaSourceId = info.MediaSourceId,
MediaInfo = info.Item,
DeviceName = session.DeviceName,
ClientName = session.Client,
DeviceId = session.DeviceId,
Session = session
};
await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
// Nothing to save here // Nothing to save here
// Fire events to inform plugins // Fire events to inform plugins
EventHelper.QueueEventIfNotNull( EventHelper.QueueEventIfNotNull(
PlaybackStart, PlaybackStart,
this, this,
new PlaybackProgressEventArgs eventArgs,
{
Item = libraryItem,
Users = users,
MediaSourceId = info.MediaSourceId,
MediaInfo = info.Item,
DeviceName = session.DeviceName,
ClientName = session.Client,
DeviceId = session.DeviceId,
Session = session
},
_logger); _logger);
StartIdleCheckTimer(); StartIdleCheckTimer();
@ -750,23 +753,25 @@ namespace Emby.Server.Implementations.Session
} }
} }
PlaybackProgress?.Invoke( var eventArgs = new PlaybackProgressEventArgs
this, {
new PlaybackProgressEventArgs Item = libraryItem,
{ Users = users,
Item = libraryItem, PlaybackPositionTicks = session.PlayState.PositionTicks,
Users = users, MediaSourceId = session.PlayState.MediaSourceId,
PlaybackPositionTicks = session.PlayState.PositionTicks, MediaInfo = info.Item,
MediaSourceId = session.PlayState.MediaSourceId, DeviceName = session.DeviceName,
MediaInfo = info.Item, ClientName = session.Client,
DeviceName = session.DeviceName, DeviceId = session.DeviceId,
ClientName = session.Client, IsPaused = info.IsPaused,
DeviceId = session.DeviceId, PlaySessionId = info.PlaySessionId,
IsPaused = info.IsPaused, IsAutomated = isAutomated,
PlaySessionId = info.PlaySessionId, Session = session
IsAutomated = isAutomated, };
Session = session
}); await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
PlaybackProgress?.Invoke(this, eventArgs);
if (!isAutomated) if (!isAutomated)
{ {
@ -943,23 +948,23 @@ namespace Emby.Server.Implementations.Session
} }
} }
EventHelper.QueueEventIfNotNull( var eventArgs = new PlaybackStopEventArgs
PlaybackStopped, {
this, Item = libraryItem,
new PlaybackStopEventArgs Users = users,
{ PlaybackPositionTicks = info.PositionTicks,
Item = libraryItem, PlayedToCompletion = playedToCompletion,
Users = users, MediaSourceId = info.MediaSourceId,
PlaybackPositionTicks = info.PositionTicks, MediaInfo = info.Item,
PlayedToCompletion = playedToCompletion, DeviceName = session.DeviceName,
MediaSourceId = info.MediaSourceId, ClientName = session.Client,
MediaInfo = info.Item, DeviceId = session.DeviceId,
DeviceName = session.DeviceName, Session = session
ClientName = session.Client, };
DeviceId = session.DeviceId,
Session = session await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false);
},
_logger); 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)