updated nuget
This commit is contained in:
parent
33a3e215d0
commit
eb72c2db51
|
@ -62,17 +62,6 @@ namespace MediaBrowser.Common.Net
|
|||
/// <exception cref="System.ArgumentNullException">messageType</exception>
|
||||
Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the web socket message async.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="messageType">Type of the message.</param>
|
||||
/// <param name="dataFunction">The data function.</param>
|
||||
/// <param name="connections">The connections.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, IEnumerable<IWebSocketConnection> connections, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the web socket listeners.
|
||||
/// </summary>
|
||||
|
|
|
@ -7,6 +7,12 @@ namespace MediaBrowser.Common.Net
|
|||
{
|
||||
public interface IWebSocketConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last activity date.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Model.Session;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Session;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -7,55 +8,70 @@ namespace MediaBrowser.Controller.Session
|
|||
public interface ISessionController
|
||||
{
|
||||
/// <summary>
|
||||
/// Supportses the specified session.
|
||||
/// Gets a value indicating whether [supports media remote control].
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
bool Supports(SessionInfo session);
|
||||
/// <value><c>true</c> if [supports media remote control]; otherwise, <c>false</c>.</value>
|
||||
bool SupportsMediaRemoteControl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is session active.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is session active; otherwise, <c>false</c>.</value>
|
||||
bool IsSessionActive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sends the system command.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="command">The command.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendSystemCommand(SessionInfo session, SystemCommand command, CancellationToken cancellationToken);
|
||||
Task SendSystemCommand(SystemCommand command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the message command.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="command">The command.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendMessageCommand(SessionInfo session, MessageCommand command, CancellationToken cancellationToken);
|
||||
Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the play command.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="command">The command.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendPlayCommand(SessionInfo session, PlayRequest command, CancellationToken cancellationToken);
|
||||
Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the browse command.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="command">The command.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendBrowseCommand(SessionInfo session, BrowseRequest command, CancellationToken cancellationToken);
|
||||
Task SendBrowseCommand(BrowseRequest command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the playstate command.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="command">The command.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendPlaystateCommand(SessionInfo session, PlaystateRequest command, CancellationToken cancellationToken);
|
||||
Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the library update info.
|
||||
/// </summary>
|
||||
/// <param name="info">The info.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendLibraryUpdateInfo(LibraryUpdateInfo info, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the restart required message.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendRestartRequiredMessage(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,6 @@ namespace MediaBrowser.Controller.Session
|
|||
/// </summary>
|
||||
public interface ISessionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the parts.
|
||||
/// </summary>
|
||||
/// <param name="remoteControllers">The remote controllers.</param>
|
||||
void AddParts(IEnumerable<ISessionController> remoteControllers);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [playback start].
|
||||
/// </summary>
|
||||
|
@ -119,5 +113,12 @@ namespace MediaBrowser.Controller.Session
|
|||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the restart required message.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SendRestartRequiredMessage(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,6 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Session
|
||||
{
|
||||
|
@ -14,7 +11,6 @@ namespace MediaBrowser.Controller.Session
|
|||
{
|
||||
public SessionInfo()
|
||||
{
|
||||
WebSockets = new List<IWebSocketConnection>();
|
||||
QueueableMediaTypes = new List<string>();
|
||||
}
|
||||
|
||||
|
@ -114,18 +110,18 @@ namespace MediaBrowser.Controller.Session
|
|||
/// <value>The device id.</value>
|
||||
public string DeviceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the web socket.
|
||||
/// </summary>
|
||||
/// <value>The web socket.</value>
|
||||
public List<IWebSocketConnection> WebSockets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application version.
|
||||
/// </summary>
|
||||
/// <value>The application version.</value>
|
||||
public string ApplicationVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the session controller.
|
||||
/// </summary>
|
||||
/// <value>The session controller.</value>
|
||||
public ISessionController SessionController { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is active.
|
||||
/// </summary>
|
||||
|
@ -134,9 +130,9 @@ namespace MediaBrowser.Controller.Session
|
|||
{
|
||||
get
|
||||
{
|
||||
if (WebSockets.Count > 0)
|
||||
if (SessionController != null)
|
||||
{
|
||||
return WebSockets.Any(i => i.State == WebSocketState.Open);
|
||||
return SessionController.IsSessionActive;
|
||||
}
|
||||
|
||||
return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
|
||||
|
@ -151,7 +147,12 @@ namespace MediaBrowser.Controller.Session
|
|||
{
|
||||
get
|
||||
{
|
||||
return WebSockets.Any(i => i.State == WebSocketState.Open);
|
||||
if (SessionController != null)
|
||||
{
|
||||
return SessionController.SupportsMediaRemoteControl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,6 +206,24 @@ namespace MediaBrowser.Model.Querying
|
|||
/// <value>The parent index number.</value>
|
||||
public int? ParentIndexNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the min players.
|
||||
/// </summary>
|
||||
/// <value>The min players.</value>
|
||||
public int? MinPlayers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name starts with or greater.
|
||||
/// </summary>
|
||||
/// <value>The name starts with or greater.</value>
|
||||
public string NameStartsWithOrGreater { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album artist starts with or greater.
|
||||
/// </summary>
|
||||
/// <value>The album artist starts with or greater.</value>
|
||||
public string AlbumArtistStartsWithOrGreater { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ItemQuery" /> class.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
@ -21,7 +20,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
private readonly ISessionManager _sessionManager;
|
||||
private readonly IServerManager _serverManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
@ -48,11 +46,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
/// </summary>
|
||||
private const int LibraryUpdateDuration = 20000;
|
||||
|
||||
public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IServerManager serverManager, IUserManager userManager, ILogger logger)
|
||||
public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IUserManager userManager, ILogger logger)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_sessionManager = sessionManager;
|
||||
_serverManager = serverManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
@ -187,26 +184,25 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
/// <param name="foldersAddedTo">The folders added to.</param>
|
||||
/// <param name="foldersRemovedFrom">The folders removed from.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
private async void SendChangeNotifications(IEnumerable<BaseItem> itemsAdded, IEnumerable<BaseItem> itemsUpdated, IEnumerable<BaseItem> itemsRemoved, IEnumerable<Folder> foldersAddedTo, IEnumerable<Folder> foldersRemovedFrom, CancellationToken cancellationToken)
|
||||
private async void SendChangeNotifications(List<BaseItem> itemsAdded, List<BaseItem> itemsUpdated, List<BaseItem> itemsRemoved, List<Folder> foldersAddedTo, List<Folder> foldersRemovedFrom, CancellationToken cancellationToken)
|
||||
{
|
||||
var currentSessions = _sessionManager.Sessions.ToList();
|
||||
|
||||
var users = currentSessions.Select(i => i.User)
|
||||
.Where(i => i != null)
|
||||
.Select(i => i.Id)
|
||||
.Distinct()
|
||||
foreach (var user in _userManager.Users.ToList())
|
||||
{
|
||||
var id = user.Id;
|
||||
var userSessions = _sessionManager.Sessions
|
||||
.Where(u => u.User != null && u.User.Id == id && u.SessionController != null && u.IsActive)
|
||||
.ToList();
|
||||
|
||||
foreach (var userId in users)
|
||||
if (userSessions.Count > 0)
|
||||
{
|
||||
var id = userId;
|
||||
var webSockets = currentSessions.Where(u => u.User != null && u.User.Id == id)
|
||||
.SelectMany(i => i.WebSockets)
|
||||
.ToList();
|
||||
var info = GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo,
|
||||
foldersRemovedFrom, id);
|
||||
|
||||
foreach (var userSession in userSessions)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _serverManager.SendWebSocketMessageAsync("LibraryChanged", () => GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, foldersRemovedFrom, id), webSockets, cancellationToken).ConfigureAwait(false);
|
||||
await userSession.SessionController.SendLibraryUpdateInfo(info, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -215,6 +211,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the library update info.
|
||||
/// </summary>
|
||||
|
|
|
@ -8,8 +8,10 @@ using MediaBrowser.Controller.Dto;
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||
{
|
||||
|
@ -45,13 +47,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
|
||||
private readonly IDtoService _dtoService;
|
||||
|
||||
private ISessionManager _sessionManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WebSocketEvents" /> class.
|
||||
/// </summary>
|
||||
/// <param name="serverManager">The server manager.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
public WebSocketEvents(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, IDtoService dtoService)
|
||||
public WebSocketEvents(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, IDtoService dtoService, ISessionManager sessionManager)
|
||||
{
|
||||
_serverManager = serverManager;
|
||||
_userManager = userManager;
|
||||
|
@ -59,6 +63,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
_appHost = appHost;
|
||||
_taskManager = taskManager;
|
||||
_dtoService = dtoService;
|
||||
_sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
@ -126,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
|||
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
||||
void kernel_HasPendingRestartChanged(object sender, EventArgs e)
|
||||
{
|
||||
_serverManager.SendWebSocketMessage("RestartRequired", _appHost.GetSystemInfo());
|
||||
_sessionManager.SendRestartRequiredMessage(CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -273,7 +273,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
|||
/// dataFunction
|
||||
/// or
|
||||
/// cancellationToken</exception>
|
||||
public async Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, IEnumerable<IWebSocketConnection> connections, CancellationToken cancellationToken)
|
||||
private async Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, IEnumerable<IWebSocketConnection> connections, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(messageType))
|
||||
{
|
||||
|
|
|
@ -56,6 +56,12 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
|||
/// <value>The last activity date.</value>
|
||||
public DateTime LastActivityDate { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
|
||||
/// </summary>
|
||||
|
@ -83,6 +89,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
|||
throw new ArgumentNullException("logger");
|
||||
}
|
||||
|
||||
Id = Guid.NewGuid();
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_socket = socket;
|
||||
_socket.OnReceiveBytes = OnReceiveInternal;
|
||||
|
|
|
@ -78,12 +78,6 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
private List<ISessionController> _remoteControllers;
|
||||
public void AddParts(IEnumerable<ISessionController> remoteControllers)
|
||||
{
|
||||
_remoteControllers = remoteControllers.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all connections.
|
||||
/// </summary>
|
||||
|
@ -437,16 +431,6 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
return session;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the controllers.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <returns>IEnumerable{ISessionRemoteController}.</returns>
|
||||
private IEnumerable<ISessionController> GetControllers(SessionInfo session)
|
||||
{
|
||||
return _remoteControllers.Where(i => i.Supports(session));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the system command.
|
||||
/// </summary>
|
||||
|
@ -458,9 +442,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = GetSessionForRemoteControl(sessionId);
|
||||
|
||||
var tasks = GetControllers(session).Select(i => i.SendSystemCommand(session, command, cancellationToken));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
return session.SessionController.SendSystemCommand(command, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -474,9 +456,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = GetSessionForRemoteControl(sessionId);
|
||||
|
||||
var tasks = GetControllers(session).Select(i => i.SendMessageCommand(session, command, cancellationToken));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
return session.SessionController.SendMessageCommand(command, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -490,9 +470,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = GetSessionForRemoteControl(sessionId);
|
||||
|
||||
var tasks = GetControllers(session).Select(i => i.SendPlayCommand(session, command, cancellationToken));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
return session.SessionController.SendPlayCommand(command, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -506,9 +484,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = GetSessionForRemoteControl(sessionId);
|
||||
|
||||
var tasks = GetControllers(session).Select(i => i.SendBrowseCommand(session, command, cancellationToken));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
return session.SessionController.SendBrowseCommand(command, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -522,7 +498,25 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
var session = GetSessionForRemoteControl(sessionId);
|
||||
|
||||
var tasks = GetControllers(session).Select(i => i.SendPlaystateCommand(session, command, cancellationToken));
|
||||
return session.SessionController.SendPlaystateCommand(command, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendRestartRequiredMessage(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.SendRestartRequiredMessage(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error in SendRestartRequiredMessage.", ex);
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -33,6 +33,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
/// The _dto service
|
||||
/// </summary>
|
||||
private readonly IDtoService _dtoService;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SessionWebSocketListener" /> class.
|
||||
|
@ -40,11 +41,12 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
/// <param name="sessionManager">The session manager.</param>
|
||||
/// <param name="logManager">The log manager.</param>
|
||||
/// <param name="dtoService">The dto service.</param>
|
||||
public SessionWebSocketListener(ISessionManager sessionManager, ILogManager logManager, IDtoService dtoService)
|
||||
public SessionWebSocketListener(ISessionManager sessionManager, ILogManager logManager, IDtoService dtoService, IServerApplicationHost appHost)
|
||||
{
|
||||
_sessionManager = sessionManager;
|
||||
_logger = logManager.GetLogger(GetType().Name);
|
||||
_dtoService = dtoService;
|
||||
_appHost = appHost;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -55,6 +57,34 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
public Task ProcessMessage(WebSocketMessageInfo message)
|
||||
{
|
||||
if (string.Equals(message.MessageType, "Identity", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ProcessIdentityMessage(message);
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "Context", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ProcessContextMessage(message);
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ReportPlaybackStart(message);
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ReportPlaybackProgress(message);
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ReportPlaybackStopped(message);
|
||||
}
|
||||
|
||||
return _trueTaskResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the identity message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ProcessIdentityMessage(WebSocketMessageInfo message)
|
||||
{
|
||||
_logger.Debug("Received Identity message");
|
||||
|
||||
|
@ -71,19 +101,24 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
if (session != null)
|
||||
{
|
||||
var sockets = session.WebSockets.Where(i => i.State == WebSocketState.Open).ToList();
|
||||
sockets.Add(message.Connection);
|
||||
var controller = new WebSocketController(session, _appHost);
|
||||
controller.Sockets.Add(message.Connection);
|
||||
|
||||
session.WebSockets = sockets;
|
||||
session.SessionController = controller;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn("Unable to determine session based on identity message: {0}", message.Data);
|
||||
}
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "Context", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
/// <summary>
|
||||
/// Processes the context message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ProcessContextMessage(WebSocketMessageInfo message)
|
||||
{
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
var session = GetSessionFromMessage(message);
|
||||
|
||||
if (session != null)
|
||||
{
|
||||
|
@ -94,18 +129,86 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
session.NowViewingItemName = vals[2];
|
||||
session.NowViewingContext = vals.Length > 3 ? vals[3] : null;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the session from message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <returns>SessionInfo.</returns>
|
||||
private SessionInfo GetSessionFromMessage(WebSocketMessageInfo message)
|
||||
{
|
||||
_logger.Warn("Unable to determine session based on context message: {0}", message.Data);
|
||||
var result = _sessionManager.Sessions.FirstOrDefault(i =>
|
||||
{
|
||||
var controller = i.SessionController as WebSocketController;
|
||||
|
||||
if (controller != null)
|
||||
{
|
||||
if (controller.Sockets.Any(s => s.Id == message.Connection.Id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
ReportPlaybackStart(message);
|
||||
_logger.Error("Unable to session based on web socket message");
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the playback start.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ReportPlaybackStart(WebSocketMessageInfo message)
|
||||
{
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
_logger.Debug("Received PlaybackStart message");
|
||||
|
||||
var session = GetSessionFromMessage(message);
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var vals = message.Data.Split('|');
|
||||
|
||||
var item = _dtoService.GetItemByDtoId(vals[0]);
|
||||
|
||||
var queueableMediaTypes = string.Empty;
|
||||
var canSeek = true;
|
||||
|
||||
if (vals.Length > 1)
|
||||
{
|
||||
canSeek = string.Equals(vals[1], "true", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
if (vals.Length > 2)
|
||||
{
|
||||
queueableMediaTypes = vals[2];
|
||||
}
|
||||
|
||||
var info = new PlaybackInfo
|
||||
{
|
||||
CanSeek = canSeek,
|
||||
Item = item,
|
||||
SessionId = session.Id,
|
||||
QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
|
||||
};
|
||||
|
||||
_sessionManager.OnPlaybackStart(info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the playback progress.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ReportPlaybackProgress(WebSocketMessageInfo message)
|
||||
{
|
||||
var session = GetSessionFromMessage(message);
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
|
@ -140,11 +243,16 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
_sessionManager.OnPlaybackProgress(info);
|
||||
}
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
/// <summary>
|
||||
/// Reports the playback stopped.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ReportPlaybackStopped(WebSocketMessageInfo message)
|
||||
{
|
||||
_logger.Debug("Received PlaybackStopped message");
|
||||
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
var session = GetSessionFromMessage(message);
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
|
@ -174,49 +282,5 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
_sessionManager.OnPlaybackStopped(info);
|
||||
}
|
||||
}
|
||||
|
||||
return _trueTaskResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the playback start.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ReportPlaybackStart(WebSocketMessageInfo message)
|
||||
{
|
||||
_logger.Debug("Received PlaybackStart message");
|
||||
|
||||
var session = _sessionManager.Sessions
|
||||
.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var vals = message.Data.Split('|');
|
||||
|
||||
var item = _dtoService.GetItemByDtoId(vals[0]);
|
||||
|
||||
var queueableMediaTypes = string.Empty;
|
||||
var canSeek = true;
|
||||
|
||||
if (vals.Length > 1)
|
||||
{
|
||||
canSeek = string.Equals(vals[1], "true", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
if (vals.Length > 2)
|
||||
{
|
||||
queueableMediaTypes = vals[2];
|
||||
}
|
||||
|
||||
var info = new PlaybackInfo
|
||||
{
|
||||
CanSeek = canSeek,
|
||||
Item = item,
|
||||
SessionId = session.Id,
|
||||
QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
|
||||
};
|
||||
|
||||
_sessionManager.OnPlaybackStart(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Net;
|
||||
using MediaBrowser.Model.Session;
|
||||
using MediaBrowser.Model.System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -11,15 +15,39 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
{
|
||||
public class WebSocketController : ISessionController
|
||||
{
|
||||
public bool Supports(SessionInfo session)
|
||||
public SessionInfo Session { get; private set; }
|
||||
public List<IWebSocketConnection> Sockets { get; private set; }
|
||||
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
|
||||
public WebSocketController(SessionInfo session, IServerApplicationHost appHost)
|
||||
{
|
||||
return session.WebSockets.Any(i => i.State == WebSocketState.Open);
|
||||
Session = session;
|
||||
_appHost = appHost;
|
||||
Sockets = new List<IWebSocketConnection>();
|
||||
}
|
||||
|
||||
private IWebSocketConnection GetSocket(SessionInfo session)
|
||||
public bool SupportsMediaRemoteControl
|
||||
{
|
||||
var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open);
|
||||
get
|
||||
{
|
||||
return Sockets.Any(i => i.State == WebSocketState.Open);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSessionActive
|
||||
{
|
||||
get
|
||||
{
|
||||
return Sockets.Any(i => i.State == WebSocketState.Open);
|
||||
}
|
||||
}
|
||||
|
||||
private IWebSocketConnection GetActiveSocket()
|
||||
{
|
||||
var socket = Sockets
|
||||
.OrderByDescending(i => i.LastActivityDate)
|
||||
.FirstOrDefault(i => i.State == WebSocketState.Open);
|
||||
|
||||
if (socket == null)
|
||||
{
|
||||
|
@ -29,9 +57,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
return socket;
|
||||
}
|
||||
|
||||
public Task SendSystemCommand(SessionInfo session, SystemCommand command, CancellationToken cancellationToken)
|
||||
public Task SendSystemCommand(SystemCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetSocket(session);
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<string>
|
||||
{
|
||||
|
@ -41,9 +69,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendMessageCommand(SessionInfo session, MessageCommand command, CancellationToken cancellationToken)
|
||||
public Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetSocket(session);
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<MessageCommand>
|
||||
{
|
||||
|
@ -53,9 +81,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendPlayCommand(SessionInfo session, PlayRequest command, CancellationToken cancellationToken)
|
||||
public Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetSocket(session);
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<PlayRequest>
|
||||
{
|
||||
|
@ -65,9 +93,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendBrowseCommand(SessionInfo session, BrowseRequest command, CancellationToken cancellationToken)
|
||||
public Task SendBrowseCommand(BrowseRequest command, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetSocket(session);
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<BrowseRequest>
|
||||
{
|
||||
|
@ -77,9 +105,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendPlaystateCommand(SessionInfo session, PlaystateRequest command, CancellationToken cancellationToken)
|
||||
public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetSocket(session);
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<PlaystateRequest>
|
||||
{
|
||||
|
@ -88,5 +116,34 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SendLibraryUpdateInfo(LibraryUpdateInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<LibraryUpdateInfo>
|
||||
{
|
||||
MessageType = "Playstate",
|
||||
Data = info
|
||||
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the restart required message.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public Task SendRestartRequiredMessage(CancellationToken cancellationToken)
|
||||
{
|
||||
var socket = GetActiveSocket();
|
||||
|
||||
return socket.SendAsync(new WebSocketMessage<SystemInfo>
|
||||
{
|
||||
MessageType = "RestartRequired",
|
||||
Data = _appHost.GetSystemInfo()
|
||||
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -427,8 +427,6 @@ namespace MediaBrowser.ServerApplication
|
|||
|
||||
ProviderManager.AddParts(GetExports<BaseMetadataProvider>());
|
||||
|
||||
SessionManager.AddParts(GetExports<ISessionController>());
|
||||
|
||||
ImageProcessor.AddParts(GetExports<IImageEnhancer>());
|
||||
|
||||
LiveTvManager.AddParts(GetExports<ILiveTvService>());
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace MediaBrowser.ServerApplication.Native
|
|||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenCommunity(ILogger logger)
|
||||
{
|
||||
OpenUrl("http://community.mediabrowser.tv/", logger);
|
||||
OpenUrl("http://mediabrowser3.com/community", logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common.Internal</id>
|
||||
<version>3.0.215</version>
|
||||
<version>3.0.216</version>
|
||||
<title>MediaBrowser.Common.Internal</title>
|
||||
<authors>Luke</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.215" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.216" />
|
||||
<dependency id="NLog" version="2.0.1.2" />
|
||||
<dependency id="ServiceStack.Text" version="3.9.58" />
|
||||
<dependency id="SimpleInjector" version="2.3.2" />
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common</id>
|
||||
<version>3.0.215</version>
|
||||
<version>3.0.216</version>
|
||||
<title>MediaBrowser.Common</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Server.Core</id>
|
||||
<version>3.0.215</version>
|
||||
<version>3.0.216</version>
|
||||
<title>Media Browser.Server.Core</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.215" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.216" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
|
Loading…
Reference in New Issue
Block a user