2019-01-13 13:01:16 -07:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 12:24:58 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-12-26 12:34:39 -07:00
|
|
|
using MediaBrowser.Controller.Net;
|
2013-05-30 20:38:46 -07:00
|
|
|
using MediaBrowser.Controller.Session;
|
2018-12-13 06:18:25 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-05-30 20:38:46 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
namespace MediaBrowser.Api.Session
|
2013-05-30 20:38:46 -07:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class SessionInfoWebSocketListener
|
|
|
|
/// </summary>
|
2019-02-15 15:05:14 -07:00
|
|
|
public class SessionInfoWebSocketListener : BasePeriodicWebSocketListener<IEnumerable<SessionInfo>, WebSocketListenerState>
|
2013-05-30 20:38:46 -07:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the name.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The name.</value>
|
2019-01-13 13:31:14 -07:00
|
|
|
protected override string Name => "Sessions";
|
2013-05-30 20:38:46 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The _kernel
|
|
|
|
/// </summary>
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SessionInfoWebSocketListener"/> class.
|
|
|
|
/// </summary>
|
2018-09-12 10:26:21 -07:00
|
|
|
public SessionInfoWebSocketListener(ILogger logger, ISessionManager sessionManager)
|
|
|
|
: base(logger)
|
2013-05-30 20:38:46 -07:00
|
|
|
{
|
|
|
|
_sessionManager = sessionManager;
|
2014-05-13 17:46:45 -07:00
|
|
|
|
|
|
|
_sessionManager.SessionStarted += _sessionManager_SessionStarted;
|
|
|
|
_sessionManager.SessionEnded += _sessionManager_SessionEnded;
|
|
|
|
_sessionManager.PlaybackStart += _sessionManager_PlaybackStart;
|
|
|
|
_sessionManager.PlaybackStopped += _sessionManager_PlaybackStopped;
|
|
|
|
_sessionManager.PlaybackProgress += _sessionManager_PlaybackProgress;
|
|
|
|
_sessionManager.CapabilitiesChanged += _sessionManager_CapabilitiesChanged;
|
|
|
|
_sessionManager.SessionActivity += _sessionManager_SessionActivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_SessionActivity(object sender, SessionEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_CapabilitiesChanged(object sender, SessionEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e)
|
|
|
|
{
|
2017-04-25 11:23:38 -07:00
|
|
|
SendData(!e.IsAutomated);
|
2014-05-13 17:46:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_PlaybackStopped(object sender, PlaybackStopEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_SessionEnded(object sender, SessionEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sessionManager_SessionStarted(object sender, SessionEventArgs e)
|
|
|
|
{
|
|
|
|
SendData(true);
|
2013-05-30 20:38:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the data to send.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
/// <returns>Task{SystemInfo}.</returns>
|
2018-09-12 10:26:21 -07:00
|
|
|
protected override Task<IEnumerable<SessionInfo>> GetDataToSend(WebSocketListenerState state, CancellationToken cancellationToken)
|
2013-05-30 20:38:46 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
return Task.FromResult(_sessionManager.Sessions);
|
2014-05-13 17:46:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool dispose)
|
|
|
|
{
|
|
|
|
_sessionManager.SessionStarted -= _sessionManager_SessionStarted;
|
|
|
|
_sessionManager.SessionEnded -= _sessionManager_SessionEnded;
|
|
|
|
_sessionManager.PlaybackStart -= _sessionManager_PlaybackStart;
|
|
|
|
_sessionManager.PlaybackStopped -= _sessionManager_PlaybackStopped;
|
|
|
|
_sessionManager.PlaybackProgress -= _sessionManager_PlaybackProgress;
|
|
|
|
_sessionManager.CapabilitiesChanged -= _sessionManager_CapabilitiesChanged;
|
|
|
|
_sessionManager.SessionActivity -= _sessionManager_SessionActivity;
|
|
|
|
|
|
|
|
base.Dispose(dispose);
|
|
|
|
}
|
2013-05-30 20:38:46 -07:00
|
|
|
}
|
|
|
|
}
|