ISessionManager.cs 15 KB

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