IGroupStateContext.cs 8.8 KB

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