ISessionManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using MediaBrowser.Controller.Authentication;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Security;
  5. using MediaBrowser.Model.Dto;
  6. using MediaBrowser.Model.Events;
  7. using MediaBrowser.Model.Session;
  8. using MediaBrowser.Model.Users;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  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 [capabilities changed].
  43. /// </summary>
  44. event EventHandler<SessionEventArgs> CapabilitiesChanged;
  45. /// <summary>
  46. /// Occurs when [authentication failed].
  47. /// </summary>
  48. event EventHandler<GenericEventArgs<AuthenticationRequest>> AuthenticationFailed;
  49. /// <summary>
  50. /// Occurs when [authentication succeeded].
  51. /// </summary>
  52. event EventHandler<GenericEventArgs<AuthenticationResult>> AuthenticationSucceeded;
  53. /// <summary>
  54. /// Gets the sessions.
  55. /// </summary>
  56. /// <value>The sessions.</value>
  57. IEnumerable<SessionInfo> Sessions { get; }
  58. /// <summary>
  59. /// Logs the user activity.
  60. /// </summary>
  61. /// <param name="appName">Type of the client.</param>
  62. /// <param name="appVersion">The app version.</param>
  63. /// <param name="deviceId">The device id.</param>
  64. /// <param name="deviceName">Name of the device.</param>
  65. /// <param name="remoteEndPoint">The remote end point.</param>
  66. /// <param name="user">The user.</param>
  67. SessionInfo LogSessionActivity(string appName, string appVersion, string deviceId, string deviceName, string remoteEndPoint, User user);
  68. void UpdateDeviceName(string sessionId, string reportedDeviceName);
  69. /// <summary>
  70. /// Used to report that playback has started for an item
  71. /// </summary>
  72. /// <param name="info">The info.</param>
  73. /// <returns>Task.</returns>
  74. Task OnPlaybackStart(PlaybackStartInfo info);
  75. /// <summary>
  76. /// Used to report playback progress for an item
  77. /// </summary>
  78. /// <param name="info">The info.</param>
  79. /// <returns>Task.</returns>
  80. /// <exception cref="System.ArgumentNullException"></exception>
  81. Task OnPlaybackProgress(PlaybackProgressInfo info);
  82. Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated);
  83. /// <summary>
  84. /// Used to report that playback has ended for an item
  85. /// </summary>
  86. /// <param name="info">The info.</param>
  87. /// <returns>Task.</returns>
  88. /// <exception cref="System.ArgumentNullException"></exception>
  89. Task OnPlaybackStopped(PlaybackStopInfo info);
  90. /// <summary>
  91. /// Reports the session ended.
  92. /// </summary>
  93. /// <param name="sessionId">The session identifier.</param>
  94. /// <returns>Task.</returns>
  95. void ReportSessionEnded(string sessionId);
  96. /// <summary>
  97. /// Sends the general command.
  98. /// </summary>
  99. /// <param name="controllingSessionId">The controlling session identifier.</param>
  100. /// <param name="sessionId">The session identifier.</param>
  101. /// <param name="command">The command.</param>
  102. /// <param name="cancellationToken">The cancellation token.</param>
  103. /// <returns>Task.</returns>
  104. Task SendGeneralCommand(string controllingSessionId, string sessionId, GeneralCommand command, CancellationToken cancellationToken);
  105. /// <summary>
  106. /// Sends the message command.
  107. /// </summary>
  108. /// <param name="controllingSessionId">The controlling session identifier.</param>
  109. /// <param name="sessionId">The session id.</param>
  110. /// <param name="command">The command.</param>
  111. /// <param name="cancellationToken">The cancellation token.</param>
  112. /// <returns>Task.</returns>
  113. Task SendMessageCommand(string controllingSessionId, string sessionId, MessageCommand command, CancellationToken cancellationToken);
  114. /// <summary>
  115. /// Sends the play 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 SendPlayCommand(string controllingSessionId, string sessionId, PlayRequest command, CancellationToken cancellationToken);
  123. /// <summary>
  124. /// Sends the browse 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 SendBrowseCommand(string controllingSessionId, string sessionId, BrowseRequest command, CancellationToken cancellationToken);
  132. /// <summary>
  133. /// Sends the playstate command.
  134. /// </summary>
  135. /// <param name="controllingSessionId">The controlling session identifier.</param>
  136. /// <param name="sessionId">The session id.</param>
  137. /// <param name="command">The command.</param>
  138. /// <param name="cancellationToken">The cancellation token.</param>
  139. /// <returns>Task.</returns>
  140. Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken);
  141. /// <summary>
  142. /// Sends the message to admin sessions.
  143. /// </summary>
  144. /// <typeparam name="T"></typeparam>
  145. /// <param name="name">The name.</param>
  146. /// <param name="data">The data.</param>
  147. /// <param name="cancellationToken">The cancellation token.</param>
  148. /// <returns>Task.</returns>
  149. Task SendMessageToAdminSessions<T>(string name, T data, CancellationToken cancellationToken);
  150. /// <summary>
  151. /// Sends the message to user sessions.
  152. /// </summary>
  153. /// <typeparam name="T"></typeparam>
  154. /// <returns>Task.</returns>
  155. Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, T data, CancellationToken cancellationToken);
  156. Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, Func<T> dataFn, CancellationToken cancellationToken);
  157. /// <summary>
  158. /// Sends the message to user device sessions.
  159. /// </summary>
  160. /// <typeparam name="T"></typeparam>
  161. /// <param name="deviceId">The device identifier.</param>
  162. /// <param name="name">The name.</param>
  163. /// <param name="data">The data.</param>
  164. /// <param name="cancellationToken">The cancellation token.</param>
  165. /// <returns>Task.</returns>
  166. Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data, CancellationToken cancellationToken);
  167. /// <summary>
  168. /// Sends the restart required message.
  169. /// </summary>
  170. /// <param name="cancellationToken">The cancellation token.</param>
  171. /// <returns>Task.</returns>
  172. Task SendRestartRequiredNotification(CancellationToken cancellationToken);
  173. /// <summary>
  174. /// Sends the server shutdown notification.
  175. /// </summary>
  176. /// <param name="cancellationToken">The cancellation token.</param>
  177. /// <returns>Task.</returns>
  178. Task SendServerShutdownNotification(CancellationToken cancellationToken);
  179. /// <summary>
  180. /// Sends the server restart notification.
  181. /// </summary>
  182. /// <param name="cancellationToken">The cancellation token.</param>
  183. /// <returns>Task.</returns>
  184. Task SendServerRestartNotification(CancellationToken cancellationToken);
  185. /// <summary>
  186. /// Adds the additional user.
  187. /// </summary>
  188. /// <param name="sessionId">The session identifier.</param>
  189. /// <param name="userId">The user identifier.</param>
  190. void AddAdditionalUser(string sessionId, Guid userId);
  191. /// <summary>
  192. /// Removes the additional user.
  193. /// </summary>
  194. /// <param name="sessionId">The session identifier.</param>
  195. /// <param name="userId">The user identifier.</param>
  196. void RemoveAdditionalUser(string sessionId, Guid userId);
  197. /// <summary>
  198. /// Reports the now viewing item.
  199. /// </summary>
  200. /// <param name="sessionId">The session identifier.</param>
  201. /// <param name="itemId">The item identifier.</param>
  202. void ReportNowViewingItem(string sessionId, string itemId);
  203. /// <summary>
  204. /// Reports the now viewing item.
  205. /// </summary>
  206. /// <param name="sessionId">The session identifier.</param>
  207. /// <param name="item">The item.</param>
  208. void ReportNowViewingItem(string sessionId, BaseItemDto item);
  209. /// <summary>
  210. /// Authenticates the new session.
  211. /// </summary>
  212. /// <param name="request">The request.</param>
  213. /// <returns>Task{SessionInfo}.</returns>
  214. Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request);
  215. /// <summary>
  216. /// Creates the new session.
  217. /// </summary>
  218. /// <param name="request">The request.</param>
  219. /// <returns>Task&lt;AuthenticationResult&gt;.</returns>
  220. Task<AuthenticationResult> CreateNewSession(AuthenticationRequest request);
  221. /// <summary>
  222. /// Reports the capabilities.
  223. /// </summary>
  224. /// <param name="sessionId">The session identifier.</param>
  225. /// <param name="capabilities">The capabilities.</param>
  226. void ReportCapabilities(string sessionId, ClientCapabilities capabilities);
  227. /// <summary>
  228. /// Reports the transcoding information.
  229. /// </summary>
  230. /// <param name="deviceId">The device identifier.</param>
  231. /// <param name="info">The information.</param>
  232. void ReportTranscodingInfo(string deviceId, TranscodingInfo info);
  233. /// <summary>
  234. /// Clears the transcoding information.
  235. /// </summary>
  236. /// <param name="deviceId">The device identifier.</param>
  237. void ClearTranscodingInfo(string deviceId);
  238. /// <summary>
  239. /// Gets the session.
  240. /// </summary>
  241. /// <param name="deviceId">The device identifier.</param>
  242. /// <param name="client">The client.</param>
  243. /// <param name="version">The version.</param>
  244. /// <returns>SessionInfo.</returns>
  245. SessionInfo GetSession(string deviceId, string client, string version);
  246. /// <summary>
  247. /// Gets the session by authentication token.
  248. /// </summary>
  249. /// <param name="token">The token.</param>
  250. /// <param name="deviceId">The device identifier.</param>
  251. /// <param name="remoteEndpoint">The remote endpoint.</param>
  252. /// <returns>SessionInfo.</returns>
  253. SessionInfo GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint);
  254. /// <summary>
  255. /// Gets the session by authentication token.
  256. /// </summary>
  257. /// <param name="info">The information.</param>
  258. /// <param name="deviceId">The device identifier.</param>
  259. /// <param name="remoteEndpoint">The remote endpoint.</param>
  260. /// <param name="appVersion">The application version.</param>
  261. /// <returns>Task&lt;SessionInfo&gt;.</returns>
  262. SessionInfo GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion);
  263. /// <summary>
  264. /// Logouts the specified access token.
  265. /// </summary>
  266. /// <param name="accessToken">The access token.</param>
  267. /// <returns>Task.</returns>
  268. void Logout(string accessToken);
  269. void Logout(AuthenticationInfo accessToken);
  270. /// <summary>
  271. /// Revokes the user tokens.
  272. /// </summary>
  273. /// <returns>Task.</returns>
  274. void RevokeUserTokens(Guid userId, string currentAccessToken);
  275. /// <summary>
  276. /// Revokes the token.
  277. /// </summary>
  278. /// <param name="id">The identifier.</param>
  279. /// <returns>Task.</returns>
  280. void RevokeToken(string id);
  281. void CloseIfNeeded(SessionInfo session);
  282. }
  283. }