ISessionManager.cs 15 KB

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