jellyfin/MediaBrowser.Api/Session/SessionsService.cs

560 lines
22 KiB
C#
Raw Normal View History

2014-12-29 20:18:48 +00:00
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
2014-07-12 02:31:08 +00:00
using MediaBrowser.Controller.Security;
2013-05-09 22:43:11 +00:00
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Session;
2013-05-10 12:18:07 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2013-05-10 12:18:07 +00:00
using System.Threading;
2013-05-28 17:25:10 +00:00
using System.Threading.Tasks;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.Services;
2014-08-10 22:13:17 +00:00
namespace MediaBrowser.Api.Session
{
/// <summary>
/// Class GetSessions
/// </summary>
2014-03-23 19:36:25 +00:00
[Route("/Sessions", "GET", Summary = "Gets a list of sessions")]
[Authenticated]
2017-08-19 19:43:35 +00:00
public class GetSessions : IReturn<SessionInfoDto[]>
{
[ApiMember(Name = "ControllableByUserId", Description = "Optional. Filter by sessions that a given user is allowed to remote control.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2015-05-29 23:51:33 +00:00
public string ControllableByUserId { get; set; }
2014-01-06 16:48:43 +00:00
2014-03-23 20:49:05 +00:00
[ApiMember(Name = "DeviceId", Description = "Optional. Filter by device id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2014-01-06 16:48:43 +00:00
public string DeviceId { get; set; }
2013-05-10 12:18:07 +00:00
}
2013-05-11 16:45:20 +00:00
/// <summary>
2014-04-13 17:27:13 +00:00
/// Class DisplayContent
2013-05-11 16:45:20 +00:00
/// </summary>
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Viewing", "POST", Summary = "Instructs a session to browse to an item or view")]
[Authenticated]
2014-04-13 17:27:13 +00:00
public class DisplayContent : IReturnVoid
2013-05-10 12:18:07 +00:00
{
2013-05-11 16:45:20 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-05-10 12:18:07 +00:00
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2013-05-10 12:18:07 +00:00
/// <summary>
2013-05-10 12:18:07 +00:00
/// Artist, Genre, Studio, Person, or any kind of BaseItem
/// </summary>
2013-05-10 12:18:07 +00:00
/// <value>The type of the item.</value>
2013-05-28 17:25:10 +00:00
[ApiMember(Name = "ItemType", Description = "The type of item to browse to.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2013-05-10 12:18:07 +00:00
public string ItemType { get; set; }
/// <summary>
/// Artist name, genre name, item Id, etc
/// </summary>
/// <value>The item identifier.</value>
2013-05-26 00:53:51 +00:00
[ApiMember(Name = "ItemId", Description = "The Id of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string ItemId { get; set; }
2013-05-10 12:18:07 +00:00
2013-05-26 00:53:51 +00:00
/// <summary>
/// Gets or sets the name of the item.
/// </summary>
/// <value>The name of the item.</value>
[ApiMember(Name = "ItemName", Description = "The name of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string ItemName { get; set; }
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Playing", "POST", Summary = "Instructs a session to play an item")]
[Authenticated]
2013-05-28 17:25:10 +00:00
public class Play : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2013-05-28 17:25:10 +00:00
/// <summary>
/// Artist, Genre, Studio, Person, or any kind of BaseItem
/// </summary>
/// <value>The type of the item.</value>
[ApiMember(Name = "ItemIds", Description = "The ids of the items to play, comma delimited", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST", AllowMultiple = true)]
public string ItemIds { get; set; }
/// <summary>
/// Gets or sets the start position ticks that the first item should be played at
/// </summary>
/// <value>The start position ticks.</value>
[ApiMember(Name = "StartPositionTicks", Description = "The starting position of the first item.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public long? StartPositionTicks { get; set; }
/// <summary>
/// Gets or sets the play command.
/// </summary>
/// <value>The play command.</value>
[ApiMember(Name = "PlayCommand", Description = "The type of play command to issue (PlayNow, PlayNext, PlayLast). Clients who have not yet implemented play next and play last may play now.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public PlayCommand PlayCommand { get; set; }
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Playing/{Command}", "POST", Summary = "Issues a playstate command to a client")]
[Authenticated]
2017-06-09 19:26:54 +00:00
public class SendPlaystateCommand : PlaystateRequest, IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/System/{Command}", "POST", Summary = "Issues a system command to a client")]
[Authenticated]
2013-08-28 04:16:21 +00:00
public class SendSystemCommand : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2013-08-28 04:16:21 +00:00
/// <summary>
/// Gets or sets the command.
/// </summary>
/// <value>The play command.</value>
[ApiMember(Name = "Command", Description = "The command to send.", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-03-31 21:04:22 +00:00
public string Command { get; set; }
}
[Route("/Sessions/{Id}/Command/{Command}", "POST", Summary = "Issues a system command to a client")]
[Authenticated]
2014-03-31 21:04:22 +00:00
public class SendGeneralCommand : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2014-03-31 21:04:22 +00:00
/// <summary>
/// Gets or sets the command.
/// </summary>
/// <value>The play command.</value>
[ApiMember(Name = "Command", Description = "The command to send.", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Command { get; set; }
}
[Route("/Sessions/{Id}/Command", "POST", Summary = "Issues a system command to a client")]
[Authenticated]
2014-03-31 21:04:22 +00:00
public class SendFullGeneralCommand : GeneralCommand, IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2013-08-28 04:16:21 +00:00
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Message", "POST", Summary = "Issues a command to a client to display a message to the user")]
[Authenticated]
2013-08-28 04:16:21 +00:00
public class SendMessageCommand : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
2013-08-28 04:16:21 +00:00
[ApiMember(Name = "Text", Description = "The message text.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Text { get; set; }
[ApiMember(Name = "Header", Description = "The message header.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Header { get; set; }
[ApiMember(Name = "TimeoutMs", Description = "The message timeout. If omitted the user will have to confirm viewing the message.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
2013-08-28 04:16:21 +00:00
public long? TimeoutMs { get; set; }
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Users/{UserId}", "POST", Summary = "Adds an additional user to a session")]
[Authenticated]
public class AddUserToSession : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
[ApiMember(Name = "UserId", Description = "UserId Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2015-05-29 23:51:33 +00:00
public string UserId { get; set; }
}
2014-03-23 19:36:25 +00:00
[Route("/Sessions/{Id}/Users/{UserId}", "DELETE", Summary = "Removes an additional user from a session")]
[Authenticated]
public class RemoveUserFromSession : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 02:17:48 +00:00
public string Id { get; set; }
[ApiMember(Name = "UserId", Description = "UserId Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2015-05-29 23:51:33 +00:00
public string UserId { get; set; }
}
2014-04-13 17:27:13 +00:00
[Route("/Sessions/Capabilities", "POST", Summary = "Updates capabilities for a device")]
2014-07-08 01:41:03 +00:00
[Authenticated]
public class PostCapabilities : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-13 17:27:13 +00:00
public string Id { get; set; }
2014-01-05 06:08:22 +00:00
[ApiMember(Name = "PlayableMediaTypes", Description = "A list of playable media types, comma delimited. Audio, Video, Book, Game, Photo.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string PlayableMediaTypes { get; set; }
2014-03-21 03:31:40 +00:00
2014-04-02 21:55:19 +00:00
[ApiMember(Name = "SupportedCommands", Description = "A list of supported remote control commands, comma delimited", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string SupportedCommands { get; set; }
2014-05-17 18:37:40 +00:00
2014-05-18 19:58:42 +00:00
[ApiMember(Name = "MessageCallbackUrl", Description = "A url to post messages to, including remote control commands.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MessageCallbackUrl { get; set; }
2014-05-17 18:37:40 +00:00
[ApiMember(Name = "SupportsMediaControl", Description = "Determines whether media can be played remotely.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool SupportsMediaControl { get; set; }
2014-10-11 20:38:13 +00:00
2014-12-13 03:56:30 +00:00
[ApiMember(Name = "SupportsSync", Description = "Determines whether sync is supported.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool SupportsSync { get; set; }
2014-12-14 20:01:26 +00:00
2015-01-20 05:19:13 +00:00
[ApiMember(Name = "SupportsPersistentIdentifier", Description = "Determines whether the device supports a unique identifier.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool SupportsPersistentIdentifier { get; set; }
2017-01-02 05:13:39 +00:00
public bool SupportsContentUploading { get; set; }
public PostCapabilities()
{
2015-01-20 05:19:13 +00:00
SupportsPersistentIdentifier = true;
}
}
2014-03-13 09:18:32 +00:00
2014-12-14 20:01:26 +00:00
[Route("/Sessions/Capabilities/Full", "POST", Summary = "Updates capabilities for a device")]
[Authenticated]
public class PostFullCapabilities : ClientCapabilities, IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get; set; }
}
2014-07-08 01:41:03 +00:00
[Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")]
2014-11-15 02:31:03 +00:00
[Authenticated]
2014-07-08 01:41:03 +00:00
public class ReportSessionEnded : IReturnVoid
{
}
2014-07-12 02:31:08 +00:00
[Route("/Auth/Keys", "GET")]
2014-11-15 02:31:03 +00:00
[Authenticated(Roles = "Admin")]
2014-07-12 02:31:08 +00:00
public class GetApiKeys
{
}
[Route("/Auth/Keys/{Key}", "DELETE")]
2014-11-15 02:31:03 +00:00
[Authenticated(Roles = "Admin")]
2014-07-12 02:31:08 +00:00
public class RevokeKey
{
[ApiMember(Name = "Key", Description = "Auth Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Key { get; set; }
}
[Route("/Auth/Keys", "POST")]
2014-11-15 02:31:03 +00:00
[Authenticated(Roles = "Admin")]
2014-07-12 02:31:08 +00:00
public class CreateKey
{
[ApiMember(Name = "App", Description = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string App { get; set; }
}
/// <summary>
/// Class SessionsService
/// </summary>
public class SessionsService : BaseApiService
{
/// <summary>
/// The _session manager
/// </summary>
private readonly ISessionManager _sessionManager;
private readonly IUserManager _userManager;
2014-07-08 01:41:03 +00:00
private readonly IAuthorizationContext _authContext;
2014-07-12 02:31:08 +00:00
private readonly IAuthenticationRepository _authRepo;
2014-12-29 20:18:48 +00:00
private readonly IDeviceManager _deviceManager;
2016-11-10 14:41:24 +00:00
private readonly ISessionContext _sessionContext;
2013-09-04 17:02:19 +00:00
/// <summary>
2013-05-11 16:45:20 +00:00
/// Initializes a new instance of the <see cref="SessionsService" /> class.
/// </summary>
/// <param name="sessionManager">The session manager.</param>
2014-04-06 17:53:23 +00:00
/// <param name="userManager">The user manager.</param>
2014-07-12 02:31:08 +00:00
/// <param name="authContext">The authentication context.</param>
/// <param name="authRepo">The authentication repo.</param>
2016-11-10 14:41:24 +00:00
public SessionsService(ISessionManager sessionManager, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext)
{
_sessionManager = sessionManager;
_userManager = userManager;
2014-07-08 01:41:03 +00:00
_authContext = authContext;
2014-07-12 02:31:08 +00:00
_authRepo = authRepo;
2014-12-29 20:18:48 +00:00
_deviceManager = deviceManager;
2016-11-10 14:41:24 +00:00
_sessionContext = sessionContext;
2014-07-08 01:41:03 +00:00
}
2014-07-12 02:31:08 +00:00
public void Delete(RevokeKey request)
{
var task = _sessionManager.RevokeToken(request.Key);
Task.WaitAll(task);
}
2014-08-19 01:42:53 +00:00
public void Post(CreateKey request)
2014-07-12 02:31:08 +00:00
{
2014-08-19 01:42:53 +00:00
var task = _authRepo.Create(new AuthenticationInfo
2014-07-12 02:31:08 +00:00
{
AppName = request.App,
IsActive = true,
AccessToken = Guid.NewGuid().ToString("N"),
DateCreated = DateTime.UtcNow
}, CancellationToken.None);
2014-08-19 01:42:53 +00:00
Task.WaitAll(task);
2014-07-12 02:31:08 +00:00
}
2014-07-08 01:41:03 +00:00
public void Post(ReportSessionEnded request)
{
var auth = _authContext.GetAuthorizationInfo(Request);
_sessionManager.Logout(auth.Token);
}
2014-07-12 02:31:08 +00:00
public object Get(GetApiKeys request)
{
var result = _authRepo.Get(new AuthenticationInfoQuery
{
2016-01-20 03:02:14 +00:00
IsActive = true,
HasUser = false
2014-07-12 02:31:08 +00:00
});
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetSessions request)
{
2013-05-10 12:18:07 +00:00
var result = _sessionManager.Sessions.Where(i => i.IsActive);
2014-01-06 16:48:43 +00:00
if (!string.IsNullOrEmpty(request.DeviceId))
{
result = result.Where(i => string.Equals(i.DeviceId, request.DeviceId, StringComparison.OrdinalIgnoreCase));
}
2015-05-29 23:51:33 +00:00
if (!string.IsNullOrWhiteSpace(request.ControllableByUserId))
{
2014-05-17 18:37:40 +00:00
result = result.Where(i => i.SupportsMediaControl);
2015-05-29 23:51:33 +00:00
var user = _userManager.GetUserById(request.ControllableByUserId);
2014-12-20 06:06:27 +00:00
if (!user.Policy.EnableRemoteControlOfOtherUsers)
{
2015-05-29 23:51:33 +00:00
result = result.Where(i => !i.UserId.HasValue || i.ContainsUser(request.ControllableByUserId));
2014-11-19 02:45:12 +00:00
}
2014-12-20 06:06:27 +00:00
if (!user.Policy.EnableSharedDeviceControl)
2014-11-19 02:45:12 +00:00
{
2015-04-11 02:43:30 +00:00
result = result.Where(i => i.UserId.HasValue);
}
2014-12-29 20:18:48 +00:00
result = result.Where(i =>
{
var deviceId = i.DeviceId;
if (!string.IsNullOrWhiteSpace(deviceId))
{
if (!_deviceManager.CanAccessDevice(user.Id.ToString("N"), deviceId))
{
return false;
}
}
return true;
});
}
2017-08-19 19:43:35 +00:00
return ToOptimizedResult(result.Select(_sessionManager.GetSessionInfoDto).ToArray());
}
2013-05-10 12:18:07 +00:00
2014-08-19 01:42:53 +00:00
public void Post(SendPlaystateCommand request)
2014-03-13 09:18:32 +00:00
{
2017-06-09 19:26:54 +00:00
var task = _sessionManager.SendPlaystateCommand(GetSession(_sessionContext).Result.Id, request.Id, request, CancellationToken.None);
2014-08-19 01:42:53 +00:00
Task.WaitAll(task);
}
2013-05-11 16:45:20 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2014-08-19 01:42:53 +00:00
public void Post(DisplayContent request)
2013-05-28 17:25:10 +00:00
{
var command = new BrowseRequest
{
ItemId = request.ItemId,
ItemName = request.ItemName,
ItemType = request.ItemType
};
2016-11-10 14:41:24 +00:00
var task = _sessionManager.SendBrowseCommand(GetSession(_sessionContext).Result.Id, request.Id, command, CancellationToken.None);
2014-08-19 01:42:53 +00:00
Task.WaitAll(task);
2013-05-10 12:18:07 +00:00
}
2013-05-28 17:25:10 +00:00
2013-08-28 04:16:21 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2014-08-19 01:42:53 +00:00
public void Post(SendSystemCommand request)
2013-08-28 04:16:21 +00:00
{
2014-03-31 21:04:22 +00:00
GeneralCommandType commandType;
2014-08-17 18:12:17 +00:00
var name = request.Command;
2013-08-28 04:16:21 +00:00
2014-08-17 18:12:17 +00:00
if (Enum.TryParse(name, true, out commandType))
2014-03-31 21:04:22 +00:00
{
2014-08-17 18:12:17 +00:00
name = commandType.ToString();
}
2014-03-31 21:04:22 +00:00
2016-11-10 14:41:24 +00:00
var currentSession = GetSession(_sessionContext).Result;
2014-03-31 21:04:22 +00:00
2014-08-17 18:12:17 +00:00
var command = new GeneralCommand
{
Name = name,
ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null
};
2014-03-31 21:04:22 +00:00
2014-08-19 01:42:53 +00:00
var task = _sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None);
Task.WaitAll(task);
2013-08-28 04:16:21 +00:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2014-08-19 01:42:53 +00:00
public void Post(SendMessageCommand request)
2013-08-28 04:16:21 +00:00
{
var command = new MessageCommand
2013-08-28 04:16:21 +00:00
{
Header = string.IsNullOrEmpty(request.Header) ? "Message from Server" : request.Header,
TimeoutMs = request.TimeoutMs,
Text = request.Text
};
2013-08-28 04:16:21 +00:00
2016-11-10 14:41:24 +00:00
var task = _sessionManager.SendMessageCommand(GetSession(_sessionContext).Result.Id, request.Id, command, CancellationToken.None);
2014-08-19 01:42:53 +00:00
Task.WaitAll(task);
2013-08-28 04:16:21 +00:00
}
2013-05-28 17:25:10 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2014-08-19 01:42:53 +00:00
public void Post(Play request)
2013-05-28 17:25:10 +00:00
{
var command = new PlayRequest
2013-05-28 17:25:10 +00:00
{
ItemIds = request.ItemIds.Split(','),
2014-03-13 09:18:32 +00:00
PlayCommand = request.PlayCommand,
StartPositionTicks = request.StartPositionTicks
};
2013-05-28 17:25:10 +00:00
2016-11-10 14:41:24 +00:00
var task = _sessionManager.SendPlayCommand(GetSession(_sessionContext).Result.Id, request.Id, command, CancellationToken.None);
2014-08-19 01:42:53 +00:00
Task.WaitAll(task);
2013-05-28 17:25:10 +00:00
}
2014-08-19 01:42:53 +00:00
public void Post(SendGeneralCommand request)
2014-03-31 21:04:22 +00:00
{
2016-11-10 14:41:24 +00:00
var currentSession = GetSession(_sessionContext).Result;
2014-03-31 21:04:22 +00:00
var command = new GeneralCommand
{
Name = request.Command,
ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null
};
2014-08-19 01:42:53 +00:00
var task = _sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None);
Task.WaitAll(task);
2014-03-31 21:04:22 +00:00
}
2014-08-19 01:42:53 +00:00
public void Post(SendFullGeneralCommand request)
2014-03-31 21:04:22 +00:00
{
2016-11-10 14:41:24 +00:00
var currentSession = GetSession(_sessionContext).Result;
2014-03-31 21:04:22 +00:00
request.ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null;
2014-08-19 01:42:53 +00:00
var task = _sessionManager.SendGeneralCommand(currentSession.Id, request.Id, request, CancellationToken.None);
Task.WaitAll(task);
2014-03-31 21:04:22 +00:00
}
public void Post(AddUserToSession request)
{
_sessionManager.AddAdditionalUser(request.Id, request.UserId);
}
public void Delete(RemoveUserFromSession request)
{
_sessionManager.RemoveAdditionalUser(request.Id, request.UserId);
}
public void Post(PostCapabilities request)
{
2014-04-13 17:27:13 +00:00
if (string.IsNullOrWhiteSpace(request.Id))
{
2016-11-10 14:41:24 +00:00
request.Id = GetSession(_sessionContext).Result.Id;
2014-04-13 17:27:13 +00:00
}
2014-10-11 20:38:13 +00:00
_sessionManager.ReportCapabilities(request.Id, new ClientCapabilities
2014-03-21 03:31:40 +00:00
{
2017-08-19 19:43:35 +00:00
PlayableMediaTypes = SplitValue(request.PlayableMediaTypes, ','),
2017-08-19 19:43:35 +00:00
SupportedCommands = SplitValue(request.SupportedCommands, ','),
2014-05-17 18:37:40 +00:00
2014-05-18 19:58:42 +00:00
SupportsMediaControl = request.SupportsMediaControl,
2014-10-11 20:38:13 +00:00
MessageCallbackUrl = request.MessageCallbackUrl,
2014-12-13 03:56:30 +00:00
SupportsSync = request.SupportsSync,
2017-01-02 05:13:39 +00:00
SupportsContentUploading = request.SupportsContentUploading,
2015-01-20 05:19:13 +00:00
SupportsPersistentIdentifier = request.SupportsPersistentIdentifier
2014-03-21 03:31:40 +00:00
});
}
2014-12-14 20:01:26 +00:00
public void Post(PostFullCapabilities request)
{
if (string.IsNullOrWhiteSpace(request.Id))
{
2016-11-10 14:41:24 +00:00
request.Id = GetSession(_sessionContext).Result.Id;
2014-12-14 20:01:26 +00:00
}
_sessionManager.ReportCapabilities(request.Id, request);
}
}
2014-03-13 09:18:32 +00:00
}