@applicaster/zapp-react-native-utils 16.0.0-alpha.1593888345 → 16.0.0-alpha.1733304298
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/actionUtils/index.ts +3 -1
- package/actionsExecutor/ActionExecutor.ts +10 -1
- package/actionsExecutor/ActionExecutorContext.tsx +3 -0
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +139 -5
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +160 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
- package/actionsExecutor/actions/index.ts +2 -0
- package/actionsExecutor/actions/navigateToScreen.ts +29 -45
- package/actionsExecutor/actions/openBottomSheet.ts +21 -6
- package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +1 -0
- package/actionsExecutor/feedDecorator.ts +6 -0
- package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
- package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
- package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
- package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
- package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
- package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
- package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +28 -129
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +15 -2
- package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
- package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/index.ts +7 -0
- package/appUtils/playerManager/player.ts +25 -0
- package/appUtils/playerManager/playerNative.ts +22 -0
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
- package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
- package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
- package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
- package/cellUtils/index.ts +40 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +189 -46
- package/configurationUtils/modalBlocksParser.ts +57 -101
- package/entryActions/__tests__/buildEntryActions.test.ts +97 -18
- package/entryActions/aliasPresentation.ts +26 -42
- package/entryActions/buildEntryActions.ts +1 -0
- package/entryActions/index.ts +0 -2
- package/focusManager/FocusManager.ts +26 -0
- package/focusManager/__tests__/FocusManager.test.ts +9 -0
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/xrayToolbox.ts +67 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/manifestUtils/keys.js +7 -2
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +2 -1
- package/modalState/ModalOrchestrator.ts +2 -0
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +39 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +2 -0
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +14 -0
- package/modalState/useBottomSheetContent.ts +17 -12
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/package.json +3 -2
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/quickBrickAssets/__tests__/index.test.ts +18 -0
- package/quickBrickAssets/index.ts +35 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +29 -23
- 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/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- package/reactHooks/feed/useFeedLoader.tsx +28 -1
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
- package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
- package/reactHooks/navigation/__tests__/index.test.tsx +128 -1
- package/reactHooks/navigation/useRoute.ts +8 -4
- package/reactHooks/usePluginConfiguration.ts +84 -46
- package/riverComponetsMeasurementProvider/index.tsx +3 -1
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
- package/uiActionsRegistrator/registry.ts +16 -0
- package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
- package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
|
@@ -59,6 +59,19 @@ export enum SharedPlayerCallBacksKeys {
|
|
|
59
59
|
// PIP
|
|
60
60
|
OnPlayerDetached = "onPlayerDetached",
|
|
61
61
|
OnPlayerAttached = "onPlayerAttached",
|
|
62
|
+
|
|
63
|
+
OnRemoteCommand = "onRemoteCommand",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Ids native sends in onRemoteCommand (lock screen / Control Center / CarPlay buttons)
|
|
67
|
+
export enum RemoteCommand {
|
|
68
|
+
Play = "play",
|
|
69
|
+
Pause = "pause",
|
|
70
|
+
Stop = "stop",
|
|
71
|
+
NextTrack = "nextTrack",
|
|
72
|
+
PreviousTrack = "previousTrack",
|
|
73
|
+
SkipForward = "skipForward",
|
|
74
|
+
SkipBackward = "skipBackward",
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
export enum PlayerRole {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { setUserLanguagePreference } from "./userLanguagePreference";
|
|
12
12
|
import { PlayerRole } from "./const";
|
|
13
13
|
import { RNPlayerManager } from "./nativePlayerManager";
|
|
14
|
+
import { registerPlayerToolbox } from "./playerToolbox";
|
|
14
15
|
|
|
15
16
|
const { log_error, log_debug, log_warning } = createLogger({
|
|
16
17
|
category: "General",
|
|
@@ -54,6 +55,7 @@ export class PlayerManager {
|
|
|
54
55
|
public static getInstance() {
|
|
55
56
|
if (!PlayerManager.instance) {
|
|
56
57
|
PlayerManager.instance = new PlayerManager();
|
|
58
|
+
registerPlayerToolbox(PlayerManager.instance);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
return PlayerManager.instance;
|
|
@@ -395,6 +397,11 @@ export class PlayerManager {
|
|
|
395
397
|
return this.manager.removeHandler(event, handler);
|
|
396
398
|
}
|
|
397
399
|
|
|
400
|
+
/** Whether anything handles `event` now, e.g. a mounted PlayerContainer for "toggleFullscreen". */
|
|
401
|
+
public hasHandler(event: string) {
|
|
402
|
+
return this.manager.handlers[event]?.length > 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
398
405
|
// TODO: should not be
|
|
399
406
|
public invokeHandler(event, ...args) {
|
|
400
407
|
return this.manager.invokeHandler(event, ...args);
|
|
@@ -76,6 +76,12 @@ export class Player {
|
|
|
76
76
|
private overlaysObserver?: OverlaysObserver | null;
|
|
77
77
|
private entryObservable?: BehaviorSubject<ZappEntry> | null;
|
|
78
78
|
private contentSubject?: BehaviorSubject<PlayerContent> | null;
|
|
79
|
+
// Read by the X-Ray `player` toolbox: the last onError/onVideoError of the current entry,
|
|
80
|
+
// and the Play Next action of the PlayerContainer showing this player.
|
|
81
|
+
public lastError: unknown = null;
|
|
82
|
+
public playNextHandler: (() => void) | null = null;
|
|
83
|
+
// The web engine the default player picked (hls.js, dash.js, shaka, video.js); null elsewhere.
|
|
84
|
+
public engine: string | null = null;
|
|
79
85
|
|
|
80
86
|
protected listeners: {
|
|
81
87
|
[key: string]: QuickBrickPlayer.SharedPlayerCallBacks;
|
|
@@ -89,6 +95,7 @@ export class Player {
|
|
|
89
95
|
|
|
90
96
|
set entry(newEntry: ZappEntry | null) {
|
|
91
97
|
this._entry = newEntry;
|
|
98
|
+
this.lastError = null;
|
|
92
99
|
// The live entry is scoped to the entry it overlays - see
|
|
93
100
|
// `OverlaysObserver.clearLiveEntry`. No-op when there is no observer,
|
|
94
101
|
// which is every non-live player.
|
|
@@ -271,6 +278,10 @@ export class Player {
|
|
|
271
278
|
|
|
272
279
|
getEntry = (): ZappEntry | null => this.entry;
|
|
273
280
|
|
|
281
|
+
/** The entry Play Next would play now; null without one. Never creates the overlay observer. */
|
|
282
|
+
getPlayNextEntry = (): ZappEntry | null =>
|
|
283
|
+
this.overlaysObserver?.getPlayNextEntry() ?? null;
|
|
284
|
+
|
|
274
285
|
logState = (text, additionalParams = {}) => {
|
|
275
286
|
const isSeeking = this.playerState.seekPosition !== null;
|
|
276
287
|
|
|
@@ -492,6 +503,8 @@ export class Player {
|
|
|
492
503
|
};
|
|
493
504
|
|
|
494
505
|
onVideoError = (error: Error) => {
|
|
506
|
+
this.lastError = error;
|
|
507
|
+
|
|
495
508
|
this.invokeListenersUpdate({
|
|
496
509
|
callbackName: SharedPlayerCallBacksKeys.OnVideoError,
|
|
497
510
|
event: error,
|
|
@@ -499,6 +512,8 @@ export class Player {
|
|
|
499
512
|
};
|
|
500
513
|
|
|
501
514
|
onError = (error: Error) => {
|
|
515
|
+
this.lastError = error;
|
|
516
|
+
|
|
502
517
|
this.invokeListenersUpdate({
|
|
503
518
|
callbackName: SharedPlayerCallBacksKeys.OnError,
|
|
504
519
|
event: error,
|
|
@@ -746,6 +761,13 @@ export class Player {
|
|
|
746
761
|
});
|
|
747
762
|
};
|
|
748
763
|
|
|
764
|
+
onRemoteCommand = (event: QuickBrickPlayer.RemoteCommandEvent) => {
|
|
765
|
+
this.invokeListenersUpdate({
|
|
766
|
+
callbackName: SharedPlayerCallBacksKeys.OnRemoteCommand,
|
|
767
|
+
event,
|
|
768
|
+
});
|
|
769
|
+
};
|
|
770
|
+
|
|
749
771
|
getTracksState = (): QuickBrickPlayer.TracksState =>
|
|
750
772
|
this.playerState.trackState;
|
|
751
773
|
|
|
@@ -823,6 +845,8 @@ export class Player {
|
|
|
823
845
|
// PIP
|
|
824
846
|
onPlayerDetached: this.onPlayerDetached,
|
|
825
847
|
onPlayerAttached: this.onPlayerAttached,
|
|
848
|
+
|
|
849
|
+
onRemoteCommand: this.onRemoteCommand,
|
|
826
850
|
});
|
|
827
851
|
|
|
828
852
|
play = () => {};
|
|
@@ -832,6 +856,7 @@ export class Player {
|
|
|
832
856
|
setPlaybackRate = (_rate) => {};
|
|
833
857
|
startSleepTimer = (_timestamp) => {};
|
|
834
858
|
cancelSleepTimer = () => {};
|
|
859
|
+
command = (_command: string, _userInfo?: Record<string, any>) => {};
|
|
835
860
|
|
|
836
861
|
getPluginConfiguration = () => null;
|
|
837
862
|
appStateChange = (_appState, _previousAppState) => {};
|
|
@@ -6,6 +6,7 @@ import { findNodeHandle } from "react-native";
|
|
|
6
6
|
import { PlayerRole } from "./const";
|
|
7
7
|
import { toBooleanWithDefaultFalse } from "../../booleanUtils";
|
|
8
8
|
import { RNPlayerManager } from "./nativePlayerManager";
|
|
9
|
+
import { isApplePlatform } from "../../reactUtils";
|
|
9
10
|
|
|
10
11
|
const logger = createLogger({
|
|
11
12
|
category: "PlayerNativeController",
|
|
@@ -27,6 +28,7 @@ interface PlayerMethods {
|
|
|
27
28
|
appStateChange?: (appState: string, previousAppState: string) => void;
|
|
28
29
|
closeNativePlayer?: () => void;
|
|
29
30
|
togglePlayPause?: () => void;
|
|
31
|
+
command?: (command: string, userInfo?: Record<string, any>) => void;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
type PlayerComponent = ReactComponent<PlayerRefProps> & PlayerMethods;
|
|
@@ -52,6 +54,7 @@ const PlayerModuleFuncNames = {
|
|
|
52
54
|
startSleepTimer: "startSleepTimer",
|
|
53
55
|
cancelSleepTimer: "cancelSleepTimer",
|
|
54
56
|
getSleepTimerEnd: "getSleepTimerEnd",
|
|
57
|
+
command: "command",
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
export class PlayerNative extends Player {
|
|
@@ -206,6 +209,25 @@ export class PlayerNative extends Player {
|
|
|
206
209
|
}
|
|
207
210
|
};
|
|
208
211
|
|
|
212
|
+
command = (command: string, userInfo?: Record<string, any>) => {
|
|
213
|
+
if (isApplePlatform()) {
|
|
214
|
+
const module = this.getPlayerModule();
|
|
215
|
+
module?.command?.(command, this.playerId, userInfo);
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (
|
|
221
|
+
!this.invokeNativeFunction(
|
|
222
|
+
PlayerModuleFuncNames.command,
|
|
223
|
+
command,
|
|
224
|
+
userInfo
|
|
225
|
+
)
|
|
226
|
+
) {
|
|
227
|
+
this.currentPlayerComponent()?.command?.(command, userInfo);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
209
231
|
disableBufferAnimation = (): boolean => false;
|
|
210
232
|
|
|
211
233
|
selectTrack = (
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { isApplePlatform } from "../../reactUtils";
|
|
2
2
|
import { NativeModules } from "react-native";
|
|
3
3
|
|
|
4
|
-
const NativePlayerModule = isApplePlatform()
|
|
5
|
-
? NativeModules.PlayerModule
|
|
6
|
-
: NativeModules.QuickBrickDefaultPlayerModule;
|
|
7
|
-
|
|
8
4
|
const PlayerNativeCommandTypes = {
|
|
9
5
|
pause: "pause",
|
|
10
6
|
clearPlayerData: "clearPlayerData",
|
|
11
7
|
removeViewByNativeId: "removeViewByNativeId",
|
|
8
|
+
setPlayerControls: "setPlayerControls",
|
|
12
9
|
};
|
|
13
10
|
|
|
14
11
|
const PlayerNativeSendCommand = (
|
|
@@ -16,8 +13,8 @@ const PlayerNativeSendCommand = (
|
|
|
16
13
|
playerId: string,
|
|
17
14
|
userInfo?: Record<string, any>
|
|
18
15
|
) => {
|
|
19
|
-
if (playerId && command) {
|
|
20
|
-
|
|
16
|
+
if (isApplePlatform() && playerId && command) {
|
|
17
|
+
NativeModules.PlayerModule?.command?.(command, playerId, userInfo);
|
|
21
18
|
}
|
|
22
19
|
};
|
|
23
20
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { registerXrayToolbox, XrayToolSpec } from "../../logger/xrayToolbox";
|
|
2
|
+
import type { PlayerManager } from "./index";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* X-Ray `player.*` toolbox: lets an agent read and drive the active player without screenshots.
|
|
6
|
+
* Registered by the PlayerManager singleton itself, so it exists wherever players do. Skipped
|
|
7
|
+
* when the installed X-Ray plugin has no React toolbox API.
|
|
8
|
+
*
|
|
9
|
+
* How the player is shown (video modal mode, mini player) is navigation state: see `nav.*`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const toNumber = (value: unknown) =>
|
|
13
|
+
typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
14
|
+
|
|
15
|
+
const clamp = (value: number, max: number) => Math.min(Math.max(value, 0), max);
|
|
16
|
+
|
|
17
|
+
/** Key systems the entry declares (widevine, playready, fairplay...). */
|
|
18
|
+
const drmKeySystems = (drm: unknown) =>
|
|
19
|
+
drm && typeof drm === "object" && Object.keys(drm).length
|
|
20
|
+
? Object.keys(drm)
|
|
21
|
+
: null;
|
|
22
|
+
|
|
23
|
+
/** The range a seek can reach: the DVR window on live, the content on VOD. */
|
|
24
|
+
const requireSeekable = (player: {
|
|
25
|
+
getSeekableDuration: () => number | undefined;
|
|
26
|
+
}) => {
|
|
27
|
+
const seekable = toNumber(player.getSeekableDuration());
|
|
28
|
+
|
|
29
|
+
if (!seekable) throw new Error("Seek is not supported");
|
|
30
|
+
|
|
31
|
+
return seekable;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const tools = (manager: PlayerManager): XrayToolSpec[] => {
|
|
35
|
+
const requirePlayer = () => {
|
|
36
|
+
const player = manager.getActivePlayer();
|
|
37
|
+
|
|
38
|
+
if (!player) throw new Error("No active player");
|
|
39
|
+
|
|
40
|
+
return player;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
name: "state",
|
|
46
|
+
description:
|
|
47
|
+
"The active player: entry, position and duration in seconds (the ad's while an ad plays), " +
|
|
48
|
+
"playing/buffering/ad/live/muted, role (Primary, Cell, Chromecast) and casting; in seconds, " +
|
|
49
|
+
"seekableDuration and contentPosition/contentDuration (the content's, even during ads); " +
|
|
50
|
+
"drm key systems, lastError {message} and next {id, title}, each null when absent; " +
|
|
51
|
+
"plugin (player plugin id) and engine (the default player's web engine, else null). " +
|
|
52
|
+
"active: false when nothing plays.",
|
|
53
|
+
handler: () => {
|
|
54
|
+
const player = manager.getActivePlayer();
|
|
55
|
+
|
|
56
|
+
if (!player) return { active: false, casting: manager.isCasting() };
|
|
57
|
+
|
|
58
|
+
const entry = player.getEntry();
|
|
59
|
+
const seekableDuration = toNumber(player.getSeekableDuration());
|
|
60
|
+
const next = player.getPlayNextEntry();
|
|
61
|
+
const error: any = player.lastError;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
active: true,
|
|
65
|
+
playerId: player.playerId,
|
|
66
|
+
entry: entry ? { id: entry.id, title: entry.title } : null,
|
|
67
|
+
position: toNumber(player.getPosition()),
|
|
68
|
+
duration: toNumber(player.getDuration()),
|
|
69
|
+
// isPlaying() only means "not paused", which is also true before the stream starts.
|
|
70
|
+
playing: !!player.isReadyToPlay() && player.isPlaying(),
|
|
71
|
+
buffering: !!player.isBuffering(),
|
|
72
|
+
readyToPlay: !!player.isReadyToPlay(),
|
|
73
|
+
ad: player.isAd(),
|
|
74
|
+
live: !!player.isLive(),
|
|
75
|
+
muted: !!player.getIsMuted(),
|
|
76
|
+
role: player.playerRole,
|
|
77
|
+
plugin: player.playerPluginId ?? null,
|
|
78
|
+
engine: player.engine ?? null,
|
|
79
|
+
casting: manager.isCasting(),
|
|
80
|
+
seekableDuration,
|
|
81
|
+
contentPosition: toNumber(player.getContentPosition()),
|
|
82
|
+
contentDuration: toNumber(player.getContentDuration()),
|
|
83
|
+
drm: drmKeySystems(entry?.extensions?.drm),
|
|
84
|
+
lastError:
|
|
85
|
+
error == null
|
|
86
|
+
? null
|
|
87
|
+
: { message: String(error?.message ?? error?.error ?? error) },
|
|
88
|
+
next: next ? { id: next.id, title: next.title } : null,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "play",
|
|
94
|
+
description: "Resume the active player.",
|
|
95
|
+
handler: () => {
|
|
96
|
+
requirePlayer().play();
|
|
97
|
+
|
|
98
|
+
return "OK";
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "pause",
|
|
103
|
+
description: "Pause the active player.",
|
|
104
|
+
handler: () => {
|
|
105
|
+
requirePlayer().pause();
|
|
106
|
+
|
|
107
|
+
return "OK";
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "next",
|
|
112
|
+
description:
|
|
113
|
+
"Play the next item, as the Play Next overlay does. Fails when there is none.",
|
|
114
|
+
handler: () => {
|
|
115
|
+
const player = requirePlayer();
|
|
116
|
+
const next = player.getPlayNextEntry();
|
|
117
|
+
|
|
118
|
+
if (!next || !player.playNextHandler) throw new Error("No next item");
|
|
119
|
+
|
|
120
|
+
player.playNextHandler();
|
|
121
|
+
|
|
122
|
+
return { id: next.id, title: next.title };
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "seek",
|
|
127
|
+
description:
|
|
128
|
+
"Seek to an absolute position, as the player's console command does: seconds from the start, " +
|
|
129
|
+
"or from the end when negative. Clamped to the seekable range. Where it lands can differ: " +
|
|
130
|
+
"server-side ads snap back to the break before the target; read player.state afterwards.",
|
|
131
|
+
parameters: [
|
|
132
|
+
{
|
|
133
|
+
name: "position",
|
|
134
|
+
type: "number",
|
|
135
|
+
description:
|
|
136
|
+
"Seconds from the start; negative values count back from the end.",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
handler: ({ position }) => {
|
|
140
|
+
const player = requirePlayer();
|
|
141
|
+
const seconds = toNumber(position);
|
|
142
|
+
|
|
143
|
+
if (seconds === null) {
|
|
144
|
+
throw new Error("'position' must be a number of seconds");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const seekable = requireSeekable(player);
|
|
148
|
+
|
|
149
|
+
const target =
|
|
150
|
+
seconds >= 0
|
|
151
|
+
? Math.min(seconds, seekable)
|
|
152
|
+
: clamp(seekable + seconds, seekable);
|
|
153
|
+
|
|
154
|
+
player.seekTo(target);
|
|
155
|
+
|
|
156
|
+
return { position: target };
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "offset",
|
|
161
|
+
description:
|
|
162
|
+
"Seek relative to the current position, as the player's console command does: positive " +
|
|
163
|
+
"forward, negative back. Clamped to the seekable range.",
|
|
164
|
+
parameters: [
|
|
165
|
+
{
|
|
166
|
+
name: "seconds",
|
|
167
|
+
type: "number",
|
|
168
|
+
description: "Seconds to move: positive forward, negative back.",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
handler: ({ seconds }) => {
|
|
172
|
+
const player = requirePlayer();
|
|
173
|
+
const delta = toNumber(seconds);
|
|
174
|
+
|
|
175
|
+
if (delta === null) throw new Error("'seconds' must be a number");
|
|
176
|
+
|
|
177
|
+
if (delta === 0) throw new Error("Ignored zero relative seek");
|
|
178
|
+
|
|
179
|
+
const seekable = requireSeekable(player);
|
|
180
|
+
const from = toNumber(player.getContentPosition()) ?? 0;
|
|
181
|
+
const target = clamp(from + delta, seekable);
|
|
182
|
+
|
|
183
|
+
player.seekTo(target);
|
|
184
|
+
|
|
185
|
+
return { from, position: target };
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const registerPlayerToolbox = (manager: PlayerManager) =>
|
|
192
|
+
registerXrayToolbox({
|
|
193
|
+
name: "player",
|
|
194
|
+
description: "Inspect and control the active player.",
|
|
195
|
+
tools: tools(manager),
|
|
196
|
+
});
|
|
@@ -8,6 +8,7 @@ import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/
|
|
|
8
8
|
import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
|
|
9
9
|
import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
|
|
10
10
|
import { isTV } from "../../reactUtils";
|
|
11
|
+
import { PlayerAnalyticsManager } from "../../analyticsUtils/PlayerAnalyticsManager";
|
|
11
12
|
|
|
12
13
|
// TODO: Rename to ControllerType
|
|
13
14
|
export const usePlayerControllerSetup = ({
|
|
@@ -68,6 +69,11 @@ export const usePlayerControllerSetup = ({
|
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// The analytics manager attaches its listener when a player registers, so it
|
|
73
|
+
// must exist first; on web the Player wrapper that also creates it renders
|
|
74
|
+
// only after the lazily loaded engine chunk, i.e. after registration.
|
|
75
|
+
PlayerAnalyticsManager.getInstance();
|
|
76
|
+
|
|
71
77
|
playerManager.registerPlayer({
|
|
72
78
|
id: playerId,
|
|
73
79
|
playerController,
|
|
@@ -47,4 +47,17 @@ describe("reorderByIds", () => {
|
|
|
47
47
|
|
|
48
48
|
expect(result.map((i) => i.key)).toEqual(["c", "b", "a"]);
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
it("reorders duplicate items when using unique slot identifiers via getId", () => {
|
|
52
|
+
const duplicateItems = [
|
|
53
|
+
{ id: "x", slot: "s1", name: "First X" },
|
|
54
|
+
{ id: "y", slot: "s2", name: "Y" },
|
|
55
|
+
{ id: "x", slot: "s3", name: "Second X" },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const result = reorderByIds(duplicateItems, ["s3", "s1"], (i) => i.slot);
|
|
59
|
+
|
|
60
|
+
expect(result).toHaveLength(3);
|
|
61
|
+
expect(result.map((i) => i.name)).toEqual(["Second X", "Y", "First X"]);
|
|
62
|
+
});
|
|
50
63
|
});
|
package/arrayUtils/index.ts
CHANGED
|
@@ -167,7 +167,7 @@ export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
|
|
|
167
167
|
export function reorderByIds<T>(
|
|
168
168
|
items: T[],
|
|
169
169
|
orderedIds: string[],
|
|
170
|
-
getId: (item: T) => string
|
|
170
|
+
getId: (item: T) => string = (item: any) => item?.id
|
|
171
171
|
): T[] {
|
|
172
172
|
if (!items || items.length === 0) return [];
|
|
173
173
|
if (!orderedIds || orderedIds.length === 0) return [...items];
|
|
@@ -175,14 +175,16 @@ export function reorderByIds<T>(
|
|
|
175
175
|
const itemMap = new Map<string, T>();
|
|
176
176
|
|
|
177
177
|
items.forEach((item) => {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
const id = getId(item);
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
id !== undefined &&
|
|
182
|
+
id !== null &&
|
|
183
|
+
id !== "" &&
|
|
184
|
+
!itemMap.has(String(id))
|
|
185
|
+
) {
|
|
186
|
+
itemMap.set(String(id), item);
|
|
187
|
+
}
|
|
186
188
|
});
|
|
187
189
|
|
|
188
190
|
const reorderedSubset: T[] = [];
|
|
@@ -192,48 +194,29 @@ export function reorderByIds<T>(
|
|
|
192
194
|
const strId = String(id);
|
|
193
195
|
const item = itemMap.get(strId);
|
|
194
196
|
|
|
195
|
-
if (item && !
|
|
197
|
+
if (item && !orderedIdsSet.has(strId)) {
|
|
196
198
|
reorderedSubset.push(item);
|
|
197
|
-
|
|
198
|
-
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
199
|
-
|
|
200
|
-
keys.forEach((k) => {
|
|
201
|
-
if (k !== undefined && k !== null && k !== "") {
|
|
202
|
-
orderedIdsSet.add(String(k));
|
|
203
|
-
}
|
|
204
|
-
});
|
|
199
|
+
orderedIdsSet.add(strId);
|
|
205
200
|
}
|
|
206
201
|
});
|
|
207
202
|
|
|
208
203
|
if (reorderedSubset.length === 0) return [...items];
|
|
209
204
|
|
|
210
205
|
let subsetIdx = 0;
|
|
211
|
-
const result: T[] = [];
|
|
212
|
-
|
|
213
|
-
items.forEach((item) => {
|
|
214
|
-
const rawId = getId(item);
|
|
215
|
-
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
216
|
-
|
|
217
|
-
const isMatched = keys.some(
|
|
218
|
-
(k) =>
|
|
219
|
-
k !== undefined &&
|
|
220
|
-
k !== null &&
|
|
221
|
-
k !== "" &&
|
|
222
|
-
orderedIdsSet.has(String(k))
|
|
223
|
-
);
|
|
224
206
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
207
|
+
return items.map((item) => {
|
|
208
|
+
const id = getId(item);
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
id !== undefined &&
|
|
212
|
+
id !== null &&
|
|
213
|
+
id !== "" &&
|
|
214
|
+
orderedIdsSet.has(String(id)) &&
|
|
215
|
+
subsetIdx < reorderedSubset.length
|
|
216
|
+
) {
|
|
217
|
+
return reorderedSubset[subsetIdx++];
|
|
231
218
|
}
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
while (subsetIdx < reorderedSubset.length) {
|
|
235
|
-
result.push(reorderedSubset[subsetIdx++]);
|
|
236
|
-
}
|
|
237
219
|
|
|
238
|
-
|
|
220
|
+
return item;
|
|
221
|
+
});
|
|
239
222
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getButtonsEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getButtonsEnabled", () => {
|
|
4
|
+
it("returns true when the buttons container is enabled", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: true })
|
|
7
|
+
).toBe(true);
|
|
8
|
+
|
|
9
|
+
expect(
|
|
10
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "true" })
|
|
11
|
+
).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("returns false when the buttons container is disabled", () => {
|
|
15
|
+
expect(
|
|
16
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: false })
|
|
17
|
+
).toBe(false);
|
|
18
|
+
|
|
19
|
+
expect(
|
|
20
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "false" })
|
|
21
|
+
).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns false when the key or styles are missing", () => {
|
|
25
|
+
expect(getButtonsEnabled({})).toBe(false);
|
|
26
|
+
expect(getButtonsEnabled(undefined)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getCellNavigationEnabled", () => {
|
|
4
|
+
it("returns true when cell navigation is enabled", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getCellNavigationEnabled({
|
|
7
|
+
mobile_buttons_container_cell_navigation_enabled: true,
|
|
8
|
+
})
|
|
9
|
+
).toBe(true);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
getCellNavigationEnabled({
|
|
13
|
+
mobile_buttons_container_cell_navigation_enabled: "true",
|
|
14
|
+
})
|
|
15
|
+
).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("returns false when cell navigation is disabled", () => {
|
|
19
|
+
expect(
|
|
20
|
+
getCellNavigationEnabled({
|
|
21
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
22
|
+
})
|
|
23
|
+
).toBe(false);
|
|
24
|
+
|
|
25
|
+
expect(
|
|
26
|
+
getCellNavigationEnabled({
|
|
27
|
+
mobile_buttons_container_cell_navigation_enabled: "false",
|
|
28
|
+
})
|
|
29
|
+
).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("returns false when the key or styles are missing", () => {
|
|
33
|
+
expect(getCellNavigationEnabled({})).toBe(false);
|
|
34
|
+
expect(getCellNavigationEnabled(undefined)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getIsCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getIsCellNavigationEnabled", () => {
|
|
4
|
+
it("is disabled when buttons are enabled and cell navigation is off", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getIsCellNavigationEnabled({
|
|
7
|
+
mobile_buttons_container_buttons_enabled: true,
|
|
8
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
9
|
+
})
|
|
10
|
+
).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("is enabled when buttons and cell navigation are both on", () => {
|
|
14
|
+
expect(
|
|
15
|
+
getIsCellNavigationEnabled({
|
|
16
|
+
mobile_buttons_container_buttons_enabled: true,
|
|
17
|
+
mobile_buttons_container_cell_navigation_enabled: true,
|
|
18
|
+
})
|
|
19
|
+
).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("is enabled when buttons are disabled", () => {
|
|
23
|
+
expect(
|
|
24
|
+
getIsCellNavigationEnabled({
|
|
25
|
+
mobile_buttons_container_buttons_enabled: false,
|
|
26
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
27
|
+
})
|
|
28
|
+
).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("is enabled when the keys or styles are missing", () => {
|
|
32
|
+
expect(getIsCellNavigationEnabled({})).toBe(true);
|
|
33
|
+
expect(getIsCellNavigationEnabled(undefined)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isCellNavigationEnabled", () => {
|
|
4
|
+
it("is enabled when buttons are disabled, regardless of the toggle", () => {
|
|
5
|
+
expect(isCellNavigationEnabled(false, false)).toBe(true);
|
|
6
|
+
expect(isCellNavigationEnabled(false, true)).toBe(true);
|
|
7
|
+
expect(isCellNavigationEnabled(undefined, undefined)).toBe(true);
|
|
8
|
+
expect(isCellNavigationEnabled("false", false)).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("is disabled when buttons are enabled and the toggle is off or missing", () => {
|
|
12
|
+
expect(isCellNavigationEnabled(true, false)).toBe(false);
|
|
13
|
+
expect(isCellNavigationEnabled(true, undefined)).toBe(false);
|
|
14
|
+
expect(isCellNavigationEnabled("true", "false")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("is enabled when buttons and the toggle are both enabled", () => {
|
|
18
|
+
expect(isCellNavigationEnabled(true, true)).toBe(true);
|
|
19
|
+
expect(isCellNavigationEnabled("true", "true")).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
});
|