@applicaster/zapp-react-native-utils 16.0.0-alpha.2480030155 → 16.0.0-alpha.2500443242

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.
Files changed (142) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +50 -3
  3. package/actionsExecutor/ActionExecutorContext.tsx +99 -17
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  6. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  7. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  8. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  9. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  10. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
  12. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  13. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  14. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  15. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  16. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  17. package/actionsExecutor/actions/goBack.ts +60 -0
  18. package/actionsExecutor/actions/goHome.ts +31 -0
  19. package/actionsExecutor/actions/index.ts +12 -0
  20. package/actionsExecutor/actions/navigateToScreen.ts +43 -45
  21. package/actionsExecutor/actions/openBottomSheet.ts +339 -0
  22. package/actionsExecutor/actions/presentScreen.ts +78 -0
  23. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  24. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  25. package/actionsExecutor/actions/showAlert.ts +51 -0
  26. package/actionsExecutor/actions/showToast.ts +2 -2
  27. package/actionsExecutor/consts.ts +27 -0
  28. package/actionsExecutor/feedDecorator.ts +6 -6
  29. package/appUtils/HooksManager/index.ts +9 -0
  30. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +131 -54
  31. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  32. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  33. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  38. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  39. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  40. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  41. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  42. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  43. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  44. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  45. package/appUtils/playerManager/const.ts +13 -0
  46. package/appUtils/playerManager/index.ts +7 -0
  47. package/appUtils/playerManager/player.ts +124 -2
  48. package/appUtils/playerManager/playerNative.ts +27 -3
  49. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  50. package/appUtils/playerManager/playerToolbox.ts +157 -0
  51. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  52. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  53. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  54. package/arrayUtils/index.ts +62 -0
  55. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  56. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  57. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  58. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  59. package/cellUtils/index.ts +104 -22
  60. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  61. package/configurationUtils/__tests__/modalBlocksParser.test.ts +392 -0
  62. package/configurationUtils/index.ts +77 -73
  63. package/configurationUtils/manifestKeyParser.ts +50 -10
  64. package/configurationUtils/modalBlocksParser.ts +252 -0
  65. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  66. package/entryActions/aliasPresentation.ts +108 -0
  67. package/entryActions/buildEntryActions.ts +167 -0
  68. package/entryActions/index.ts +15 -0
  69. package/entryActions/types.ts +39 -0
  70. package/focusManager/FocusManager.ts +26 -0
  71. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  72. package/localizationUtils/index.ts +12 -6
  73. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  74. package/logger/xrayToolbox.ts +67 -0
  75. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  76. package/manifestUtils/_internals/index.js +8 -3
  77. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  78. package/manifestUtils/defaultManifestConfigurations/player.js +338 -1
  79. package/manifestUtils/index.js +3 -0
  80. package/manifestUtils/keys.js +6 -1
  81. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  82. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  83. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  84. package/manifestUtils/modalBlocks.js +304 -0
  85. package/modalState/ContentViewModel.ts +113 -0
  86. package/modalState/EditableCollection.ts +17 -0
  87. package/modalState/EditableCollectionRegistry.ts +51 -0
  88. package/modalState/ModalOrchestrator.ts +212 -0
  89. package/modalState/RemoteEditableCollection.ts +235 -0
  90. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  91. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  92. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  93. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  94. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  95. package/modalState/__tests__/index.test.ts +30 -1
  96. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  97. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  98. package/modalState/index.ts +35 -83
  99. package/modalState/store.ts +109 -0
  100. package/modalState/types.ts +162 -0
  101. package/modalState/useBottomSheetContent.ts +109 -0
  102. package/navigationUtils/xrayNavigator.ts +12 -0
  103. package/package.json +2 -2
  104. package/perfTracker.ts +206 -0
  105. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  106. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  107. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  108. package/playerUtils/contentDataKeys.ts +134 -0
  109. package/playerUtils/index.ts +37 -16
  110. package/playerUtils/isAudioItem.ts +26 -0
  111. package/playerUtils/resolvePlayerActions.ts +71 -0
  112. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  113. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  114. package/pluginUtils/index.ts +29 -0
  115. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  116. package/reactHooks/actions/index.ts +67 -2
  117. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  118. package/reactHooks/cell-click/index.ts +21 -14
  119. package/reactHooks/connection/index.tsx +8 -5
  120. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  121. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  122. package/reactHooks/index.ts +2 -0
  123. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  124. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  125. package/reactHooks/navigation/index.ts +2 -0
  126. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  127. package/reactHooks/navigation/useRoute.ts +22 -5
  128. package/reactHooks/usePluginConfiguration.ts +88 -47
  129. package/reactHooks/utils/__tests__/index.test.js +22 -2
  130. package/reactHooks/utils/index.ts +11 -1
  131. package/riverComponetsMeasurementProvider/index.tsx +8 -1
  132. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  133. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  134. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  135. package/uiActionsRegistrator/index.ts +25 -203
  136. package/uiActionsRegistrator/registry.ts +351 -0
  137. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  138. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  139. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  140. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  141. package/playerUtils/getPlayerActionButtons.ts +0 -17
  142. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -2,9 +2,8 @@ import { BehaviorSubject, Observable } from "rxjs";
2
2
  import { distinctUntilChanged } from "rxjs/operators";
3
3
  import { Player } from "../player";
4
4
  import { createLogger, utilsLogger } from "../../../logger";
5
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
5
+ import { getPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
6
6
  import {
7
- findPluginByIdentifier,
8
7
  loadFeedEntry,
9
8
  loadFeedAndPrefetchThumbnailImage,
10
9
  parseTimeToSeconds,
@@ -19,6 +18,12 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
19
18
  parent: utilsLogger,
20
19
  });
21
20
 
21
+ /**
22
+ * Mirrors `initial_value` for `audio_live_player_update_interval` in
23
+ * `defaultManifestConfigurations/player.js`.
24
+ */
25
+ const DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS = 60;
26
+
22
27
  type ChapterMarkerOriginal = {
23
28
  id: string;
24
29
  title: string;
@@ -40,11 +45,6 @@ export type LiveMetadataConfig = {
40
45
  updateInterval: number;
41
46
  };
42
47
 
43
- export type TitleSummaryEvent = {
44
- title: string | number;
45
- summary: string | number;
46
- };
47
-
48
48
  type ChapterMarkersObserverProps = {
49
49
  player: Player;
50
50
  };
@@ -66,11 +66,9 @@ export class OverlaysObserver {
66
66
  readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
67
67
  private playNextSubject: BehaviorSubject<PlayNextState>;
68
68
  private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
69
- private titleSummarySubject: BehaviorSubject<TitleSummaryEvent>;
70
- private feedUrl: string;
71
- private reloadData: () => void;
72
- private updateTitleAndDescription: (data: any) => void;
73
- private feedDataInterval: any;
69
+ private liveContentInterval: any;
70
+ private liveContentGeneration = 0;
71
+ private _liveEntry: ZappEntry | null = null;
74
72
  private liveMetadataUpdateInterval: any;
75
73
  private releasePlayerObserver?: () => void;
76
74
  readonly entry: ZappEntry;
@@ -86,41 +84,140 @@ export class OverlaysObserver {
86
84
  this.player = player;
87
85
  this.entry = player.getEntry();
88
86
 
89
- this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
90
- title: this.entry?.title || "",
91
- summary: this.entry?.summary || "",
92
- });
93
-
94
87
  this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
95
88
  this.entry?.extensions?.liveMetadata || null
96
89
  );
97
90
 
98
91
  this.chapterMarkerEvents = this.prepareChapterMarkers();
99
92
  this.releasePlayerObserver = this.subscribeToPlayerEvents();
100
- this.feedUrl = "";
101
- this.reloadData = () => {};
102
- this.updateTitleAndDescription = () => {};
103
- this.feedDataInterval = null;
93
+ this.liveContentInterval = null;
104
94
  this.liveMetadataUpdateInterval = null;
105
95
  void this.preparePlayNext();
106
96
  void this.prepareLiveMetadata();
107
97
  }
108
98
 
109
- private setupFeedDataInterval(interval: number) {
110
- if (this.feedUrl && this.reloadData && this.updateTitleAndDescription) {
111
- this.feedDataInterval = setInterval(() => {
112
- this.reloadData();
113
- }, interval * 1000);
99
+ /**
100
+ * Polls the live feed and pushes each loaded entry into the player, which
101
+ * re-resolves its Title/Subtitle and publishes on its content channel.
102
+ *
103
+ * Runs entirely outside React: `loadFeedEntry` builds its request through
104
+ * `RequestBuilder.setUrl`, which inflates URL macros with the entry and
105
+ * screen contexts, so no `useInflatedUrl` is needed. `prepareLiveMetadata`
106
+ * below already polls this way.
107
+ */
108
+ public startLiveContentUpdates() {
109
+ this.stopLiveContentUpdates();
110
+
111
+ if (!this.player?.isLive?.()) {
112
+ log_debug("startLiveContentUpdates: Player is not live. Skipping...");
113
+
114
+ return;
115
+ }
116
+
117
+ const feedUrl = this.getLiveContentFeedUrl();
118
+
119
+ if (!feedUrl) {
120
+ log_debug(
121
+ "startLiveContentUpdates: Entry carries no live channel feed. Skipping..."
122
+ );
123
+
124
+ return;
114
125
  }
126
+
127
+ const intervalSeconds = this.getLiveContentUpdateInterval();
128
+
129
+ // Clearing the interval cannot cancel a request already in flight, so each
130
+ // run carries the generation it started in. A response that arrives after
131
+ // a stop or a restart belongs to a channel that is no longer playing and
132
+ // is dropped, rather than publishing the previous programme's title over
133
+ // the current one.
134
+ const generation = ++this.liveContentGeneration;
135
+
136
+ const load = async () => {
137
+ try {
138
+ const entry = await loadFeedEntry(feedUrl, this.entry);
139
+
140
+ if (generation !== this.liveContentGeneration) {
141
+ return;
142
+ }
143
+
144
+ this._liveEntry = entry;
145
+ this.player.publishContent();
146
+ } catch {
147
+ // `loadFeedEntry` already logs the failure. Keep whatever content is
148
+ // currently published rather than blanking the title on a transient
149
+ // network error.
150
+ }
151
+ };
152
+
153
+ void load();
154
+
155
+ this.liveContentInterval = setInterval(load, intervalSeconds * 1000);
115
156
  }
116
157
 
117
- public clearFeedDataInterval() {
118
- if (this.feedDataInterval) {
119
- clearInterval(this.feedDataInterval);
120
- this.feedDataInterval = null;
158
+ public stopLiveContentUpdates() {
159
+ // Invalidates any in-flight request as well as the interval.
160
+ this.liveContentGeneration += 1;
161
+
162
+ if (this.liveContentInterval) {
163
+ clearInterval(this.liveContentInterval);
164
+ this.liveContentInterval = null;
121
165
  }
122
166
  }
123
167
 
168
+ /**
169
+ * The programme feed for the channel currently playing. Derived here rather
170
+ * than by the caller so no UI component needs to know where a live channel
171
+ * keeps its feed, or that the URL has to be rewritten to reach the
172
+ * programme ("livePage") view of it.
173
+ */
174
+ private getLiveContentFeedUrl(): string {
175
+ const channelSrc =
176
+ this.player.getEntry()?.extensions?.live?.channel_src ?? "";
177
+
178
+ return channelSrc.replace(new RegExp("subClass", "g"), "livePage");
179
+ }
180
+
181
+ /**
182
+ * Falls back to the manifest's own `initial_value` when the app ships no
183
+ * value: `intervalSeconds * 1000` would otherwise be `NaN`, and
184
+ * `setInterval` treats `NaN` as `0` - a tight loop hammering the feed.
185
+ */
186
+ private getLiveContentUpdateInterval(): number {
187
+ const configured =
188
+ this.player.getPluginConfiguration()?.audio_live_player_update_interval;
189
+
190
+ const seconds = Number(configured);
191
+
192
+ return Number.isFinite(seconds) && seconds > 0
193
+ ? seconds
194
+ : DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS;
195
+ }
196
+
197
+ /**
198
+ * The entry most recently loaded from the live channel feed - the programme
199
+ * currently on air, as opposed to `player.entry`, which is the channel and
200
+ * stays put for the whole listening session.
201
+ *
202
+ * Read by `Player.getContent()`, which prefers it over the player's own
203
+ * entry. It lives here rather than on `Player` because it is live-feed
204
+ * state, like `liveMetadata` and play-next: a VOD or cast player never has
205
+ * an observer at all, so it never carries this either.
206
+ */
207
+ public get liveEntry(): ZappEntry | null {
208
+ return this._liveEntry;
209
+ }
210
+
211
+ /**
212
+ * Called by `Player`'s `entry` setter. The live entry is an overlay on the
213
+ * current entry, so its lifetime is scoped to that entry: without this, a
214
+ * programme from a previous channel would shadow the new one forever - the
215
+ * content would change but the title would not.
216
+ */
217
+ public clearLiveEntry() {
218
+ this._liveEntry = null;
219
+ }
220
+
124
221
  public clearLiveMetadataUpdateInterval() {
125
222
  if (this.liveMetadataUpdateInterval) {
126
223
  clearInterval(this.liveMetadataUpdateInterval);
@@ -128,22 +225,6 @@ export class OverlaysObserver {
128
225
  }
129
226
  }
130
227
 
131
- public setFeedDataHandlers(
132
- feedUrl: string,
133
- reloadData: () => void,
134
- interval: number,
135
- updateTitleAndDescription: (data: any) => void
136
- ) {
137
- this.feedUrl = feedUrl;
138
- this.reloadData = reloadData;
139
- this.updateTitleAndDescription = updateTitleAndDescription;
140
- this.setupFeedDataInterval(interval);
141
- }
142
-
143
- public getTitleSummaryObservable(): Observable<TitleSummaryEvent> {
144
- return this.titleSummarySubject.asObservable().pipe(distinctUntilChanged());
145
- }
146
-
147
228
  hidePlayNext = () => {
148
229
  this.isPlayNextSuppressed = true;
149
230
  this.playNextSubject.next(null);
@@ -155,11 +236,8 @@ export class OverlaysObserver {
155
236
 
156
237
  preparePlayNext = async () => {
157
238
  try {
158
- const plugins = appStore.get("plugins");
159
-
160
- const playNextPlugin: any = findPluginByIdentifier(
161
- "QuickBrickPlayNextOverlay",
162
- plugins
239
+ const playNextPlugin: any = getPluginByIdentifier(
240
+ "QuickBrickPlayNextOverlay"
163
241
  );
164
242
 
165
243
  if (!playNextPlugin) {
@@ -170,7 +248,7 @@ export class OverlaysObserver {
170
248
  return;
171
249
  }
172
250
 
173
- const playNextFeedUrl: string = retrieveFeedUrl(this.entry);
251
+ const playNextFeedUrl: string = await retrieveFeedUrl(this.entry);
174
252
 
175
253
  if (!playNextFeedUrl || typeof playNextFeedUrl !== "string") {
176
254
  log_debug(
@@ -395,9 +473,8 @@ export class OverlaysObserver {
395
473
  this.chapterSubject.complete();
396
474
  this.playNextSubject.complete();
397
475
  this.liveMetadataSubject.complete();
398
- this.titleSummarySubject.complete();
399
476
  this.releasePlayerObserver?.();
400
- this.clearFeedDataInterval();
477
+ this.stopLiveContentUpdates();
401
478
  this.clearLiveMetadataUpdateInterval();
402
479
  this.releasePlayerObserver = null;
403
480
  };
@@ -0,0 +1,67 @@
1
+ import { getUpcomingQueue } from "../getUpcomingQueue";
2
+
3
+ describe("getUpcomingQueue", () => {
4
+ it("returns null when plugin is not provided or has no module", async () => {
5
+ expect(await getUpcomingQueue(undefined)).toBeNull();
6
+ expect(await getUpcomingQueue({} as any)).toBeNull();
7
+ });
8
+
9
+ it("returns null when QueueManager is not present on module", async () => {
10
+ const plugin = {
11
+ identifier: "queue-action",
12
+ module: {},
13
+ } as any;
14
+
15
+ expect(await getUpcomingQueue(plugin)).toBeNull();
16
+ });
17
+
18
+ it("calls setupQuickBrickQueue when QueueManager is not initialized", async () => {
19
+ const setupQuickBrickQueue = jest.fn();
20
+ const mockUpcoming = [{ id: "item_1" }];
21
+
22
+ const QueueManager = {
23
+ isInitialized: jest
24
+ .fn()
25
+ .mockReturnValueOnce(false)
26
+ .mockReturnValueOnce(true),
27
+ instance: {
28
+ getUpcomingQueue: jest.fn().mockResolvedValue(mockUpcoming),
29
+ },
30
+ };
31
+
32
+ const plugin = {
33
+ identifier: "queue-action",
34
+ module: {
35
+ QueueManager,
36
+ setupQuickBrickQueue,
37
+ },
38
+ } as any;
39
+
40
+ const result = await getUpcomingQueue(plugin);
41
+
42
+ expect(setupQuickBrickQueue).toHaveBeenCalled();
43
+ expect(result).toEqual(mockUpcoming);
44
+ });
45
+
46
+ it("returns upcoming items when QueueManager is already initialized", async () => {
47
+ const mockUpcoming = [{ id: "item_1" }, { id: "item_2" }];
48
+
49
+ const QueueManager = {
50
+ isInitialized: jest.fn().mockReturnValue(true),
51
+ instance: {
52
+ getUpcomingQueue: jest.fn().mockResolvedValue(mockUpcoming),
53
+ },
54
+ };
55
+
56
+ const plugin = {
57
+ identifier: "queue-action",
58
+ module: {
59
+ QueueManager,
60
+ },
61
+ } as any;
62
+
63
+ const result = await getUpcomingQueue(plugin);
64
+
65
+ expect(result).toEqual(mockUpcoming);
66
+ });
67
+ });
@@ -0,0 +1,205 @@
1
+ import { OverlaysObserver } from "../OverlaysObserver";
2
+ import { loadFeedEntry } from "../utils";
3
+
4
+ jest.mock("../utils", () => ({
5
+ ...jest.requireActual("../utils"),
6
+ loadFeedEntry: jest.fn(),
7
+ }));
8
+
9
+ const FEED_ENTRY = { title: "Programme One" } as unknown as ZappEntry;
10
+
11
+ const CHANNEL_ENTRY = {
12
+ title: "Channel",
13
+ extensions: { live: { channel_src: "https://feed.test/subClass/audio" } },
14
+ } as unknown as ZappEntry;
15
+
16
+ const makePlayer = ({
17
+ isLive = true,
18
+ entry = CHANNEL_ENTRY,
19
+ configuration = { audio_live_player_update_interval: 30 },
20
+ }: {
21
+ isLive?: boolean;
22
+ entry?: ZappEntry;
23
+ configuration?: Record<string, any>;
24
+ } = {}) => ({
25
+ isLive: () => isLive,
26
+ getEntry: () => entry,
27
+ getPluginConfiguration: () => configuration,
28
+ publishContent: jest.fn(),
29
+ addListener: jest.fn(() => () => {}),
30
+ removeListener: jest.fn(),
31
+ });
32
+
33
+ describe("OverlaysObserver live content", () => {
34
+ beforeEach(() => {
35
+ jest.useFakeTimers();
36
+ (loadFeedEntry as jest.Mock).mockReset();
37
+ (loadFeedEntry as jest.Mock).mockResolvedValue(FEED_ENTRY);
38
+ });
39
+
40
+ afterEach(() => {
41
+ jest.useRealTimers();
42
+ });
43
+
44
+ it("stores the loaded programme and asks the player to republish", async () => {
45
+ const player = makePlayer();
46
+ const observer = new OverlaysObserver({ player } as any);
47
+
48
+ observer.startLiveContentUpdates();
49
+
50
+ await Promise.resolve();
51
+ await Promise.resolve();
52
+
53
+ expect(observer.liveEntry).toBe(FEED_ENTRY);
54
+ expect(player.publishContent).toHaveBeenCalled();
55
+
56
+ observer.stopLiveContentUpdates();
57
+ });
58
+
59
+ it("clears the stored programme on clearLiveEntry", async () => {
60
+ const player = makePlayer();
61
+ const observer = new OverlaysObserver({ player } as any);
62
+
63
+ observer.startLiveContentUpdates();
64
+
65
+ await Promise.resolve();
66
+ await Promise.resolve();
67
+
68
+ observer.clearLiveEntry();
69
+
70
+ expect(observer.liveEntry).toBeNull();
71
+
72
+ observer.stopLiveContentUpdates();
73
+ });
74
+
75
+ it("reloads on the configured interval", async () => {
76
+ const player = makePlayer();
77
+ const observer = new OverlaysObserver({ player } as any);
78
+
79
+ observer.startLiveContentUpdates();
80
+
81
+ await Promise.resolve();
82
+
83
+ (loadFeedEntry as jest.Mock).mockClear();
84
+
85
+ jest.advanceTimersByTime(30_000);
86
+
87
+ expect(loadFeedEntry).toHaveBeenCalledTimes(1);
88
+
89
+ observer.stopLiveContentUpdates();
90
+ });
91
+
92
+ it("stops polling after stopLiveContentUpdates", async () => {
93
+ const player = makePlayer();
94
+ const observer = new OverlaysObserver({ player } as any);
95
+
96
+ observer.startLiveContentUpdates();
97
+
98
+ await Promise.resolve();
99
+
100
+ observer.stopLiveContentUpdates();
101
+
102
+ (loadFeedEntry as jest.Mock).mockClear();
103
+
104
+ jest.advanceTimersByTime(90_000);
105
+
106
+ expect(loadFeedEntry).not.toHaveBeenCalled();
107
+ });
108
+
109
+ it("keeps the previous content when a poll fails", async () => {
110
+ const player = makePlayer();
111
+ const observer = new OverlaysObserver({ player } as any);
112
+
113
+ (loadFeedEntry as jest.Mock).mockRejectedValue(new Error("network"));
114
+
115
+ observer.startLiveContentUpdates();
116
+
117
+ await Promise.resolve();
118
+ await Promise.resolve();
119
+
120
+ expect(observer.liveEntry).toBeNull();
121
+ expect(player.publishContent).not.toHaveBeenCalled();
122
+
123
+ observer.stopLiveContentUpdates();
124
+ });
125
+
126
+ it("drops a response that arrives after polling was stopped", async () => {
127
+ const player = makePlayer();
128
+ const observer = new OverlaysObserver({ player } as any);
129
+
130
+ let resolveLoad: (entry: ZappEntry) => void;
131
+
132
+ (loadFeedEntry as jest.Mock).mockReturnValue(
133
+ new Promise<ZappEntry>((resolve) => {
134
+ resolveLoad = resolve;
135
+ })
136
+ );
137
+
138
+ observer.startLiveContentUpdates();
139
+ observer.stopLiveContentUpdates();
140
+
141
+ // The request was already in flight when polling stopped: clearing the
142
+ // interval cannot cancel it, so its result must be ignored rather than
143
+ // published over whatever is playing now.
144
+ resolveLoad(FEED_ENTRY);
145
+
146
+ await Promise.resolve();
147
+ await Promise.resolve();
148
+
149
+ expect(observer.liveEntry).toBeNull();
150
+ expect(player.publishContent).not.toHaveBeenCalled();
151
+ });
152
+
153
+ it("does not start polling when the entry carries no live channel feed", () => {
154
+ const player = makePlayer({ entry: { title: "No Feed" } as ZappEntry });
155
+ const observer = new OverlaysObserver({ player } as any);
156
+
157
+ observer.startLiveContentUpdates();
158
+
159
+ expect(loadFeedEntry).not.toHaveBeenCalled();
160
+ });
161
+
162
+ it("does not start polling for on-demand content", () => {
163
+ const player = makePlayer({ isLive: false });
164
+ const observer = new OverlaysObserver({ player } as any);
165
+
166
+ observer.startLiveContentUpdates();
167
+
168
+ expect(loadFeedEntry).not.toHaveBeenCalled();
169
+ });
170
+
171
+ it("rewrites the channel url to reach the programme feed", () => {
172
+ const player = makePlayer();
173
+ const observer = new OverlaysObserver({ player } as any);
174
+
175
+ observer.startLiveContentUpdates();
176
+
177
+ expect(loadFeedEntry).toHaveBeenCalledWith(
178
+ "https://feed.test/livePage/audio",
179
+ expect.anything()
180
+ );
181
+
182
+ observer.stopLiveContentUpdates();
183
+ });
184
+
185
+ it("falls back to the manifest default interval when none is configured", async () => {
186
+ // An unset value would make `intervalSeconds * 1000` NaN, and setInterval
187
+ // treats NaN as 0 - a tight loop hammering the feed.
188
+ const player = makePlayer({ configuration: {} });
189
+ const observer = new OverlaysObserver({ player } as any);
190
+
191
+ observer.startLiveContentUpdates();
192
+
193
+ await Promise.resolve();
194
+
195
+ (loadFeedEntry as jest.Mock).mockClear();
196
+
197
+ jest.advanceTimersByTime(59_000);
198
+ expect(loadFeedEntry).not.toHaveBeenCalled();
199
+
200
+ jest.advanceTimersByTime(1_000);
201
+ expect(loadFeedEntry).toHaveBeenCalledTimes(1);
202
+
203
+ observer.stopLiveContentUpdates();
204
+ });
205
+ });
@@ -0,0 +1,56 @@
1
+ import { retrieveFeedUrl, retrievePlayPreviousFeedUrl } from "../utils";
2
+
3
+ // mock for import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
4
+ jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
5
+ appStore: {
6
+ get: jest.fn(() => []),
7
+ },
8
+ }));
9
+
10
+ const entryWith = (extensions: Record<string, unknown>): ZappEntry =>
11
+ ({ id: "1", type: { value: "video" }, extensions }) as ZappEntry;
12
+
13
+ describe("playlist feed url accessors", () => {
14
+ it("returns the next feed url when present", async () => {
15
+ const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
16
+
17
+ await expect(retrieveFeedUrl(entry)).resolves.toBe(
18
+ "https://feeds/next.json"
19
+ );
20
+ });
21
+
22
+ it("resolves to null for a missing entry", async () => {
23
+ await expect(
24
+ retrieveFeedUrl(undefined as unknown as ZappEntry)
25
+ ).resolves.toBeNull();
26
+ });
27
+
28
+ it("returns the previous feed url when present", () => {
29
+ const entry = entryWith({
30
+ play_previous_feed_url: "https://feeds/prev.json",
31
+ });
32
+
33
+ expect(retrievePlayPreviousFeedUrl(entry)).toBe("https://feeds/prev.json");
34
+ });
35
+
36
+ it("returns undefined when only the next url is present", () => {
37
+ const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
38
+
39
+ expect(retrievePlayPreviousFeedUrl(entry)).toBeUndefined();
40
+ });
41
+
42
+ it("returns undefined for an entry with no extensions", () => {
43
+ expect(
44
+ retrievePlayPreviousFeedUrl({
45
+ id: "1",
46
+ type: { value: "video" },
47
+ } as ZappEntry)
48
+ ).toBeUndefined();
49
+ });
50
+
51
+ it("returns undefined for a missing entry", () => {
52
+ expect(
53
+ retrievePlayPreviousFeedUrl(undefined as unknown as ZappEntry)
54
+ ).toBeUndefined();
55
+ });
56
+ });
@@ -0,0 +1,4 @@
1
+ /** `queue-action` is not supported on this platform. See getUpcomingQueue.ts */
2
+ export const getUpcomingQueue = async (
3
+ _plugin?: QuickBrickPlugin | ZappPlugin
4
+ ): Promise<unknown[] | null> => null;
@@ -0,0 +1,4 @@
1
+ /** `queue-action` is not supported on this platform. See getUpcomingQueue.ts */
2
+ export const getUpcomingQueue = async (
3
+ _plugin?: QuickBrickPlugin | ZappPlugin
4
+ ): Promise<unknown[] | null> => null;
@@ -0,0 +1,24 @@
1
+ export const getUpcomingQueue = async (
2
+ plugin?: QuickBrickPlugin | ZappPlugin
3
+ ): Promise<unknown[] | null> => {
4
+ const module = (plugin as any)?.module;
5
+ const QueueManager = module?.QueueManager;
6
+ const setupQuickBrickQueue = module?.setupQuickBrickQueue;
7
+
8
+ if (!QueueManager) {
9
+ return null;
10
+ }
11
+
12
+ if (
13
+ !QueueManager.isInitialized?.() &&
14
+ typeof setupQuickBrickQueue === "function"
15
+ ) {
16
+ setupQuickBrickQueue();
17
+ }
18
+
19
+ if (!QueueManager.isInitialized?.()) {
20
+ return null;
21
+ }
22
+
23
+ return QueueManager.instance.getUpcomingQueue();
24
+ };
@@ -0,0 +1,4 @@
1
+ /** `queue-action` is not supported on this platform. See getUpcomingQueue.ts */
2
+ export const getUpcomingQueue = async (
3
+ _plugin?: QuickBrickPlugin | ZappPlugin
4
+ ): Promise<unknown[] | null> => null;