2
0

ISessionManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Jellyfin.Data.Events;
  7. using MediaBrowser.Controller.Authentication;
  8. using MediaBrowser.Controller.Library;
  9. using MediaBrowser.Controller.Security;
  10. using MediaBrowser.Model.Dto;
  11. using MediaBrowser.Model.Session;
  12. using MediaBrowser.Model.SyncPlay;
  13. namespace MediaBrowser.Controller.Session
  14. {
  15. /// <summary>
  16. /// Interface ISessionManager.
  17. /// </summary>
  18. public interface ISessionManager
  19. {
  20. /// <summary>
  21. /// Occurs when [playback start].
  22. /// </summary>
  23. event EventHandler<PlaybackProgressEventArgs> PlaybackStart;
  24. /// <summary>
  25. /// Occurs when [playback progress].
  26. /// </summary>
  27. event EventHandler<PlaybackProgressEventArgs> PlaybackProgress;
  28. /// <summary>
  29. /// Occurs when [playback stopped].
  30. /// </summary>
  31. event EventHandler<PlaybackStopEventArgs> PlaybackStopped;
  32. /// <summary>
  33. /// Occurs when [session started].
  34. /// </summary>
  35. event EventHandler<SessionEventArgs> SessionStarted;
  36. /// <summary>
  37. /// Occurs when [session ended].
  38. /// </summary>
  39. event EventHandler<SessionEventArgs> SessionEnded;
  40. event EventHandler<SessionEventArgs> SessionActivity;
  41. /// <summary>
  42. /// Occurs when [session controller connected].
  43. /// </summary>
  44. event EventHandler<SessionEventArgs> SessionControllerConnected;
  45. /// <summary>
  46. /// Occurs when [capabilities changed].
  47. /// </summary>
  48. event EventHandler<SessionEventArgs> CapabilitiesChanged;
  49. /// <summary>
  50. /// Occurs when [authentication failed].
  51. /// </summary>
  52. event EventHandler<GenericEventArgs<AuthenticationRequest>> AuthenticationFailed;
  53. /// <summary>
  54. /// Occurs when [authentication succeeded].
  55. /// </summary>
  56. event EventHandler<GenericEventArgs<AuthenticationResult>> AuthenticationSucceeded;
  57. /// <summary>
  58. /// Gets the sessions.
  59. /// </summary>
  60. /// <value>The sessions.</value>
  61. IEnumerable<SessionInfo> Sessions { get; }
  62. /// <summary>
  63. /// Logs the user activity.
  64. /// </summary>
  65. /// <param name="appName">Type of the client.</param>
  66. /// <param name="appVersion">The app version.</param>
  67. /// <param name="deviceId">The device id.</param>
  68. /// <param name="deviceName">Name of the device.</param>
  69. /// <param name="remoteEndPoint">The remote end point.</param>
  70. /// <param name="user">The user.</param>
  71. SessionInfo LogSessionActivity(string appName, string appVersion, string deviceId, string deviceName, string remoteEndPoint, Jellyfin.Data.Entities.User user);
  72. /// <summary>
  73. /// Used to report that a session controller has connected.
  74. /// </summary>
  75. /// <param name="session">The session.</param>
  76. void OnSessionControllerConnected(SessionInfo session);
  77. void UpdateDeviceName(string sessionId, string reportedDeviceName);
  78. /// <summary>
  79. /// Used to report that playback has started for an item.
  80. /// </summary>
  81. /// <param name="info">The info.</param>
  82. /// <returns>Task.</returns>
  83. Task OnPlaybackStart(PlaybackStartInfo info);
  84. /// <summary>
  85. /// Used to report playback progress for an item.
  86. /// </summary>
  87. /// <param name="info">The info.</param>
  88. /// <returns>Task.</returns>
  89. /// <exception cref="ArgumentNullException"></exception>
  90. Task OnPlaybackProgress(PlaybackProgressInfo info);
  91. Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated);
  92. /// <summary>
  93. /// Used to report that playback has ended for an item.
  94. /// </summary>
  95. /// <param name="info">The info.</param>
  96. /// <returns>Task.</returns>
  97. /// <exception cref="ArgumentNullException"></exception>
  98. Task OnPlaybackStopped(PlaybackStopInfo info);
  99. /// <summary>
  100. /// Reports the session ended.
  101. /// </summary>
  102. /// <param name="sessionId">The session identifier.</param>
  103. /// <returns>Task.</returns>
  104. void ReportSessionEnded(string sessionId);
  105. /// <summary>
  106. /// Sends the general command.
  107. /// </summary>
  108. /// <param name="controllingSessionId">The controlling session identifier.</param>
  109. /// <param name="sessionId">The session identifier.</param>
  110. /// <param name="command">The command.</param>
  111. /// <param name="cancellationToken">The cancellation token.</param>
  112. /// <returns>Task.</returns>
  113. Task SendGeneralCommand(string controllingSessionId, string sessionId, GeneralCommand command, CancellationToken cancellationToken);
  114. /// <summary>
  115. /// Sends the message command.
  116. /// </summary>
  117. /// <param name="controllingSessionId">The controlling session identifier.</param>
  118. /// <param name="sessionId">The session id.</param>
  119. /// <param name="command">The command.</param>
  120. /// <param name="cancellationToken">The cancellation token.</param>
  121. /// <returns>Task.</returns>
  122. Task SendMessageCommand(string controllingSessionId, string sessionId, MessageCommand command, CancellationToken cancellationToken);
  123. /// <summary>
  124. /// Sends the play command.
  125. /// </summary>
  126. /// <param name="controllingSessionId">The controlling session identifier.</param>
  127. /// <param name="sessionId">The session id.</param>
  128. /// <param name="command">The command.</param>
  129. /// <param name="cancellationToken">The cancellation token.</param>
  130. /// <returns>Task.</returns>
  131. Task SendPlayCommand(string controllingSessionId, string sessionId, PlayRequest command, CancellationToken cancellationToken);
  132. /// <summary>
  133. /// Sends a SyncPlayCommand to a session.
  134. /// </summary>
  135. /// <param name="session">The session.</param>
  136. /// <param name="command">The command.</param>
  137. /// <param name="cancellationToken">The cancellation token.</param>
  138. /// <returns>Task.</returns>
  139. Task SendSyncPlayCommand(SessionInfo session, SendCommand command, CancellationToken cancellationToken);
  140. /// <summary>
  141. /// Sends a SyncPlayGroupUpdate to a session.
  142. /// </summary>
  143. /// <param name="session">The session.</param>
  144. /// <param name="command">The group update.</param>
  145. /// <param name="cancellationToken">The cancellation token.</param>
  146. /// <returns>Task.</returns>
  147. Task SendSyncPlayGroupUpdate<T>(SessionInfo session, GroupUpdate<T> command, CancellationToken cancellationToken);
  148. /// <summary>
  149. /// Sends the browse command.
  150. /// </summary>
  151. /// <param name="controllingSessionId">The controlling session identifier.</param>
  152. /// <param name="sessionId">The session id.</param>
  153. /// <param name="command">The command.</param>
  154. /// <param name="cancellationToken">The cancellation token.</param>
  155. /// <returns>Task.</returns>
  156. Task SendBrowseCommand(string controllingSessionId, string sessionId, BrowseRequest command, CancellationToken cancellationToken);
  157. /// <summary>
  158. /// Sends the playstate command.
  159. /// </summary>
  160. /// <param name="controllingSessionId">The controlling session identifier.</param>
  161. /// <param name="sessionId">The session id.</param>
  162. /// <param name="command">The command.</param>
  163. /// <param name="cancellationToken">The cancellation token.</param>
  164. /// <returns>Task.</returns>
  165. Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken);
  166. /// <summary>
  167. /// Sends the message to admin sessions.
  168. /// </summary>
  169. /// <typeparam name="T"></typeparam>
  170. /// <param name="name">The name.</param>
  171. /// <param name="data">The data.</param>
  172. /// <param name="cancellationToken">The cancellation token.</param>
  173. /// <returns>Task.</returns>
  174. Task SendMessageToAdminSessions<T>(SessionMessageType name, T data, CancellationToken cancellationToken);
  175. /// <summary>
  176. /// Sends the message to user sessions.
  177. /// </summary>
  178. /// <typeparam name="T"></typeparam>
  179. /// <returns>Task.</returns>
  180. Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, T data, CancellationToken cancellationToken);
  181. Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, Func<T> dataFn, CancellationToken cancellationToken);
  182. /// <summary>
  183. /// Sends the message to user device sessions.
  184. /// </summary>
  185. /// <typeparam name="T"></typeparam>
  186. /// <param name="deviceId">The device identifier.</param>
  187. /// <param name="name">The name.</param>
  188. /// <param name="data">The data.</param>
  189. /// <param name="cancellationToken">The cancellation token.</param>
  190. /// <returns>Task.</returns>
  191. Task SendMessageToUserDeviceSessions<T>(string deviceId, SessionMessageType name, T data, CancellationToken cancellationToken);
  192. /// <summary>
  193. /// Sends the restart required message.
  194. /// </summary>
  195. /// <param name="cancellationToken">The cancellation token.</param>
  196. /// <returns>Task.</returns>
  197. Task SendRestartRequiredNotification(CancellationToken cancellationToken);
  198. /// <summary>
  199. /// Sends the server shutdown notification.
  200. /// </summary>
  201. /// <param name="cancellationToken">The cancellation token.</param>
  202. /// <returns>Task.</returns>
  203. Task SendServerShutdownNotification(CancellationToken cancellationToken);
  204. /// <summary>
  205. /// Sends the server restart notification.
  206. /// </summary>
  207. /// <param name="cancellationToken">The cancellation token.</param>
  208. /// <returns>Task.</returns>
  209. Task SendServerRestartNotification(CancellationToken cancellationToken);
  210. /// <summary>
  211. /// Adds the additional user.
  212. /// </summary>
  213. /// <param name="sessionId">The session identifier.</param>
  214. /// <param name="userId">The user identifier.</param>
  215. void AddAdditionalUser(string sessionId, Guid userId);
  216. /// <summary>
  217. /// Removes the additional user.
  218. /// </summary>
  219. /// <param name="sessionId">The session identifier.</param>
  220. /// <param name="userId">The user identifier.</param>
  221. void RemoveAdditionalUser(string sessionId, Guid userId);
  222. /// <summary>
  223. /// Reports the now viewing item.
  224. /// </summary>
  225. /// <param name="sessionId">The session identifier.</param>
  226. /// <param name="itemId">The item identifier.</param>
  227. void ReportNowViewingItem(string sessionId, string itemId);
  228. /// <summary>
  229. /// Reports the now viewing item.
  230. /// </summary>
  231. /// <param name="sessionId">The session identifier.</param>
  232. /// <param name="item">The item.</param>
  233. void ReportNowViewingItem(string sessionId, BaseItemDto item);
  234. /// <summary>
  235. /// Authenticates the new session.
  236. /// </summary>
  237. /// <param name="request">The request.</param>
  238. /// <returns>Task{SessionInfo}.</returns>
  239. Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request);
  240. /// <summary>
  241. /// Authenticates a new session with quick connect.
  242. /// </summary>
  243. /// <param name="request">The request.</param>
  244. /// <param name="token">Quick connect access token.</param>
  245. /// <returns>Task{SessionInfo}.</returns>
  246. Task<AuthenticationResult> AuthenticateQuickConnect(AuthenticationRequest request, string token);
  247. /// <summary>
  248. /// Creates the new session.
  249. /// </summary>
  250. /// <param name="request">The request.</param>
  251. /// <returns>Task&lt;AuthenticationResult&gt;.</returns>
  252. Task<AuthenticationResult> CreateNewSession(AuthenticationRequest request);
  253. /// <summary>
  254. /// Reports the capabilities.
  255. /// </summary>
  256. /// <param name="sessionId">The session identifier.</param>
  257. /// <param name="capabilities">The capabilities.</param>
  258. void ReportCapabilities(string sessionId, ClientCapabilities capabilities);
  259. /// <summary>
  260. /// Reports the transcoding information.
  261. /// </summary>
  262. /// <param name="deviceId">The device identifier.</param>
  263. /// <param name="info">The information.</param>
  264. void ReportTranscodingInfo(string deviceId, TranscodingInfo info);
  265. /// <summary>
  266. /// Clears the transcoding information.
  267. /// </summary>
  268. /// <param name="deviceId">The device identifier.</param>
  269. void ClearTranscodingInfo(string deviceId);
  270. /// <summary>
  271. /// Gets the session.
  272. /// </summary>
  273. /// <param name="deviceId">The device identifier.</param>
  274. /// <param name="client">The client.</param>
  275. /// <param name="version">The version.</param>
  276. /// <returns>SessionInfo.</returns>
  277. SessionInfo GetSession(string deviceId, string client, string version);
  278. /// <summary>
  279. /// Gets the session by authentication token.
  280. /// </summary>
  281. /// <param name="token">The token.</param>
  282. /// <param name="deviceId">The device identifier.</param>
  283. /// <param name="remoteEndpoint">The remote endpoint.</param>
  284. /// <returns>SessionInfo.</returns>
  285. SessionInfo GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint);
  286. /// <summary>
  287. /// Gets the session by authentication token.
  288. /// </summary>
  289. /// <param name="info">The information.</param>
  290. /// <param name="deviceId">The device identifier.</param>
  291. /// <param name="remoteEndpoint">The remote endpoint.</param>
  292. /// <param name="appVersion">The application version.</param>
  293. /// <returns>Task&lt;SessionInfo&gt;.</returns>
  294. SessionInfo GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion);
  295. /// <summary>
  296. /// Logouts the specified access token.
  297. /// </summary>
  298. /// <param name="accessToken">The access token.</param>
  299. /// <returns>Task.</returns>
  300. void Logout(string accessToken);
  301. void Logout(AuthenticationInfo accessToken);
  302. /// <summary>
  303. /// Revokes the user tokens.
  304. /// </summary>
  305. /// <returns>Task.</returns>
  306. void RevokeUserTokens(Guid userId, string currentAccessToken);
  307. /// <summary>
  308. /// Revokes the token.
  309. /// </summary>
  310. /// <param name="id">The identifier.</param>
  311. /// <returns>Task.</returns>
  312. void RevokeToken(string id);
  313. void CloseIfNeeded(SessionInfo session);
  314. }
  315. }