IGroupStateContext.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #nullable disable
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Controller.Session;
  7. using MediaBrowser.Controller.SyncPlay.Queue;
  8. using MediaBrowser.Model.SyncPlay;
  9. namespace MediaBrowser.Controller.SyncPlay
  10. {
  11. /// <summary>
  12. /// Interface IGroupStateContext.
  13. /// </summary>
  14. public interface IGroupStateContext
  15. {
  16. /// <summary>
  17. /// Gets the default ping value used for sessions, in milliseconds.
  18. /// </summary>
  19. /// <value>The default ping value used for sessions, in milliseconds.</value>
  20. long DefaultPing { get; }
  21. /// <summary>
  22. /// Gets the maximum time offset error accepted for dates reported by clients, in milliseconds.
  23. /// </summary>
  24. /// <value>The maximum offset error accepted, in milliseconds.</value>
  25. long TimeSyncOffset { get; }
  26. /// <summary>
  27. /// Gets the maximum offset error accepted for position reported by clients, in milliseconds.
  28. /// </summary>
  29. /// <value>The maximum offset error accepted, in milliseconds.</value>
  30. long MaxPlaybackOffset { get; }
  31. /// <summary>
  32. /// Gets the group identifier.
  33. /// </summary>
  34. /// <value>The group identifier.</value>
  35. Guid GroupId { get; }
  36. /// <summary>
  37. /// Gets or sets the position ticks.
  38. /// </summary>
  39. /// <value>The position ticks.</value>
  40. long PositionTicks { get; set; }
  41. /// <summary>
  42. /// Gets or sets the last activity.
  43. /// </summary>
  44. /// <value>The last activity.</value>
  45. DateTime LastActivity { get; set; }
  46. /// <summary>
  47. /// Gets the play queue.
  48. /// </summary>
  49. /// <value>The play queue.</value>
  50. PlayQueueManager PlayQueue { get; }
  51. /// <summary>
  52. /// Sets a new state.
  53. /// </summary>
  54. /// <param name="state">The new state.</param>
  55. void SetState(IGroupState state);
  56. /// <summary>
  57. /// Sends a GroupUpdate message to the interested sessions.
  58. /// </summary>
  59. /// <typeparam name="T">The type of the data of the message.</typeparam>
  60. /// <param name="from">The current session.</param>
  61. /// <param name="type">The filtering type.</param>
  62. /// <param name="message">The message to send.</param>
  63. /// <param name="cancellationToken">The cancellation token.</param>
  64. /// <returns>The task.</returns>
  65. Task SendGroupUpdate<T>(SessionInfo from, SyncPlayBroadcastType type, GroupUpdate<T> message, CancellationToken cancellationToken);
  66. /// <summary>
  67. /// Sends a playback command to the interested sessions.
  68. /// </summary>
  69. /// <param name="from">The current session.</param>
  70. /// <param name="type">The filtering type.</param>
  71. /// <param name="message">The message to send.</param>
  72. /// <param name="cancellationToken">The cancellation token.</param>
  73. /// <returns>The task.</returns>
  74. Task SendCommand(SessionInfo from, SyncPlayBroadcastType type, SendCommand message, CancellationToken cancellationToken);
  75. /// <summary>
  76. /// Builds a new playback command with some default values.
  77. /// </summary>
  78. /// <param name="type">The command type.</param>
  79. /// <returns>The command.</returns>
  80. SendCommand NewSyncPlayCommand(SendCommandType type);
  81. /// <summary>
  82. /// Builds a new group update message.
  83. /// </summary>
  84. /// <typeparam name="T">The type of the data of the message.</typeparam>
  85. /// <param name="type">The update type.</param>
  86. /// <param name="data">The data to send.</param>
  87. /// <returns>The group update.</returns>
  88. GroupUpdate<T> NewSyncPlayGroupUpdate<T>(GroupUpdateType type, T data);
  89. /// <summary>
  90. /// Sanitizes the PositionTicks, considers the current playing item when available.
  91. /// </summary>
  92. /// <param name="positionTicks">The PositionTicks.</param>
  93. /// <returns>The sanitized position ticks.</returns>
  94. long SanitizePositionTicks(long? positionTicks);
  95. /// <summary>
  96. /// Updates the ping of a session, in milliseconds.
  97. /// </summary>
  98. /// <param name="session">The session.</param>
  99. /// <param name="ping">The ping, in milliseconds.</param>
  100. void UpdatePing(SessionInfo session, long ping);
  101. /// <summary>
  102. /// Gets the highest ping in the group, in milliseconds.
  103. /// </summary>
  104. /// <returns>The highest ping in the group.</returns>
  105. long GetHighestPing();
  106. /// <summary>
  107. /// Sets the session's buffering state.
  108. /// </summary>
  109. /// <param name="session">The session.</param>
  110. /// <param name="isBuffering">The state.</param>
  111. void SetBuffering(SessionInfo session, bool isBuffering);
  112. /// <summary>
  113. /// Sets the buffering state of all the sessions.
  114. /// </summary>
  115. /// <param name="isBuffering">The state.</param>
  116. void SetAllBuffering(bool isBuffering);
  117. /// <summary>
  118. /// Gets the group buffering state.
  119. /// </summary>
  120. /// <returns><c>true</c> if there is a session buffering in the group; <c>false</c> otherwise.</returns>
  121. bool IsBuffering();
  122. /// <summary>
  123. /// Sets the session's group wait state.
  124. /// </summary>
  125. /// <param name="session">The session.</param>
  126. /// <param name="ignoreGroupWait">The state.</param>
  127. void SetIgnoreGroupWait(SessionInfo session, bool ignoreGroupWait);
  128. /// <summary>
  129. /// Sets a new play queue.
  130. /// </summary>
  131. /// <param name="playQueue">The new play queue.</param>
  132. /// <param name="playingItemPosition">The playing item position in the play queue.</param>
  133. /// <param name="startPositionTicks">The start position ticks.</param>
  134. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  135. bool SetPlayQueue(IReadOnlyList<Guid> playQueue, int playingItemPosition, long startPositionTicks);
  136. /// <summary>
  137. /// Sets the playing item.
  138. /// </summary>
  139. /// <param name="playlistItemId">The new playing item identifier.</param>
  140. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  141. bool SetPlayingItem(Guid playlistItemId);
  142. /// <summary>
  143. /// Removes items from the play queue.
  144. /// </summary>
  145. /// <param name="playlistItemIds">The items to remove.</param>
  146. /// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns>
  147. bool RemoveFromPlayQueue(IReadOnlyList<Guid> playlistItemIds);
  148. /// <summary>
  149. /// Moves an item in the play queue.
  150. /// </summary>
  151. /// <param name="playlistItemId">The playlist identifier of the item to move.</param>
  152. /// <param name="newIndex">The new position.</param>
  153. /// <returns><c>true</c> if item has been moved; <c>false</c> if something went wrong.</returns>
  154. bool MoveItemInPlayQueue(Guid playlistItemId, int newIndex);
  155. /// <summary>
  156. /// Updates the play queue.
  157. /// </summary>
  158. /// <param name="newItems">The new items to add to the play queue.</param>
  159. /// <param name="mode">The mode with which the items will be added.</param>
  160. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  161. bool AddToPlayQueue(IReadOnlyList<Guid> newItems, GroupQueueMode mode);
  162. /// <summary>
  163. /// Restarts current item in play queue.
  164. /// </summary>
  165. void RestartCurrentItem();
  166. /// <summary>
  167. /// Picks next item in play queue.
  168. /// </summary>
  169. /// <returns><c>true</c> if the item changed; <c>false</c> otherwise.</returns>
  170. bool NextItemInQueue();
  171. /// <summary>
  172. /// Picks previous item in play queue.
  173. /// </summary>
  174. /// <returns><c>true</c> if the item changed; <c>false</c> otherwise.</returns>
  175. bool PreviousItemInQueue();
  176. /// <summary>
  177. /// Sets the repeat mode.
  178. /// </summary>
  179. /// <param name="mode">The new mode.</param>
  180. void SetRepeatMode(GroupRepeatMode mode);
  181. /// <summary>
  182. /// Sets the shuffle mode.
  183. /// </summary>
  184. /// <param name="mode">The new mode.</param>
  185. void SetShuffleMode(GroupShuffleMode mode);
  186. /// <summary>
  187. /// Creates a play queue update.
  188. /// </summary>
  189. /// <param name="reason">The reason for the update.</param>
  190. /// <returns>The play queue update.</returns>
  191. PlayQueueUpdate GetPlayQueueUpdate(PlayQueueUpdateReason reason);
  192. }
  193. }