IGroupStateContext.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. /// <param name="from">The current session.</param>
  60. /// <param name="type">The filtering type.</param>
  61. /// <param name="message">The message to send.</param>
  62. /// <param name="cancellationToken">The cancellation token.</param>
  63. /// <typeparam name="T">The group update type.</typeparam>
  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. /// Sanitizes the PositionTicks, considers the current playing item when available.
  83. /// </summary>
  84. /// <param name="positionTicks">The PositionTicks.</param>
  85. /// <returns>The sanitized position ticks.</returns>
  86. long SanitizePositionTicks(long? positionTicks);
  87. /// <summary>
  88. /// Updates the ping of a session, in milliseconds.
  89. /// </summary>
  90. /// <param name="session">The session.</param>
  91. /// <param name="ping">The ping, in milliseconds.</param>
  92. void UpdatePing(SessionInfo session, long ping);
  93. /// <summary>
  94. /// Gets the highest ping in the group, in milliseconds.
  95. /// </summary>
  96. /// <returns>The highest ping in the group.</returns>
  97. long GetHighestPing();
  98. /// <summary>
  99. /// Sets the session's buffering state.
  100. /// </summary>
  101. /// <param name="session">The session.</param>
  102. /// <param name="isBuffering">The state.</param>
  103. void SetBuffering(SessionInfo session, bool isBuffering);
  104. /// <summary>
  105. /// Sets the buffering state of all the sessions.
  106. /// </summary>
  107. /// <param name="isBuffering">The state.</param>
  108. void SetAllBuffering(bool isBuffering);
  109. /// <summary>
  110. /// Gets the group buffering state.
  111. /// </summary>
  112. /// <returns><c>true</c> if there is a session buffering in the group; <c>false</c> otherwise.</returns>
  113. bool IsBuffering();
  114. /// <summary>
  115. /// Sets the session's group wait state.
  116. /// </summary>
  117. /// <param name="session">The session.</param>
  118. /// <param name="ignoreGroupWait">The state.</param>
  119. void SetIgnoreGroupWait(SessionInfo session, bool ignoreGroupWait);
  120. /// <summary>
  121. /// Sets a new play queue.
  122. /// </summary>
  123. /// <param name="playQueue">The new play queue.</param>
  124. /// <param name="playingItemPosition">The playing item position in the play queue.</param>
  125. /// <param name="startPositionTicks">The start position ticks.</param>
  126. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  127. bool SetPlayQueue(IReadOnlyList<Guid> playQueue, int playingItemPosition, long startPositionTicks);
  128. /// <summary>
  129. /// Sets the playing item.
  130. /// </summary>
  131. /// <param name="playlistItemId">The new playing item identifier.</param>
  132. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  133. bool SetPlayingItem(Guid playlistItemId);
  134. /// <summary>
  135. /// Clears the play queue.
  136. /// </summary>
  137. /// <param name="clearPlayingItem">Whether to remove the playing item as well.</param>
  138. void ClearPlayQueue(bool clearPlayingItem);
  139. /// <summary>
  140. /// Removes items from the play queue.
  141. /// </summary>
  142. /// <param name="playlistItemIds">The items to remove.</param>
  143. /// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns>
  144. bool RemoveFromPlayQueue(IReadOnlyList<Guid> playlistItemIds);
  145. /// <summary>
  146. /// Moves an item in the play queue.
  147. /// </summary>
  148. /// <param name="playlistItemId">The playlist identifier of the item to move.</param>
  149. /// <param name="newIndex">The new position.</param>
  150. /// <returns><c>true</c> if item has been moved; <c>false</c> if something went wrong.</returns>
  151. bool MoveItemInPlayQueue(Guid playlistItemId, int newIndex);
  152. /// <summary>
  153. /// Updates the play queue.
  154. /// </summary>
  155. /// <param name="newItems">The new items to add to the play queue.</param>
  156. /// <param name="mode">The mode with which the items will be added.</param>
  157. /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
  158. bool AddToPlayQueue(IReadOnlyList<Guid> newItems, GroupQueueMode mode);
  159. /// <summary>
  160. /// Restarts current item in play queue.
  161. /// </summary>
  162. void RestartCurrentItem();
  163. /// <summary>
  164. /// Picks next item in play queue.
  165. /// </summary>
  166. /// <returns><c>true</c> if the item changed; <c>false</c> otherwise.</returns>
  167. bool NextItemInQueue();
  168. /// <summary>
  169. /// Picks previous item in play queue.
  170. /// </summary>
  171. /// <returns><c>true</c> if the item changed; <c>false</c> otherwise.</returns>
  172. bool PreviousItemInQueue();
  173. /// <summary>
  174. /// Sets the repeat mode.
  175. /// </summary>
  176. /// <param name="mode">The new mode.</param>
  177. void SetRepeatMode(GroupRepeatMode mode);
  178. /// <summary>
  179. /// Sets the shuffle mode.
  180. /// </summary>
  181. /// <param name="mode">The new mode.</param>
  182. void SetShuffleMode(GroupShuffleMode mode);
  183. /// <summary>
  184. /// Creates a play queue update.
  185. /// </summary>
  186. /// <param name="reason">The reason for the update.</param>
  187. /// <returns>The play queue update.</returns>
  188. PlayQueueUpdate GetPlayQueueUpdate(PlayQueueUpdateReason reason);
  189. }
  190. }