@applicaster/zapp-react-native-utils 16.0.0-alpha.9225550512 → 16.0.0-alpha.9506982263
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/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/showToast.ts +64 -8
- package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +138 -51
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +115 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +57 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +170 -4
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +20 -15
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/layout/index.ts +1 -1
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { showToastAction } from "../showToast";
|
|
2
|
+
import { postEvent } from "../../../reactHooks/useSubscriberFor";
|
|
3
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../reactHooks/useSubscriberFor", () => ({
|
|
6
|
+
postEvent: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe("showToastAction", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
|
|
15
|
+
const action = {
|
|
16
|
+
type: "showToast",
|
|
17
|
+
options: {
|
|
18
|
+
id: "toast-1",
|
|
19
|
+
message: "Added to queue",
|
|
20
|
+
extraMessage: "Extra info",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const result = await showToastAction(action);
|
|
25
|
+
|
|
26
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
27
|
+
|
|
28
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
29
|
+
{
|
|
30
|
+
id: "toast-1",
|
|
31
|
+
message: "Added to queue",
|
|
32
|
+
extraMessage: "Extra info",
|
|
33
|
+
style: undefined,
|
|
34
|
+
timeout: 1000,
|
|
35
|
+
source: "confirmation",
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
expect(result).toBe(ActionResult.Success);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("preserves an explicit timeout and style override", async () => {
|
|
43
|
+
const action = {
|
|
44
|
+
type: "showToast",
|
|
45
|
+
options: {
|
|
46
|
+
message: "Playlist created",
|
|
47
|
+
timeout: 3000,
|
|
48
|
+
style: { backgroundColor: "#00FF00" },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
await showToastAction(action);
|
|
53
|
+
|
|
54
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
55
|
+
{
|
|
56
|
+
id: undefined,
|
|
57
|
+
message: "Playlist created",
|
|
58
|
+
extraMessage: undefined,
|
|
59
|
+
style: { backgroundColor: "#00FF00" },
|
|
60
|
+
timeout: 3000,
|
|
61
|
+
source: "confirmation",
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles missing or empty options without throwing", async () => {
|
|
67
|
+
const action = {
|
|
68
|
+
type: "showToast",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const result = await showToastAction(action);
|
|
72
|
+
|
|
73
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
74
|
+
|
|
75
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
76
|
+
{
|
|
77
|
+
id: undefined,
|
|
78
|
+
message: undefined,
|
|
79
|
+
extraMessage: undefined,
|
|
80
|
+
style: undefined,
|
|
81
|
+
timeout: 1000,
|
|
82
|
+
source: "confirmation",
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
expect(result).toBe(ActionResult.Success);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -3,12 +3,65 @@ import { ActionResult } from "../ActionExecutor";
|
|
|
3
3
|
import { ActionHandler } from "../types";
|
|
4
4
|
import { postEvent } from "../../reactHooks/useSubscriberFor";
|
|
5
5
|
|
|
6
|
+
export const CONFIRMATION_TOAST_SOURCE = "confirmation";
|
|
7
|
+
|
|
8
|
+
export const CONFIRMATION_TOAST_DEFAULT_TIMEOUT = 1000;
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Shows a mobile confirmation toast with Theme defaults from
|
|
12
|
+
* `Confirmation Toast / Message` in the base theme plugin.
|
|
13
|
+
*
|
|
14
|
+
* This action is confirmation-only by design: it always stamps
|
|
15
|
+
* `source: "confirmation"` (so Theme confirmation styles apply) and defaults
|
|
16
|
+
* `timeout` to 1000 ms. Non-confirmation toasts (e.g. Offline Experience)
|
|
17
|
+
* must post on the shared `"showToast"` event bus directly and omit `source`.
|
|
18
|
+
* Callers may override individual style fields; Theme supplies the rest.
|
|
19
|
+
*
|
|
20
|
+
* @example From React via ActionExecutorContext
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import React, { useContext } from "react";
|
|
23
|
+
* import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
|
|
24
|
+
*
|
|
25
|
+
* function QueueButton() {
|
|
26
|
+
* const { handleAction } = useContext(ActionExecutorContext);
|
|
27
|
+
*
|
|
28
|
+
* const onPress = () => {
|
|
29
|
+
* void handleAction({
|
|
30
|
+
* type: "showToast",
|
|
31
|
+
* options: { message: "Added to queue" },
|
|
32
|
+
* });
|
|
33
|
+
* };
|
|
34
|
+
*
|
|
35
|
+
* return <Button onPress={onPress} title="Add to queue" />;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example From code via the actionExecutor singleton
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
|
|
42
|
+
*
|
|
43
|
+
* await actionExecutor.handleAction({
|
|
44
|
+
* type: "showToast",
|
|
45
|
+
* options: {
|
|
46
|
+
* message: "Playlist created",
|
|
47
|
+
* style: { backgroundColor: "#00AA55" }, // optional partial override
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example From entry / pipes actions JSON
|
|
53
|
+
* ```json
|
|
54
|
+
* {
|
|
55
|
+
* "type": "showToast",
|
|
56
|
+
* "options": {
|
|
57
|
+
* "message": "Item removed from playlist"
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
8
61
|
*/
|
|
9
62
|
export interface ShowToastActionOptions {
|
|
10
|
-
id
|
|
11
|
-
message
|
|
63
|
+
id?: string;
|
|
64
|
+
message?: string;
|
|
12
65
|
extraMessage?: string;
|
|
13
66
|
style?: any;
|
|
14
67
|
timeout?: number;
|
|
@@ -17,13 +70,16 @@ export interface ShowToastActionOptions {
|
|
|
17
70
|
export const showToastAction: ActionHandler<ShowToastActionOptions> = async (
|
|
18
71
|
action
|
|
19
72
|
): Promise<ActionResult> => {
|
|
73
|
+
const options = action?.options;
|
|
74
|
+
|
|
20
75
|
postEvent("showToast", [
|
|
21
76
|
{
|
|
22
|
-
id:
|
|
23
|
-
message:
|
|
24
|
-
extraMessage:
|
|
25
|
-
style:
|
|
26
|
-
timeout:
|
|
77
|
+
id: options?.id,
|
|
78
|
+
message: options?.message,
|
|
79
|
+
extraMessage: options?.extraMessage,
|
|
80
|
+
style: options?.style,
|
|
81
|
+
timeout: options?.timeout ?? CONFIRMATION_TOAST_DEFAULT_TIMEOUT,
|
|
82
|
+
source: CONFIRMATION_TOAST_SOURCE,
|
|
27
83
|
},
|
|
28
84
|
]);
|
|
29
85
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "../appUtils/playerManager";
|
|
9
9
|
import { Player } from "../appUtils/playerManager/player";
|
|
10
10
|
import { AnalyticPlayerListener } from "./AnalyticPlayerListener";
|
|
11
|
-
import { PlayerRole } from "../appUtils/playerManager/
|
|
11
|
+
import { PlayerRole } from "../appUtils/playerManager/const";
|
|
12
12
|
|
|
13
13
|
enum PlayerAnalyticsTrackerType {
|
|
14
14
|
PlayerAnalyticsTracker = "PlayerAnalyticsTracker",
|
|
@@ -19,6 +19,12 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
|
|
|
19
19
|
parent: utilsLogger,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Mirrors `initial_value` for `audio_live_player_update_interval` in
|
|
24
|
+
* `defaultManifestConfigurations/player.js`.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS = 60;
|
|
27
|
+
|
|
22
28
|
type ChapterMarkerOriginal = {
|
|
23
29
|
id: string;
|
|
24
30
|
title: string;
|
|
@@ -40,11 +46,6 @@ export type LiveMetadataConfig = {
|
|
|
40
46
|
updateInterval: number;
|
|
41
47
|
};
|
|
42
48
|
|
|
43
|
-
export type TitleSummaryEvent = {
|
|
44
|
-
title: string | number;
|
|
45
|
-
summary: string | number;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
49
|
type ChapterMarkersObserverProps = {
|
|
49
50
|
player: Player;
|
|
50
51
|
};
|
|
@@ -59,24 +60,23 @@ type PlayNextConfig = {
|
|
|
59
60
|
export type PlayNextState = PlayNextConfig & {
|
|
60
61
|
triggerTime: number;
|
|
61
62
|
handleUserCancelPlayNext: () => void;
|
|
63
|
+
hidePlayNext: () => void;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export class OverlaysObserver {
|
|
65
67
|
readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
|
|
66
68
|
private playNextSubject: BehaviorSubject<PlayNextState>;
|
|
67
69
|
private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private updateTitleAndDescription: (data: any) => void;
|
|
72
|
-
private feedDataInterval: any;
|
|
70
|
+
private liveContentInterval: any;
|
|
71
|
+
private liveContentGeneration = 0;
|
|
72
|
+
private _liveEntry: ZappEntry | null = null;
|
|
73
73
|
private liveMetadataUpdateInterval: any;
|
|
74
74
|
private releasePlayerObserver?: () => void;
|
|
75
75
|
readonly entry: ZappEntry;
|
|
76
76
|
private chapterMarkerEvents: ChapterMarkerEvent[];
|
|
77
77
|
readonly player: Player;
|
|
78
78
|
private playNextConfig?: PlayNextConfig;
|
|
79
|
-
private
|
|
79
|
+
private isPlayNextSuppressed = false;
|
|
80
80
|
|
|
81
81
|
constructor({ player }: ChapterMarkersObserverProps) {
|
|
82
82
|
this.chapterSubject = new BehaviorSubject(null);
|
|
@@ -85,41 +85,140 @@ export class OverlaysObserver {
|
|
|
85
85
|
this.player = player;
|
|
86
86
|
this.entry = player.getEntry();
|
|
87
87
|
|
|
88
|
-
this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
|
|
89
|
-
title: this.entry?.title || "",
|
|
90
|
-
summary: this.entry?.summary || "",
|
|
91
|
-
});
|
|
92
|
-
|
|
93
88
|
this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
|
|
94
89
|
this.entry?.extensions?.liveMetadata || null
|
|
95
90
|
);
|
|
96
91
|
|
|
97
92
|
this.chapterMarkerEvents = this.prepareChapterMarkers();
|
|
98
93
|
this.releasePlayerObserver = this.subscribeToPlayerEvents();
|
|
99
|
-
this.
|
|
100
|
-
this.reloadData = () => {};
|
|
101
|
-
this.updateTitleAndDescription = () => {};
|
|
102
|
-
this.feedDataInterval = null;
|
|
94
|
+
this.liveContentInterval = null;
|
|
103
95
|
this.liveMetadataUpdateInterval = null;
|
|
104
96
|
void this.preparePlayNext();
|
|
105
97
|
void this.prepareLiveMetadata();
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Polls the live feed and pushes each loaded entry into the player, which
|
|
102
|
+
* re-resolves its Title/Subtitle and publishes on its content channel.
|
|
103
|
+
*
|
|
104
|
+
* Runs entirely outside React: `loadFeedEntry` builds its request through
|
|
105
|
+
* `RequestBuilder.setUrl`, which inflates URL macros with the entry and
|
|
106
|
+
* screen contexts, so no `useInflatedUrl` is needed. `prepareLiveMetadata`
|
|
107
|
+
* below already polls this way.
|
|
108
|
+
*/
|
|
109
|
+
public startLiveContentUpdates() {
|
|
110
|
+
this.stopLiveContentUpdates();
|
|
111
|
+
|
|
112
|
+
if (!this.player?.isLive?.()) {
|
|
113
|
+
log_debug("startLiveContentUpdates: Player is not live. Skipping...");
|
|
114
|
+
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const feedUrl = this.getLiveContentFeedUrl();
|
|
119
|
+
|
|
120
|
+
if (!feedUrl) {
|
|
121
|
+
log_debug(
|
|
122
|
+
"startLiveContentUpdates: Entry carries no live channel feed. Skipping..."
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return;
|
|
113
126
|
}
|
|
127
|
+
|
|
128
|
+
const intervalSeconds = this.getLiveContentUpdateInterval();
|
|
129
|
+
|
|
130
|
+
// Clearing the interval cannot cancel a request already in flight, so each
|
|
131
|
+
// run carries the generation it started in. A response that arrives after
|
|
132
|
+
// a stop or a restart belongs to a channel that is no longer playing and
|
|
133
|
+
// is dropped, rather than publishing the previous programme's title over
|
|
134
|
+
// the current one.
|
|
135
|
+
const generation = ++this.liveContentGeneration;
|
|
136
|
+
|
|
137
|
+
const load = async () => {
|
|
138
|
+
try {
|
|
139
|
+
const entry = await loadFeedEntry(feedUrl, this.entry);
|
|
140
|
+
|
|
141
|
+
if (generation !== this.liveContentGeneration) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this._liveEntry = entry;
|
|
146
|
+
this.player.publishContent();
|
|
147
|
+
} catch {
|
|
148
|
+
// `loadFeedEntry` already logs the failure. Keep whatever content is
|
|
149
|
+
// currently published rather than blanking the title on a transient
|
|
150
|
+
// network error.
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
void load();
|
|
155
|
+
|
|
156
|
+
this.liveContentInterval = setInterval(load, intervalSeconds * 1000);
|
|
114
157
|
}
|
|
115
158
|
|
|
116
|
-
public
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
159
|
+
public stopLiveContentUpdates() {
|
|
160
|
+
// Invalidates any in-flight request as well as the interval.
|
|
161
|
+
this.liveContentGeneration += 1;
|
|
162
|
+
|
|
163
|
+
if (this.liveContentInterval) {
|
|
164
|
+
clearInterval(this.liveContentInterval);
|
|
165
|
+
this.liveContentInterval = null;
|
|
120
166
|
}
|
|
121
167
|
}
|
|
122
168
|
|
|
169
|
+
/**
|
|
170
|
+
* The programme feed for the channel currently playing. Derived here rather
|
|
171
|
+
* than by the caller so no UI component needs to know where a live channel
|
|
172
|
+
* keeps its feed, or that the URL has to be rewritten to reach the
|
|
173
|
+
* programme ("livePage") view of it.
|
|
174
|
+
*/
|
|
175
|
+
private getLiveContentFeedUrl(): string {
|
|
176
|
+
const channelSrc =
|
|
177
|
+
this.player.getEntry()?.extensions?.live?.channel_src ?? "";
|
|
178
|
+
|
|
179
|
+
return channelSrc.replace(new RegExp("subClass", "g"), "livePage");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Falls back to the manifest's own `initial_value` when the app ships no
|
|
184
|
+
* value: `intervalSeconds * 1000` would otherwise be `NaN`, and
|
|
185
|
+
* `setInterval` treats `NaN` as `0` - a tight loop hammering the feed.
|
|
186
|
+
*/
|
|
187
|
+
private getLiveContentUpdateInterval(): number {
|
|
188
|
+
const configured =
|
|
189
|
+
this.player.getPluginConfiguration()?.audio_live_player_update_interval;
|
|
190
|
+
|
|
191
|
+
const seconds = Number(configured);
|
|
192
|
+
|
|
193
|
+
return Number.isFinite(seconds) && seconds > 0
|
|
194
|
+
? seconds
|
|
195
|
+
: DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The entry most recently loaded from the live channel feed - the programme
|
|
200
|
+
* currently on air, as opposed to `player.entry`, which is the channel and
|
|
201
|
+
* stays put for the whole listening session.
|
|
202
|
+
*
|
|
203
|
+
* Read by `Player.getContent()`, which prefers it over the player's own
|
|
204
|
+
* entry. It lives here rather than on `Player` because it is live-feed
|
|
205
|
+
* state, like `liveMetadata` and play-next: a VOD or cast player never has
|
|
206
|
+
* an observer at all, so it never carries this either.
|
|
207
|
+
*/
|
|
208
|
+
public get liveEntry(): ZappEntry | null {
|
|
209
|
+
return this._liveEntry;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Called by `Player`'s `entry` setter. The live entry is an overlay on the
|
|
214
|
+
* current entry, so its lifetime is scoped to that entry: without this, a
|
|
215
|
+
* programme from a previous channel would shadow the new one forever - the
|
|
216
|
+
* content would change but the title would not.
|
|
217
|
+
*/
|
|
218
|
+
public clearLiveEntry() {
|
|
219
|
+
this._liveEntry = null;
|
|
220
|
+
}
|
|
221
|
+
|
|
123
222
|
public clearLiveMetadataUpdateInterval() {
|
|
124
223
|
if (this.liveMetadataUpdateInterval) {
|
|
125
224
|
clearInterval(this.liveMetadataUpdateInterval);
|
|
@@ -127,25 +226,13 @@ export class OverlaysObserver {
|
|
|
127
226
|
}
|
|
128
227
|
}
|
|
129
228
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
updateTitleAndDescription: (data: any) => void
|
|
135
|
-
) {
|
|
136
|
-
this.feedUrl = feedUrl;
|
|
137
|
-
this.reloadData = reloadData;
|
|
138
|
-
this.updateTitleAndDescription = updateTitleAndDescription;
|
|
139
|
-
this.setupFeedDataInterval(interval);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public getTitleSummaryObservable(): Observable<TitleSummaryEvent> {
|
|
143
|
-
return this.titleSummarySubject.asObservable().pipe(distinctUntilChanged());
|
|
144
|
-
}
|
|
229
|
+
hidePlayNext = () => {
|
|
230
|
+
this.isPlayNextSuppressed = true;
|
|
231
|
+
this.playNextSubject.next(null);
|
|
232
|
+
};
|
|
145
233
|
|
|
146
234
|
handleUserCancelPlayNext = () => {
|
|
147
|
-
this.
|
|
148
|
-
this.playNextSubject.next(null);
|
|
235
|
+
this.hidePlayNext();
|
|
149
236
|
};
|
|
150
237
|
|
|
151
238
|
preparePlayNext = async () => {
|
|
@@ -270,7 +357,7 @@ export class OverlaysObserver {
|
|
|
270
357
|
|
|
271
358
|
// TODO: Hack for video end, will be replaced with playlist prev/next in the future
|
|
272
359
|
getPlayNextEntry = () =>
|
|
273
|
-
!this.
|
|
360
|
+
!this.isPlayNextSuppressed ? this.playNextConfig?.entry : null;
|
|
274
361
|
|
|
275
362
|
prepareChapterMarkers = () => {
|
|
276
363
|
const chapterMarkers: ChapterMarkerOriginal[] =
|
|
@@ -353,7 +440,7 @@ export class OverlaysObserver {
|
|
|
353
440
|
const shouldPlayNextBeVisible = currentTime > triggerTime;
|
|
354
441
|
|
|
355
442
|
if (shouldPlayNextBeVisible) {
|
|
356
|
-
if (this.
|
|
443
|
+
if (this.isPlayNextSuppressed) {
|
|
357
444
|
return;
|
|
358
445
|
}
|
|
359
446
|
|
|
@@ -361,10 +448,11 @@ export class OverlaysObserver {
|
|
|
361
448
|
...this.playNextConfig,
|
|
362
449
|
triggerTime,
|
|
363
450
|
handleUserCancelPlayNext: this.handleUserCancelPlayNext,
|
|
451
|
+
hidePlayNext: this.hidePlayNext,
|
|
364
452
|
});
|
|
365
453
|
} else {
|
|
366
454
|
this.playNextSubject.next(null);
|
|
367
|
-
this.
|
|
455
|
+
this.isPlayNextSuppressed = false;
|
|
368
456
|
}
|
|
369
457
|
};
|
|
370
458
|
|
|
@@ -389,9 +477,8 @@ export class OverlaysObserver {
|
|
|
389
477
|
this.chapterSubject.complete();
|
|
390
478
|
this.playNextSubject.complete();
|
|
391
479
|
this.liveMetadataSubject.complete();
|
|
392
|
-
this.titleSummarySubject.complete();
|
|
393
480
|
this.releasePlayerObserver?.();
|
|
394
|
-
this.
|
|
481
|
+
this.stopLiveContentUpdates();
|
|
395
482
|
this.clearLiveMetadataUpdateInterval();
|
|
396
483
|
this.releasePlayerObserver = null;
|
|
397
484
|
};
|
|
@@ -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
|
+
});
|