IGroupStateContext.cs 9.0 KB

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