2019-01-13 21:01:16 +01:00
using System ;
2019-02-28 23:22:57 +01:00
using System.Globalization ;
2013-05-09 19:38:02 +02:00
using System.Linq ;
2013-05-10 14:18:07 +02:00
using System.Threading ;
2013-05-28 19:25:10 +02:00
using System.Threading.Tasks ;
2017-10-22 08:22:43 +02:00
using MediaBrowser.Controller ;
2019-11-17 23:05:39 +01:00
using MediaBrowser.Controller.Configuration ;
2019-01-13 20:24:58 +01:00
using MediaBrowser.Controller.Devices ;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Net ;
using MediaBrowser.Controller.Security ;
using MediaBrowser.Controller.Session ;
2018-09-12 19:26:21 +02:00
using MediaBrowser.Model.Dto ;
2019-01-13 20:24:58 +01:00
using MediaBrowser.Model.Services ;
using MediaBrowser.Model.Session ;
2019-11-17 23:05:39 +01:00
using Microsoft.Extensions.Logging ;
2013-05-09 19:38:02 +02:00
2014-08-11 00:13:17 +02:00
namespace MediaBrowser.Api.Session
2013-05-09 19:38:02 +02:00
{
/// <summary>
/// Class GetSessions
/// </summary>
2014-03-23 20:36:25 +01:00
[Route("/Sessions", "GET", Summary = "Gets a list of sessions")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2018-09-12 19:26:21 +02:00
public class GetSessions : IReturn < SessionInfo [ ] >
2013-05-09 19:38:02 +02:00
{
2013-09-19 22:03:14 +02:00
[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")]
2018-09-12 19:26:21 +02:00
public Guid ControllableByUserId { get ; set ; }
2014-01-06 17:48:43 +01:00
2014-03-23 21:49:05 +01:00
[ApiMember(Name = "DeviceId", Description = "Optional. Filter by device id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2014-01-06 17:48:43 +01:00
public string DeviceId { get ; set ; }
2018-09-12 19:26:21 +02:00
public int? ActiveWithinSeconds { get ; set ; }
2013-05-10 14:18:07 +02:00
}
2013-05-11 18:45:20 +02:00
/// <summary>
2014-04-13 19:27:13 +02:00
/// Class DisplayContent
2013-05-11 18:45:20 +02:00
/// </summary>
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Viewing", "POST", Summary = "Instructs a session to browse to an item or view")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2014-04-13 19:27:13 +02:00
public class DisplayContent : IReturnVoid
2013-05-10 14:18:07 +02:00
{
2013-05-11 18:45:20 +02:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-05-10 14:18:07 +02:00
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 04:17:48 +02:00
public string Id { get ; set ; }
2013-05-10 14:18:07 +02:00
2013-05-09 19:38:02 +02:00
/// <summary>
2013-05-10 14:18:07 +02:00
/// Artist, Genre, Studio, Person, or any kind of BaseItem
2013-05-09 19:38:02 +02:00
/// </summary>
2013-05-10 14:18:07 +02:00
/// <value>The type of the item.</value>
2013-05-28 19:25:10 +02:00
[ApiMember(Name = "ItemType", Description = "The type of item to browse to.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2013-05-10 14:18:07 +02:00
public string ItemType { get ; set ; }
/// <summary>
/// Artist name, genre name, item Id, etc
/// </summary>
/// <value>The item identifier.</value>
2013-05-26 02:53:51 +02: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 14:18:07 +02:00
2013-05-26 02:53:51 +02: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 ; }
2013-05-09 19:38:02 +02:00
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Playing", "POST", Summary = "Instructs a session to play an item")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2017-11-09 21:58:09 +01:00
public class Play : PlayRequest
2013-05-28 19:25:10 +02:00
{
/// <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 04:17:48 +02:00
public string Id { get ; set ; }
2013-05-28 19:25:10 +02:00
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Playing/{Command}", "POST", Summary = "Issues a playstate command to a client")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2017-06-09 21:26:54 +02:00
public class SendPlaystateCommand : PlaystateRequest , IReturnVoid
2013-07-09 18:11:16 +02:00
{
/// <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 04:17:48 +02:00
public string Id { get ; set ; }
2013-07-09 18:11:16 +02:00
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/System/{Command}", "POST", Summary = "Issues a system command to a client")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2013-08-28 06:16:21 +02: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 04:17:48 +02:00
public string Id { get ; set ; }
2013-08-28 06:16:21 +02: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 23:04:22 +02:00
public string Command { get ; set ; }
}
[Route("/Sessions/{Id}/Command/{Command}", "POST", Summary = "Issues a system command to a client")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2014-03-31 23:04:22 +02: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 04:17:48 +02:00
public string Id { get ; set ; }
2014-03-31 23:04:22 +02: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")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2014-03-31 23:04:22 +02: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 04:17:48 +02:00
public string Id { get ; set ; }
2013-08-28 06:16:21 +02:00
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Message", "POST", Summary = "Issues a command to a client to display a message to the user")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2013-08-28 06:16:21 +02: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 04:17:48 +02:00
public string Id { get ; set ; }
2013-08-28 06:16:21 +02: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 ; }
2013-08-28 06:31:34 +02:00
[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 06:16:21 +02:00
public long? TimeoutMs { get ; set ; }
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Users/{UserId}", "POST", Summary = "Adds an additional user to a session")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2014-01-04 03:35:41 +01:00
public class AddUserToSession : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 04:17:48 +02:00
public string Id { get ; set ; }
2014-01-04 03:35:41 +01:00
[ApiMember(Name = "UserId", Description = "UserId Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2015-05-30 01:51:33 +02:00
public string UserId { get ; set ; }
2014-01-04 03:35:41 +01:00
}
2014-03-23 20:36:25 +01:00
[Route("/Sessions/{Id}/Users/{UserId}", "DELETE", Summary = "Removes an additional user from a session")]
2014-07-04 04:22:57 +02:00
[Authenticated]
2014-01-04 03:35:41 +01:00
public class RemoveUserFromSession : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2014-04-16 04:17:48 +02:00
public string Id { get ; set ; }
2014-01-04 03:35:41 +01:00
[ApiMember(Name = "UserId", Description = "UserId Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2015-05-30 01:51:33 +02:00
public string UserId { get ; set ; }
2014-01-04 03:35:41 +01:00
}
2014-04-13 19:27:13 +02:00
[Route("/Sessions/Capabilities", "POST", Summary = "Updates capabilities for a device")]
2014-07-08 03:41:03 +02:00
[Authenticated]
2014-01-05 06:34:06 +01:00
public class PostCapabilities : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2018-09-12 19:26:21 +02:00
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2014-04-13 19:27:13 +02:00
public string Id { get ; set ; }
2014-01-05 06:34:06 +01:00
2019-01-28 18:49:25 +01:00
[ApiMember(Name = "PlayableMediaTypes", Description = "A list of playable media types, comma delimited. Audio, Video, Book, Photo.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
2014-01-05 06:34:06 +01:00
public string PlayableMediaTypes { get ; set ; }
2014-03-21 04:31:40 +01:00
2014-04-02 23:55:19 +02: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 20:37:40 +02: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 22:38:13 +02:00
2014-12-13 04:56:30 +01: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 21:01:26 +01:00
2015-01-20 06:19:13 +01: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 ; }
2015-01-13 04:46:44 +01:00
public PostCapabilities ( )
{
2015-01-20 06:19:13 +01:00
SupportsPersistentIdentifier = true ;
2015-01-13 04:46:44 +01:00
}
2014-01-05 06:34:06 +01:00
}
2014-03-13 10:18:32 +01:00
2014-12-14 21:01:26 +01: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>
2018-09-12 19:26:21 +02:00
[ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2014-12-14 21:01:26 +01:00
public string Id { get ; set ; }
}
2014-07-08 03:41:03 +02:00
[Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")]
2014-11-15 03:31:03 +01:00
[Authenticated]
2014-07-08 03:41:03 +02:00
public class ReportSessionEnded : IReturnVoid
{
}
2014-07-12 04:31:08 +02:00
[Route("/Auth/Keys", "GET")]
2014-11-15 03:31:03 +01:00
[Authenticated(Roles = "Admin")]
2014-07-12 04:31:08 +02:00
public class GetApiKeys
{
}
2018-09-12 19:26:21 +02:00
[Route("/Auth/Providers", "GET")]
[Authenticated(Roles = "Admin")]
public class GetAuthProviders : IReturn < NameIdPair [ ] >
{
}
2019-03-22 08:01:23 +01:00
[Route("/Auth/PasswordResetProviders", "GET")]
[Authenticated(Roles = "Admin")]
public class GetPasswordResetProviders : IReturn < NameIdPair [ ] >
{
}
2014-07-12 04:31:08 +02:00
[Route("/Auth/Keys/{Key}", "DELETE")]
2014-11-15 03:31:03 +01:00
[Authenticated(Roles = "Admin")]
2014-07-12 04:31:08 +02:00
public class RevokeKey
{
2018-09-12 19:26:21 +02:00
[ApiMember(Name = "Key", Description = "Auth Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2014-07-12 04:31:08 +02:00
public string Key { get ; set ; }
}
[Route("/Auth/Keys", "POST")]
2014-11-15 03:31:03 +01:00
[Authenticated(Roles = "Admin")]
2014-07-12 04:31:08 +02:00
public class CreateKey
{
[ApiMember(Name = "App", Description = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string App { get ; set ; }
}
2013-05-09 19:38:02 +02:00
/// <summary>
2019-11-17 23:05:39 +01:00
/// Class SessionsService.
2013-05-09 19:38:02 +02:00
/// </summary>
public class SessionsService : BaseApiService
{
/// <summary>
2019-11-17 23:05:39 +01:00
/// The _session manager.
2013-05-09 19:38:02 +02:00
/// </summary>
private readonly ISessionManager _sessionManager ;
2013-10-30 16:55:55 +01:00
private readonly IUserManager _userManager ;
2014-07-08 03:41:03 +02:00
private readonly IAuthorizationContext _authContext ;
2014-07-12 04:31:08 +02:00
private readonly IAuthenticationRepository _authRepo ;
2014-12-29 21:18:48 +01:00
private readonly IDeviceManager _deviceManager ;
2016-11-10 15:41:24 +01:00
private readonly ISessionContext _sessionContext ;
2019-11-17 23:05:39 +01:00
private readonly IServerApplicationHost _appHost ;
public SessionsService (
ILogger < SessionsService > logger ,
IServerConfigurationManager serverConfigurationManager ,
IHttpResultFactory httpResultFactory ,
ISessionManager sessionManager ,
IServerApplicationHost appHost ,
IUserManager userManager ,
IAuthorizationContext authContext ,
IAuthenticationRepository authRepo ,
IDeviceManager deviceManager ,
ISessionContext sessionContext )
: base ( logger , serverConfigurationManager , httpResultFactory )
2013-05-09 19:38:02 +02:00
{
_sessionManager = sessionManager ;
2013-10-30 16:55:55 +01:00
_userManager = userManager ;
2014-07-08 03:41:03 +02:00
_authContext = authContext ;
2014-07-12 04:31:08 +02:00
_authRepo = authRepo ;
2014-12-29 21:18:48 +01:00
_deviceManager = deviceManager ;
2016-11-10 15:41:24 +01:00
_sessionContext = sessionContext ;
2017-10-22 08:22:43 +02:00
_appHost = appHost ;
2014-07-08 03:41:03 +02:00
}
2018-09-12 19:26:21 +02:00
public object Get ( GetAuthProviders request )
{
return _userManager . GetAuthenticationProviders ( ) ;
}
2019-03-22 08:01:23 +01:00
public object Get ( GetPasswordResetProviders request )
{
return _userManager . GetPasswordResetProviders ( ) ;
}
2014-07-12 04:31:08 +02:00
public void Delete ( RevokeKey request )
{
2017-08-27 02:32:33 +02:00
_sessionManager . RevokeToken ( request . Key ) ;
2014-07-12 04:31:08 +02:00
}
2014-08-19 03:42:53 +02:00
public void Post ( CreateKey request )
2014-07-12 04:31:08 +02:00
{
2017-08-27 02:32:33 +02:00
_authRepo . Create ( new AuthenticationInfo
2014-07-12 04:31:08 +02:00
{
AppName = request . App ,
2019-02-28 23:22:57 +01:00
AccessToken = Guid . NewGuid ( ) . ToString ( "N" , CultureInfo . InvariantCulture ) ,
2017-10-22 08:22:43 +02:00
DateCreated = DateTime . UtcNow ,
DeviceId = _appHost . SystemId ,
DeviceName = _appHost . FriendlyName ,
2019-10-08 20:51:11 +02:00
AppVersion = _appHost . ApplicationVersionString
2018-09-12 19:26:21 +02:00
} ) ;
2014-07-12 04:31:08 +02:00
}
2014-07-08 03:41:03 +02:00
public void Post ( ReportSessionEnded request )
{
var auth = _authContext . GetAuthorizationInfo ( Request ) ;
_sessionManager . Logout ( auth . Token ) ;
2013-05-09 19:38:02 +02:00
}
2014-07-12 04:31:08 +02:00
public object Get ( GetApiKeys request )
{
var result = _authRepo . Get ( new AuthenticationInfoQuery
{
2016-01-20 04:02:14 +01:00
HasUser = false
2014-07-12 04:31:08 +02:00
} ) ;
2018-09-12 19:26:21 +02:00
return result ;
2014-07-12 04:31:08 +02:00
}
2013-05-09 19:38:02 +02:00
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get ( GetSessions request )
{
2018-09-12 19:26:21 +02:00
var result = _sessionManager . Sessions ;
2013-05-10 14:18:07 +02:00
2014-01-06 17:48:43 +01:00
if ( ! string . IsNullOrEmpty ( request . DeviceId ) )
{
result = result . Where ( i = > string . Equals ( i . DeviceId , request . DeviceId , StringComparison . OrdinalIgnoreCase ) ) ;
}
2018-09-12 19:26:21 +02:00
if ( ! request . ControllableByUserId . Equals ( Guid . Empty ) )
2013-10-30 16:55:55 +01:00
{
2018-09-12 19:26:21 +02:00
result = result . Where ( i = > i . SupportsRemoteControl ) ;
2014-05-17 20:37:40 +02:00
2015-05-30 01:51:33 +02:00
var user = _userManager . GetUserById ( request . ControllableByUserId ) ;
2013-10-30 16:55:55 +01:00
2014-12-20 07:06:27 +01:00
if ( ! user . Policy . EnableRemoteControlOfOtherUsers )
2013-10-30 16:55:55 +01:00
{
2018-09-12 19:26:21 +02:00
result = result . Where ( i = > i . UserId . Equals ( Guid . Empty ) | | i . ContainsUser ( request . ControllableByUserId ) ) ;
2014-11-19 03:45:12 +01:00
}
2014-12-20 07:06:27 +01:00
if ( ! user . Policy . EnableSharedDeviceControl )
2014-11-19 03:45:12 +01:00
{
2018-09-12 19:26:21 +02:00
result = result . Where ( i = > ! i . UserId . Equals ( Guid . Empty ) ) ;
}
if ( request . ActiveWithinSeconds . HasValue & & request . ActiveWithinSeconds . Value > 0 )
{
var minActiveDate = DateTime . UtcNow . AddSeconds ( 0 - request . ActiveWithinSeconds . Value ) ;
result = result . Where ( i = > i . LastActivityDate > = minActiveDate ) ;
2013-10-30 16:55:55 +01:00
}
2014-12-29 21:18:48 +01:00
result = result . Where ( i = >
{
var deviceId = i . DeviceId ;
if ( ! string . IsNullOrWhiteSpace ( deviceId ) )
{
2018-09-12 19:26:21 +02:00
if ( ! _deviceManager . CanAccessDevice ( user , deviceId ) )
2014-12-29 21:18:48 +01:00
{
return false ;
}
}
return true ;
} ) ;
2013-10-30 16:55:55 +01:00
}
2018-09-12 19:26:21 +02:00
return ToOptimizedResult ( result . ToArray ( ) ) ;
2013-05-09 19:38:02 +02:00
}
2013-05-10 14:18:07 +02:00
2018-09-12 19:26:21 +02:00
public Task Post ( SendPlaystateCommand request )
2014-03-13 10:18:32 +01:00
{
2018-09-12 19:26:21 +02:00
return _sessionManager . SendPlaystateCommand ( GetSession ( _sessionContext ) . Id , request . Id , request , CancellationToken . None ) ;
2013-07-09 18:11:16 +02:00
}
2013-08-28 06:31:34 +02:00
2013-05-11 18:45:20 +02:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2018-09-12 19:26:21 +02:00
public Task Post ( DisplayContent request )
2013-05-28 19:25:10 +02:00
{
2013-09-24 21:54:42 +02:00
var command = new BrowseRequest
2013-05-27 03:23:46 +02:00
{
2013-09-24 21:54:42 +02:00
ItemId = request . ItemId ,
ItemName = request . ItemName ,
ItemType = request . ItemType
} ;
2013-05-27 03:23:46 +02:00
2018-09-12 19:26:21 +02:00
return _sessionManager . SendBrowseCommand ( GetSession ( _sessionContext ) . Id , request . Id , command , CancellationToken . None ) ;
2013-05-10 14:18:07 +02:00
}
2013-05-28 19:25:10 +02:00
2013-08-28 06:16:21 +02:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2018-09-12 19:26:21 +02:00
public Task Post ( SendSystemCommand request )
2013-08-28 06:16:21 +02:00
{
2014-08-17 20:12:17 +02:00
var name = request . Command ;
2013-08-28 06:16:21 +02:00
2019-01-13 21:46:33 +01:00
if ( Enum . TryParse ( name , true , out GeneralCommandType commandType ) )
2014-03-31 23:04:22 +02:00
{
2014-08-17 20:12:17 +02:00
name = commandType . ToString ( ) ;
}
2014-03-31 23:04:22 +02:00
2018-09-12 19:26:21 +02:00
var currentSession = GetSession ( _sessionContext ) ;
2014-03-31 23:04:22 +02:00
2014-08-17 20:12:17 +02:00
var command = new GeneralCommand
{
Name = name ,
2018-09-12 19:26:21 +02:00
ControllingUserId = currentSession . UserId
2014-08-17 20:12:17 +02:00
} ;
2014-03-31 23:04:22 +02:00
2018-09-12 19:26:21 +02:00
return _sessionManager . SendGeneralCommand ( currentSession . Id , request . Id , command , CancellationToken . None ) ;
2013-08-28 06:16:21 +02:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2018-09-12 19:26:21 +02:00
public Task Post ( SendMessageCommand request )
2013-08-28 06:16:21 +02:00
{
2013-09-24 21:54:42 +02:00
var command = new MessageCommand
2013-08-28 06:16:21 +02:00
{
2013-09-24 21:54:42 +02:00
Header = string . IsNullOrEmpty ( request . Header ) ? "Message from Server" : request . Header ,
TimeoutMs = request . TimeoutMs ,
Text = request . Text
} ;
2013-08-28 06:16:21 +02:00
2018-09-12 19:26:21 +02:00
return _sessionManager . SendMessageCommand ( GetSession ( _sessionContext ) . Id , request . Id , command , CancellationToken . None ) ;
2013-08-28 06:16:21 +02:00
}
2013-05-28 19:25:10 +02:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2018-09-12 19:26:21 +02:00
public Task Post ( Play request )
2013-05-28 19:25:10 +02:00
{
2018-09-12 19:26:21 +02:00
return _sessionManager . SendPlayCommand ( GetSession ( _sessionContext ) . Id , request . Id , request , CancellationToken . None ) ;
2013-05-28 19:25:10 +02:00
}
2014-01-04 03:35:41 +01:00
2018-09-12 19:26:21 +02:00
public Task Post ( SendGeneralCommand request )
2014-03-31 23:04:22 +02:00
{
2018-09-12 19:26:21 +02:00
var currentSession = GetSession ( _sessionContext ) ;
2014-03-31 23:04:22 +02:00
var command = new GeneralCommand
{
Name = request . Command ,
2018-09-12 19:26:21 +02:00
ControllingUserId = currentSession . UserId
2014-03-31 23:04:22 +02:00
} ;
2018-09-12 19:26:21 +02:00
return _sessionManager . SendGeneralCommand ( currentSession . Id , request . Id , command , CancellationToken . None ) ;
2014-03-31 23:04:22 +02:00
}
2018-09-12 19:26:21 +02:00
public Task Post ( SendFullGeneralCommand request )
2014-03-31 23:04:22 +02:00
{
2018-09-12 19:26:21 +02:00
var currentSession = GetSession ( _sessionContext ) ;
2014-03-31 23:04:22 +02:00
2018-09-12 19:26:21 +02:00
request . ControllingUserId = currentSession . UserId ;
2014-03-31 23:04:22 +02:00
2018-09-12 19:26:21 +02:00
return _sessionManager . SendGeneralCommand ( currentSession . Id , request . Id , request , CancellationToken . None ) ;
2014-03-31 23:04:22 +02:00
}
2014-01-04 03:35:41 +01:00
public void Post ( AddUserToSession request )
{
2018-09-12 19:26:21 +02:00
_sessionManager . AddAdditionalUser ( request . Id , new Guid ( request . UserId ) ) ;
2014-01-04 03:35:41 +01:00
}
public void Delete ( RemoveUserFromSession request )
{
2018-09-12 19:26:21 +02:00
_sessionManager . RemoveAdditionalUser ( request . Id , new Guid ( request . UserId ) ) ;
2014-01-04 03:35:41 +01:00
}
2014-01-05 06:34:06 +01:00
public void Post ( PostCapabilities request )
{
2014-04-13 19:27:13 +02:00
if ( string . IsNullOrWhiteSpace ( request . Id ) )
{
2018-09-12 19:26:21 +02:00
request . Id = GetSession ( _sessionContext ) . Id ;
2014-04-13 19:27:13 +02:00
}
2014-10-11 22:38:13 +02:00
_sessionManager . ReportCapabilities ( request . Id , new ClientCapabilities
2014-03-21 04:31:40 +01:00
{
2017-08-19 21:43:35 +02:00
PlayableMediaTypes = SplitValue ( request . PlayableMediaTypes , ',' ) ,
2014-01-05 06:34:06 +01:00
2017-08-19 21:43:35 +02:00
SupportedCommands = SplitValue ( request . SupportedCommands , ',' ) ,
2014-05-17 20:37:40 +02:00
2014-05-18 21:58:42 +02:00
SupportsMediaControl = request . SupportsMediaControl ,
2014-12-13 04:56:30 +01:00
SupportsSync = request . SupportsSync ,
2015-01-20 06:19:13 +01:00
SupportsPersistentIdentifier = request . SupportsPersistentIdentifier
2014-03-21 04:31:40 +01:00
} ) ;
2014-01-05 06:34:06 +01:00
}
2014-12-14 21:01:26 +01:00
public void Post ( PostFullCapabilities request )
{
if ( string . IsNullOrWhiteSpace ( request . Id ) )
{
2018-09-12 19:26:21 +02:00
request . Id = GetSession ( _sessionContext ) . Id ;
2014-12-14 21:01:26 +01:00
}
_sessionManager . ReportCapabilities ( request . Id , request ) ;
}
2013-05-09 19:38:02 +02:00
}
2019-01-13 20:30:41 +01:00
}