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