@applicaster/quick-brick-player 16.0.0-alpha.4065452341 → 16.0.0-alpha.4155601029

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-player",
3
- "version": "16.0.0-alpha.4065452341",
3
+ "version": "16.0.0-alpha.4155601029",
4
4
  "description": "Quick Brick Player",
5
5
  "main": "./src/index.ts",
6
6
  "types": "index.d.ts",
@@ -35,11 +35,11 @@
35
35
  },
36
36
  "homepage": "https://github.com/applicaster/quickbrick#readme",
37
37
  "dependencies": {
38
- "@applicaster/quick-brick-mobile-transport-controls": "16.0.0-rc.73",
39
- "@applicaster/quick-brick-tv-transport-controls": "16.0.0-rc.69",
40
- "@applicaster/zapp-react-native-tvos-app": "16.0.0-alpha.4065452341",
41
- "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.4065452341",
42
- "@applicaster/zapp-react-native-utils": "16.0.0-alpha.4065452341",
38
+ "@applicaster/quick-brick-mobile-transport-controls": "16.0.0-rc.127",
39
+ "@applicaster/quick-brick-tv-transport-controls": "16.0.0-rc.127",
40
+ "@applicaster/zapp-react-native-tvos-app": "16.0.0-alpha.4155601029",
41
+ "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.4155601029",
42
+ "@applicaster/zapp-react-native-utils": "16.0.0-alpha.4155601029",
43
43
  "query-string": "7.1.3",
44
44
  "shaka-player": "4.3.5",
45
45
  "typeface-montserrat": "^0.0.54",
@@ -25,7 +25,7 @@ import {
25
25
  } from "./playerActions";
26
26
 
27
27
  const { log_debug } = createLogger({
28
- subsystem: "UIComponent",
28
+ subsystem: "player/audio",
29
29
  category: "AudioPlayerWrapper",
30
30
  });
31
31
 
@@ -0,0 +1,354 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
3
+ import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
4
+ import { loadFeedEntry } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/utils";
5
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
6
+
7
+ const { log_error, log_info } = createLogger({
8
+ subsystem: "player/audio",
9
+ category: "PlaylistNavigationController",
10
+ });
11
+
12
+ export const RESTART_THRESHOLD_SECONDS = 3;
13
+
14
+ export interface PlayerSeeker {
15
+ seekTo: (time: number) => void;
16
+ }
17
+
18
+ export interface PlayerNavigator {
19
+ replaceTop: (entry: ZappEntry) => void;
20
+ }
21
+
22
+ export interface PlaylistNavigationControllerOptions {
23
+ entry: ZappEntry;
24
+ player: PlayerSeeker;
25
+ navigator: PlayerNavigator;
26
+ playerState?: QuickBrickPlayer.PlayerState;
27
+ }
28
+
29
+ export class PlaylistNavigationController {
30
+ public readonly hasNext$: BehaviorSubject<boolean>;
31
+ public readonly hasPrevious$: BehaviorSubject<boolean>;
32
+
33
+ private entry: ZappEntry;
34
+ private player: PlayerSeeker;
35
+ private navigator: PlayerNavigator;
36
+ private playerState: QuickBrickPlayer.PlayerState | undefined;
37
+ private isNavigating = false;
38
+ private unsubscribeQueueListener: (() => void) | null = null;
39
+ private isDestroyed = false;
40
+ private recalculateGeneration = 0;
41
+
42
+ constructor(options: PlaylistNavigationControllerOptions) {
43
+ this.entry = options.entry;
44
+ this.player = options.player;
45
+ this.navigator = options.navigator;
46
+ this.playerState = options.playerState;
47
+
48
+ const staticNextUrl = this.entry?.extensions?.play_next_feed_url;
49
+ const staticPrevUrl = this.entry?.extensions?.play_previous_feed_url;
50
+ const canRestart = (this.playerState?.seekableDuration ?? 0) > 0;
51
+
52
+ this.hasNext$ = new BehaviorSubject<boolean>(Boolean(staticNextUrl));
53
+
54
+ this.hasPrevious$ = new BehaviorSubject<boolean>(
55
+ Boolean(staticPrevUrl) || canRestart
56
+ );
57
+
58
+ this.subscribeToQueue();
59
+ this.recalculate();
60
+ }
61
+
62
+ public updateContext(
63
+ options: Partial<PlaylistNavigationControllerOptions>
64
+ ): void {
65
+ if (options.player) {
66
+ this.player = options.player;
67
+ }
68
+
69
+ if (options.navigator) {
70
+ this.navigator = options.navigator;
71
+ }
72
+
73
+ let needsRecalculate = false;
74
+
75
+ if (options.entry) {
76
+ const isSameEntry =
77
+ this.entry?.id === options.entry?.id &&
78
+ this.entry?.extensions?.queueItemId ===
79
+ options.entry?.extensions?.queueItemId;
80
+
81
+ if (!isSameEntry) {
82
+ this.entry = options.entry;
83
+ needsRecalculate = true;
84
+ } else {
85
+ this.entry = options.entry;
86
+ }
87
+ }
88
+
89
+ if (options.playerState) {
90
+ const prevCanRestart = (this.playerState?.seekableDuration ?? 0) > 0;
91
+ const newCanRestart = (options.playerState?.seekableDuration ?? 0) > 0;
92
+ this.playerState = options.playerState;
93
+
94
+ if (prevCanRestart !== newCanRestart) {
95
+ needsRecalculate = true;
96
+ }
97
+ }
98
+
99
+ if (needsRecalculate) {
100
+ this.recalculate();
101
+ }
102
+ }
103
+
104
+ public updatePlayerState(playerState?: QuickBrickPlayer.PlayerState): void {
105
+ const prevCanRestart = (this.playerState?.seekableDuration ?? 0) > 0;
106
+ const newCanRestart = (playerState?.seekableDuration ?? 0) > 0;
107
+ this.playerState = playerState;
108
+
109
+ if (prevCanRestart !== newCanRestart) {
110
+ this.recalculate();
111
+ }
112
+ }
113
+
114
+ public updateEntry(entry: ZappEntry): void {
115
+ if (
116
+ this.entry?.id === entry?.id &&
117
+ this.entry?.extensions?.queueItemId === entry?.extensions?.queueItemId
118
+ ) {
119
+ this.entry = entry;
120
+
121
+ return;
122
+ }
123
+
124
+ this.entry = entry;
125
+ this.recalculate();
126
+ }
127
+
128
+ private getQueueManagerInstance() {
129
+ try {
130
+ const plugins = appStore?.get?.("plugins") || [];
131
+ const queuePlugin = findPluginByIdentifier("queue-action", plugins, true);
132
+ const module = (queuePlugin as any)?.module;
133
+ const QueueManager = module?.QueueManager;
134
+ const setupQuickBrickQueue = module?.setupQuickBrickQueue;
135
+
136
+ if (
137
+ QueueManager &&
138
+ !QueueManager.isInitialized?.() &&
139
+ typeof setupQuickBrickQueue === "function"
140
+ ) {
141
+ setupQuickBrickQueue();
142
+ }
143
+
144
+ if (QueueManager?.isInitialized?.()) {
145
+ return QueueManager.instance;
146
+ }
147
+ } catch {
148
+ // Safe fallback when store or plugin is not available
149
+ }
150
+
151
+ return null;
152
+ }
153
+
154
+ private subscribeToQueue(): void {
155
+ const queueManager = this.getQueueManagerInstance();
156
+
157
+ if (queueManager?.addListener) {
158
+ this.unsubscribeQueueListener = queueManager.addListener(() => {
159
+ if (!this.isDestroyed) {
160
+ this.recalculate();
161
+ }
162
+ });
163
+ }
164
+ }
165
+
166
+ private async getQueueData(): Promise<{
167
+ upcoming: ZappEntry[];
168
+ history: ZappEntry[];
169
+ }> {
170
+ const queueManager = this.getQueueManagerInstance();
171
+
172
+ if (!queueManager) {
173
+ return { upcoming: [], history: [] };
174
+ }
175
+
176
+ try {
177
+ const [upcoming, history] = await Promise.all([
178
+ queueManager.getUpcomingQueue?.() ?? [],
179
+ queueManager.getHistoryQueue?.() ?? [],
180
+ ]);
181
+
182
+ return {
183
+ upcoming: Array.isArray(upcoming) ? upcoming : [],
184
+ history: Array.isArray(history) ? history : [],
185
+ };
186
+ } catch (error) {
187
+ log_error("PlaylistNavigationController: Error fetching queue items", {
188
+ error,
189
+ });
190
+
191
+ return { upcoming: [], history: [] };
192
+ }
193
+ }
194
+
195
+ public async recalculate(): Promise<void> {
196
+ if (this.isDestroyed) return;
197
+
198
+ const generation = ++this.recalculateGeneration;
199
+ const { upcoming, history } = await this.getQueueData();
200
+
201
+ if (this.isDestroyed || generation !== this.recalculateGeneration) {
202
+ return;
203
+ }
204
+
205
+ const staticNextUrl = this.entry?.extensions?.play_next_feed_url;
206
+ const staticPrevUrl = this.entry?.extensions?.play_previous_feed_url;
207
+
208
+ const hasNext = upcoming.length > 0 || Boolean(staticNextUrl);
209
+
210
+ const canRestart = (this.playerState?.seekableDuration ?? 0) > 0;
211
+
212
+ const hasPrevious =
213
+ history.length > 0 || Boolean(staticPrevUrl) || canRestart;
214
+
215
+ if (this.hasNext$.getValue() !== hasNext) {
216
+ this.hasNext$.next(hasNext);
217
+ }
218
+
219
+ if (this.hasPrevious$.getValue() !== hasPrevious) {
220
+ this.hasPrevious$.next(hasPrevious);
221
+ }
222
+ }
223
+
224
+ public async goNext(): Promise<void> {
225
+ if (this.isNavigating || this.isDestroyed) {
226
+ return;
227
+ }
228
+
229
+ this.isNavigating = true;
230
+
231
+ try {
232
+ const { upcoming } = await this.getQueueData();
233
+
234
+ if (this.isDestroyed) return;
235
+
236
+ if (upcoming.length > 0) {
237
+ const nextItem = upcoming[0];
238
+
239
+ log_info(
240
+ `goNext: playing next item from queue "${nextItem.title}", id: ${nextItem.id}`,
241
+ { targetId: nextItem.id }
242
+ );
243
+
244
+ if (this.isDestroyed) return;
245
+ this.navigator?.replaceTop?.(nextItem);
246
+
247
+ return;
248
+ }
249
+
250
+ const staticNextUrl = this.entry?.extensions?.play_next_feed_url;
251
+
252
+ if (staticNextUrl) {
253
+ const target = await loadFeedEntry(staticNextUrl, this.entry);
254
+
255
+ if (this.isDestroyed) return;
256
+
257
+ log_info(
258
+ `goNext: playing "${target.title}", id: ${target.id} from remote feed`,
259
+ {
260
+ staticNextUrl,
261
+ targetId: target.id,
262
+ }
263
+ );
264
+
265
+ this.navigator?.replaceTop?.(target);
266
+ }
267
+ } catch (error) {
268
+ log_error("goNext: could not navigate to next entry", { error });
269
+ } finally {
270
+ this.isNavigating = false;
271
+ }
272
+ }
273
+
274
+ public async goPrevious(): Promise<void> {
275
+ if (this.isNavigating || this.isDestroyed) {
276
+ return;
277
+ }
278
+
279
+ this.isNavigating = true;
280
+
281
+ try {
282
+ const { history } = await this.getQueueData();
283
+
284
+ if (this.isDestroyed) return;
285
+
286
+ const staticPrevUrl = this.entry?.extensions?.play_previous_feed_url;
287
+
288
+ const currentTime = this.playerState?.currentTime ?? 0;
289
+ const canRestart = (this.playerState?.seekableDuration ?? 0) > 0;
290
+
291
+ const hasQueueHistory = history.length > 0;
292
+ const hasStaticPrev = Boolean(staticPrevUrl);
293
+
294
+ const hasTarget = hasQueueHistory || hasStaticPrev;
295
+
296
+ const shouldRestart =
297
+ canRestart && (currentTime > RESTART_THRESHOLD_SECONDS || !hasTarget);
298
+
299
+ if (shouldRestart) {
300
+ if (this.isDestroyed) return;
301
+ this.player?.seekTo?.(0);
302
+
303
+ return;
304
+ }
305
+
306
+ if (hasQueueHistory) {
307
+ const prevItem = history[history.length - 1];
308
+
309
+ log_info(
310
+ `goPrevious: playing previous item from queue "${prevItem.title}", id: ${prevItem.id}`,
311
+ { targetId: prevItem.id }
312
+ );
313
+
314
+ if (this.isDestroyed) return;
315
+ this.navigator?.replaceTop?.(prevItem);
316
+
317
+ return;
318
+ }
319
+
320
+ if (hasStaticPrev) {
321
+ const target = await loadFeedEntry(staticPrevUrl, this.entry);
322
+
323
+ if (this.isDestroyed) return;
324
+
325
+ log_info(
326
+ `goPrevious: playing "${target.title}", id: ${target.id} from remote feed`,
327
+ {
328
+ staticPrevUrl,
329
+ targetId: target.id,
330
+ }
331
+ );
332
+
333
+ this.navigator?.replaceTop?.(target);
334
+ }
335
+ } catch (error) {
336
+ log_error("goPrevious: could not navigate to previous entry", { error });
337
+ } finally {
338
+ this.isNavigating = false;
339
+ }
340
+ }
341
+
342
+ public destroy(): void {
343
+ this.isDestroyed = true;
344
+ this.recalculateGeneration++;
345
+
346
+ if (this.unsubscribeQueueListener) {
347
+ this.unsubscribeQueueListener();
348
+ this.unsubscribeQueueListener = null;
349
+ }
350
+
351
+ this.hasNext$.complete();
352
+ this.hasPrevious$.complete();
353
+ }
354
+ }
@@ -5,7 +5,7 @@ import { Player } from "@applicaster/zapp-react-native-utils/appUtils/playerMana
5
5
  import { hasDatePassed, NAMESPACE } from "./utils";
6
6
 
7
7
  const { log_debug, log_error } = createLogger({
8
- subsystem: "Player",
8
+ subsystem: "player/audio",
9
9
  category: "SleepTimerManager",
10
10
  });
11
11
 
@@ -5,7 +5,7 @@ import { Player } from "@applicaster/zapp-react-native-utils/appUtils/playerMana
5
5
  import { NAMESPACE } from "./utils";
6
6
 
7
7
  const { log_debug } = createLogger({
8
- subsystem: "Player",
8
+ subsystem: "player/audio",
9
9
  category: "PlaybackSpeedManager",
10
10
  });
11
11