@applicaster/zapp-react-native-utils 16.0.0-alpha.4416921324 → 16.0.0-alpha.4635728545
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/ActionExecutor.ts +50 -3
- package/actionsExecutor/ActionExecutorContext.tsx +99 -17
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +12 -0
- package/actionsExecutor/actions/navigateToScreen.ts +18 -4
- package/actionsExecutor/actions/openBottomSheet.ts +338 -0
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +64 -8
- package/actionsExecutor/consts.ts +27 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- 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 +6 -4
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
- package/arrayUtils/index.ts +62 -0
- package/cellUtils/index.ts +30 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +214 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +108 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +212 -0
- package/modalState/RemoteEditableCollection.ts +235 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +109 -0
- package/modalState/types.ts +162 -0
- package/modalState/useBottomSheetContent.ts +109 -0
- package/package.json +2 -2
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +37 -16
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/actions/index.ts +67 -2
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +2 -0
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +11 -1
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -57,6 +57,12 @@ export const refreshComponentAction: ActionHandler = async (
|
|
|
57
57
|
}) || source;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
if (!dataSource) {
|
|
61
|
+
log_info("handleAction: refreshComponent skipped: no dataSource found");
|
|
62
|
+
|
|
63
|
+
return ActionResult.Success;
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
61
67
|
source,
|
|
62
68
|
inflatedUrl: dataSource,
|
|
@@ -62,10 +62,15 @@ export const sendCloudEventAction: ActionHandler<
|
|
|
62
62
|
subject: options.subject || String((entry as ZappEntry)?.id || ""),
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
log_info("handleAction: sendCloudEvent
|
|
65
|
+
log_info("handleAction: sending sendCloudEvent to URL", {
|
|
66
|
+
url: options.url,
|
|
67
|
+
cloudEvent,
|
|
68
|
+
});
|
|
66
69
|
|
|
67
70
|
const { error, code } = await sendCloudEvent(cloudEvent, options.url);
|
|
68
71
|
|
|
72
|
+
log_info("handleAction: sendCloudEvent result", { code, error });
|
|
73
|
+
|
|
69
74
|
if (error) {
|
|
70
75
|
log_error("sendCloudEvent: error sending cloud event", { error });
|
|
71
76
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { showAlertDialog } from "../../alertUtils";
|
|
3
|
+
import { ActionResult } from "../ActionExecutor";
|
|
4
|
+
import { ActionHandler } from "../types";
|
|
5
|
+
import { createLogger } from "../../logger";
|
|
6
|
+
|
|
7
|
+
const { log_info } = createLogger({
|
|
8
|
+
subsystem: "ActionExecutorContext",
|
|
9
|
+
category: "General",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Options for the showAlert action.
|
|
14
|
+
*/
|
|
15
|
+
export interface ShowAlertOptions {
|
|
16
|
+
/** Dialog title (required) */
|
|
17
|
+
title: string;
|
|
18
|
+
|
|
19
|
+
/** Dialog message */
|
|
20
|
+
message?: string;
|
|
21
|
+
|
|
22
|
+
/** Dismiss button text. Defaults to "OK" */
|
|
23
|
+
okButtonText?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Tells the user something and waits for them to acknowledge it.
|
|
28
|
+
*
|
|
29
|
+
* One button, because there is nothing to decide. Use `confirmDialog` when the
|
|
30
|
+
* user is choosing between going on and backing out; a `confirmDialog` without
|
|
31
|
+
* a cancel label still renders two buttons, the second one blank.
|
|
32
|
+
*
|
|
33
|
+
* Always resolves to Success: dismissing a notice is not a cancellation, so the
|
|
34
|
+
* rest of the chain runs.
|
|
35
|
+
*/
|
|
36
|
+
export const showAlertAction: ActionHandler<ShowAlertOptions> = async (
|
|
37
|
+
action
|
|
38
|
+
): Promise<ActionResult> => {
|
|
39
|
+
log_info("handleAction: showAlert event");
|
|
40
|
+
|
|
41
|
+
const options = action.options as ShowAlertOptions;
|
|
42
|
+
|
|
43
|
+
return new Promise<ActionResult>((resolve) => {
|
|
44
|
+
showAlertDialog({
|
|
45
|
+
title: options?.title,
|
|
46
|
+
message: options?.message,
|
|
47
|
+
okButtonText: options?.okButtonText || "OK",
|
|
48
|
+
completion: () => resolve(ActionResult.Success),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -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 = 5000;
|
|
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 5000 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
|
|
|
@@ -2,3 +2,30 @@ export const TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT =
|
|
|
2
2
|
"action.localStorageToggleFlag.maxItemsReached";
|
|
3
3
|
|
|
4
4
|
export const ACTION_EXECUTOR_EVENT_SOURCE = "ActionExecutor";
|
|
5
|
+
|
|
6
|
+
export const ACTION_TYPES = {
|
|
7
|
+
OPEN_BOTTOM_SHEET: "openBottomSheet",
|
|
8
|
+
DISMISS_BOTTOM_SHEET: "dismissBottomSheet",
|
|
9
|
+
PRESENT_SUB_MENU: "presentSubMenu",
|
|
10
|
+
SEND_CLOUD_EVENT: "sendCloudEvent",
|
|
11
|
+
NAVIGATE_TO_SCREEN: "navigateToScreen",
|
|
12
|
+
PRESENT_SCREEN: "presentScreen",
|
|
13
|
+
GO_BACK: "goBack",
|
|
14
|
+
GO_HOME: "goHome",
|
|
15
|
+
SHOW_TOAST: "showToast",
|
|
16
|
+
LOCAL_STORAGE_SET: "localStorageSet",
|
|
17
|
+
LOCAL_STORAGE_REMOVE: "localStorageRemove",
|
|
18
|
+
LOCAL_STORAGE_TOGGLE_FLAG: "localStorageToggleFlag",
|
|
19
|
+
SESSION_STORAGE_SET: "sessionStorageSet",
|
|
20
|
+
SESSION_STORAGE_REMOVE: "sessionStorageRemove",
|
|
21
|
+
SESSION_STORAGE_TOGGLE_FLAG: "sessionStorageToggleFlag",
|
|
22
|
+
REFRESH_COMPONENT: "refreshComponent",
|
|
23
|
+
SWITCH_LAYOUT: "switchLayout",
|
|
24
|
+
APP_RESTART: "appRestart",
|
|
25
|
+
CONFIRM_DIALOG: "confirmDialog",
|
|
26
|
+
SHOW_ALERT: "showAlert",
|
|
27
|
+
SCREEN_SET_VARIABLE: "screenSetVariable",
|
|
28
|
+
SCREEN_TOGGLE_FLAG: "screenToggleFlag",
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export type KnownActionType = (typeof ACTION_TYPES)[keyof typeof ACTION_TYPES];
|
|
@@ -159,13 +159,13 @@ export const decorateFeed = (feed: ZappFeed) => {
|
|
|
159
159
|
|
|
160
160
|
const decoratedFeed = R.clone(feed);
|
|
161
161
|
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
const selectMode =
|
|
163
|
+
feed.extensions?.preference_editor_options?.select_mode ||
|
|
164
|
+
feed.extensions?.behavior?.select_mode;
|
|
165
165
|
|
|
166
|
-
if (
|
|
166
|
+
if (selectMode === "single") {
|
|
167
167
|
return makeSingleSelect(feed, key, decoratedFeed);
|
|
168
|
-
} else {
|
|
169
|
-
return makeMultiSelect(feed, key, decoratedFeed);
|
|
170
168
|
}
|
|
169
|
+
|
|
170
|
+
return makeMultiSelect(feed, key, decoratedFeed);
|
|
171
171
|
};
|
|
@@ -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",
|
|
@@ -498,6 +498,15 @@ export function HooksManager({
|
|
|
498
498
|
presentUI
|
|
499
499
|
);
|
|
500
500
|
} catch (e) {
|
|
501
|
+
// Without this the failure is invisible: the hook stops right after the
|
|
502
|
+
// "Executing hook" line, with nothing in the log explaining why and no
|
|
503
|
+
// remaining hook ever running.
|
|
504
|
+
logHookEvent(
|
|
505
|
+
hooksManagerLogger.error,
|
|
506
|
+
`runInBackground: hook ${hookPlugin.identifier} threw: ${e?.message}`,
|
|
507
|
+
{ hook: hookPlugin, payload, error: e, stack: e?.stack }
|
|
508
|
+
);
|
|
509
|
+
|
|
501
510
|
hookPlugin.setStateAndNotify(HOOKS_EVENTS.ERROR, {
|
|
502
511
|
error: e,
|
|
503
512
|
hookPlugin,
|
|
@@ -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 {
|
|
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
|
};
|
|
@@ -59,24 +59,23 @@ type PlayNextConfig = {
|
|
|
59
59
|
export type PlayNextState = PlayNextConfig & {
|
|
60
60
|
triggerTime: number;
|
|
61
61
|
handleUserCancelPlayNext: () => void;
|
|
62
|
+
hidePlayNext: () => void;
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
export class OverlaysObserver {
|
|
65
66
|
readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
|
|
66
67
|
private playNextSubject: BehaviorSubject<PlayNextState>;
|
|
67
68
|
private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private updateTitleAndDescription: (data: any) => void;
|
|
72
|
-
private feedDataInterval: any;
|
|
69
|
+
private liveContentInterval: any;
|
|
70
|
+
private liveContentGeneration = 0;
|
|
71
|
+
private _liveEntry: ZappEntry | null = null;
|
|
73
72
|
private liveMetadataUpdateInterval: any;
|
|
74
73
|
private releasePlayerObserver?: () => void;
|
|
75
74
|
readonly entry: ZappEntry;
|
|
76
75
|
private chapterMarkerEvents: ChapterMarkerEvent[];
|
|
77
76
|
readonly player: Player;
|
|
78
77
|
private playNextConfig?: PlayNextConfig;
|
|
79
|
-
private
|
|
78
|
+
private isPlayNextSuppressed = false;
|
|
80
79
|
|
|
81
80
|
constructor({ player }: ChapterMarkersObserverProps) {
|
|
82
81
|
this.chapterSubject = new BehaviorSubject(null);
|
|
@@ -85,41 +84,140 @@ export class OverlaysObserver {
|
|
|
85
84
|
this.player = player;
|
|
86
85
|
this.entry = player.getEntry();
|
|
87
86
|
|
|
88
|
-
this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
|
|
89
|
-
title: this.entry?.title || "",
|
|
90
|
-
summary: this.entry?.summary || "",
|
|
91
|
-
});
|
|
92
|
-
|
|
93
87
|
this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
|
|
94
88
|
this.entry?.extensions?.liveMetadata || null
|
|
95
89
|
);
|
|
96
90
|
|
|
97
91
|
this.chapterMarkerEvents = this.prepareChapterMarkers();
|
|
98
92
|
this.releasePlayerObserver = this.subscribeToPlayerEvents();
|
|
99
|
-
this.
|
|
100
|
-
this.reloadData = () => {};
|
|
101
|
-
this.updateTitleAndDescription = () => {};
|
|
102
|
-
this.feedDataInterval = null;
|
|
93
|
+
this.liveContentInterval = null;
|
|
103
94
|
this.liveMetadataUpdateInterval = null;
|
|
104
95
|
void this.preparePlayNext();
|
|
105
96
|
void this.prepareLiveMetadata();
|
|
106
97
|
}
|
|
107
98
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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;
|
|
113
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;
|
|
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);
|
|
114
156
|
}
|
|
115
157
|
|
|
116
|
-
public
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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;
|
|
120
165
|
}
|
|
121
166
|
}
|
|
122
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
|
+
|
|
123
221
|
public clearLiveMetadataUpdateInterval() {
|
|
124
222
|
if (this.liveMetadataUpdateInterval) {
|
|
125
223
|
clearInterval(this.liveMetadataUpdateInterval);
|
|
@@ -127,34 +225,19 @@ export class OverlaysObserver {
|
|
|
127
225
|
}
|
|
128
226
|
}
|
|
129
227
|
|
|
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
|
-
}
|
|
228
|
+
hidePlayNext = () => {
|
|
229
|
+
this.isPlayNextSuppressed = true;
|
|
230
|
+
this.playNextSubject.next(null);
|
|
231
|
+
};
|
|
145
232
|
|
|
146
233
|
handleUserCancelPlayNext = () => {
|
|
147
|
-
this.
|
|
148
|
-
this.playNextSubject.next(null);
|
|
234
|
+
this.hidePlayNext();
|
|
149
235
|
};
|
|
150
236
|
|
|
151
237
|
preparePlayNext = async () => {
|
|
152
238
|
try {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const playNextPlugin: any = findPluginByIdentifier(
|
|
156
|
-
"QuickBrickPlayNextOverlay",
|
|
157
|
-
plugins
|
|
239
|
+
const playNextPlugin: any = getPluginByIdentifier(
|
|
240
|
+
"QuickBrickPlayNextOverlay"
|
|
158
241
|
);
|
|
159
242
|
|
|
160
243
|
if (!playNextPlugin) {
|
|
@@ -165,7 +248,7 @@ export class OverlaysObserver {
|
|
|
165
248
|
return;
|
|
166
249
|
}
|
|
167
250
|
|
|
168
|
-
const playNextFeedUrl: string = retrieveFeedUrl(this.entry);
|
|
251
|
+
const playNextFeedUrl: string = await retrieveFeedUrl(this.entry);
|
|
169
252
|
|
|
170
253
|
if (!playNextFeedUrl || typeof playNextFeedUrl !== "string") {
|
|
171
254
|
log_debug(
|
|
@@ -270,7 +353,7 @@ export class OverlaysObserver {
|
|
|
270
353
|
|
|
271
354
|
// TODO: Hack for video end, will be replaced with playlist prev/next in the future
|
|
272
355
|
getPlayNextEntry = () =>
|
|
273
|
-
!this.
|
|
356
|
+
!this.isPlayNextSuppressed ? this.playNextConfig?.entry : null;
|
|
274
357
|
|
|
275
358
|
prepareChapterMarkers = () => {
|
|
276
359
|
const chapterMarkers: ChapterMarkerOriginal[] =
|
|
@@ -353,7 +436,7 @@ export class OverlaysObserver {
|
|
|
353
436
|
const shouldPlayNextBeVisible = currentTime > triggerTime;
|
|
354
437
|
|
|
355
438
|
if (shouldPlayNextBeVisible) {
|
|
356
|
-
if (this.
|
|
439
|
+
if (this.isPlayNextSuppressed) {
|
|
357
440
|
return;
|
|
358
441
|
}
|
|
359
442
|
|
|
@@ -361,10 +444,11 @@ export class OverlaysObserver {
|
|
|
361
444
|
...this.playNextConfig,
|
|
362
445
|
triggerTime,
|
|
363
446
|
handleUserCancelPlayNext: this.handleUserCancelPlayNext,
|
|
447
|
+
hidePlayNext: this.hidePlayNext,
|
|
364
448
|
});
|
|
365
449
|
} else {
|
|
366
450
|
this.playNextSubject.next(null);
|
|
367
|
-
this.
|
|
451
|
+
this.isPlayNextSuppressed = false;
|
|
368
452
|
}
|
|
369
453
|
};
|
|
370
454
|
|
|
@@ -389,9 +473,8 @@ export class OverlaysObserver {
|
|
|
389
473
|
this.chapterSubject.complete();
|
|
390
474
|
this.playNextSubject.complete();
|
|
391
475
|
this.liveMetadataSubject.complete();
|
|
392
|
-
this.titleSummarySubject.complete();
|
|
393
476
|
this.releasePlayerObserver?.();
|
|
394
|
-
this.
|
|
477
|
+
this.stopLiveContentUpdates();
|
|
395
478
|
this.clearLiveMetadataUpdateInterval();
|
|
396
479
|
this.releasePlayerObserver = null;
|
|
397
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
|
+
});
|