@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 14.0.0-rc.90
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/ActionExecutorContext.tsx +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +154 -30
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +27 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +112 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
- package/appUtils/platform/platformUtils.ts +33 -3
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +91 -16
- package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
- package/appUtils/playerManager/conts.ts +21 -0
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +13 -3
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
- package/audioPlayerUtils/assets/index.ts +2 -0
- package/audioPlayerUtils/index.ts +242 -0
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/conf/player/__tests__/selectors.test.ts +34 -0
- package/conf/player/selectors.ts +10 -0
- package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
- package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +64 -35
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +104 -20
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
- package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
- package/manifestUtils/createConfig.js +4 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +33 -0
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +26 -21
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
- package/playerUtils/_internals/index.ts +1 -0
- package/playerUtils/_internals/utils.ts +31 -0
- package/playerUtils/configurationUtils.ts +0 -44
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +53 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +17 -10
- package/reactHooks/feed/useFeedLoader.tsx +36 -43
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/index.ts +13 -0
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +6 -4
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/mapAccum.test.ts +73 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +38 -1
- package/utils/mapAccum.ts +23 -0
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
- package/playerUtils/configurationGenerator.ts +0 -2572
|
@@ -5,6 +5,7 @@ import { createLogger, utilsLogger } from "../../../logger";
|
|
|
5
5
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
6
6
|
import {
|
|
7
7
|
findPluginByIdentifier,
|
|
8
|
+
loadFeedEntry,
|
|
8
9
|
loadFeedAndPrefetchThumbnailImage,
|
|
9
10
|
parseTimeToSeconds,
|
|
10
11
|
retrieveFeedUrl,
|
|
@@ -18,13 +19,6 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
|
|
|
18
19
|
parent: utilsLogger,
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
type ActionChapter = {
|
|
22
|
-
type: string;
|
|
23
|
-
options?: {
|
|
24
|
-
title: string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
22
|
type ChapterMarkerOriginal = {
|
|
29
23
|
id: string;
|
|
30
24
|
title: string;
|
|
@@ -33,12 +27,17 @@ type ChapterMarkerOriginal = {
|
|
|
33
27
|
actions: ActionChapter[];
|
|
34
28
|
};
|
|
35
29
|
|
|
36
|
-
export type
|
|
37
|
-
|
|
30
|
+
export type LiveMetadataEvent = {
|
|
31
|
+
programId: string;
|
|
32
|
+
assetId: string;
|
|
38
33
|
title: string;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
programStartTime: string;
|
|
35
|
+
programEndTime: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type LiveMetadataConfig = {
|
|
39
|
+
updateUrl: string;
|
|
40
|
+
updateInterval: number;
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
export type TitleSummaryEvent = {
|
|
@@ -65,11 +64,13 @@ export type PlayNextState = PlayNextConfig & {
|
|
|
65
64
|
export class OverlaysObserver {
|
|
66
65
|
readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
|
|
67
66
|
private playNextSubject: BehaviorSubject<PlayNextState>;
|
|
67
|
+
private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
|
|
68
68
|
private titleSummarySubject: BehaviorSubject<TitleSummaryEvent>;
|
|
69
69
|
private feedUrl: string;
|
|
70
70
|
private reloadData: () => void;
|
|
71
71
|
private updateTitleAndDescription: (data: any) => void;
|
|
72
72
|
private feedDataInterval: any;
|
|
73
|
+
private liveMetadataUpdateInterval: any;
|
|
73
74
|
private releasePlayerObserver?: () => void;
|
|
74
75
|
readonly entry: ZappEntry;
|
|
75
76
|
private chapterMarkerEvents: ChapterMarkerEvent[];
|
|
@@ -81,13 +82,17 @@ export class OverlaysObserver {
|
|
|
81
82
|
this.chapterSubject = new BehaviorSubject(null);
|
|
82
83
|
this.playNextSubject = new BehaviorSubject(null);
|
|
83
84
|
|
|
85
|
+
this.player = player;
|
|
86
|
+
this.entry = player.getEntry();
|
|
87
|
+
|
|
84
88
|
this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
|
|
85
|
-
title:
|
|
86
|
-
summary:
|
|
89
|
+
title: this.entry?.title || "",
|
|
90
|
+
summary: this.entry?.summary || "",
|
|
87
91
|
});
|
|
88
92
|
|
|
89
|
-
this.
|
|
90
|
-
|
|
93
|
+
this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
|
|
94
|
+
this.entry?.extensions?.liveMetadata || null
|
|
95
|
+
);
|
|
91
96
|
|
|
92
97
|
this.chapterMarkerEvents = this.prepareChapterMarkers();
|
|
93
98
|
this.releasePlayerObserver = this.subscribeToPlayerEvents();
|
|
@@ -95,7 +100,9 @@ export class OverlaysObserver {
|
|
|
95
100
|
this.reloadData = () => {};
|
|
96
101
|
this.updateTitleAndDescription = () => {};
|
|
97
102
|
this.feedDataInterval = null;
|
|
103
|
+
this.liveMetadataUpdateInterval = null;
|
|
98
104
|
void this.preparePlayNext();
|
|
105
|
+
void this.prepareLiveMetadata();
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
private setupFeedDataInterval(interval: number) {
|
|
@@ -113,6 +120,13 @@ export class OverlaysObserver {
|
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
public clearLiveMetadataUpdateInterval() {
|
|
124
|
+
if (this.liveMetadataUpdateInterval) {
|
|
125
|
+
clearInterval(this.liveMetadataUpdateInterval);
|
|
126
|
+
this.liveMetadataUpdateInterval = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
116
130
|
public setFeedDataHandlers(
|
|
117
131
|
feedUrl: string,
|
|
118
132
|
reloadData: () => void,
|
|
@@ -212,6 +226,48 @@ export class OverlaysObserver {
|
|
|
212
226
|
}
|
|
213
227
|
};
|
|
214
228
|
|
|
229
|
+
prepareLiveMetadata = async () => {
|
|
230
|
+
if (!this.player?.isLive?.()) {
|
|
231
|
+
log_debug("prepareLiveMetadata: Player is not live. Skipping...");
|
|
232
|
+
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const config: LiveMetadataConfig =
|
|
237
|
+
this.entry?.extensions?.liveMetadataConfig;
|
|
238
|
+
|
|
239
|
+
if (!config?.updateUrl || !config?.updateInterval) {
|
|
240
|
+
log_debug(
|
|
241
|
+
"prepareLiveMetadata: Live metadata configuration is not available. Skipping...",
|
|
242
|
+
{ config }
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const reloadData = async () => {
|
|
249
|
+
try {
|
|
250
|
+
const entry = await loadFeedEntry(config.updateUrl, this.entry);
|
|
251
|
+
|
|
252
|
+
this.onLiveMetadataUpdated(entry?.extensions?.liveMetadata || null);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
log_error("prepareLiveMetadata: Metadata fetching failed", {
|
|
255
|
+
error,
|
|
256
|
+
config,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
log_debug("prepareLiveMetadata: Setting up live metadata observer update", {
|
|
262
|
+
config,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const interval = Number(config?.updateInterval) || 60;
|
|
266
|
+
|
|
267
|
+
this.clearLiveMetadataUpdateInterval();
|
|
268
|
+
this.liveMetadataUpdateInterval = setInterval(reloadData, interval * 1000);
|
|
269
|
+
};
|
|
270
|
+
|
|
215
271
|
// TODO: Hack for video end, will be replaced with playlist prev/next in the future
|
|
216
272
|
getPlayNextEntry = () =>
|
|
217
273
|
!this.isCanceledByUser ? this.playNextConfig?.entry : null;
|
|
@@ -332,9 +388,11 @@ export class OverlaysObserver {
|
|
|
332
388
|
onPlayerClose = () => {
|
|
333
389
|
this.chapterSubject.complete();
|
|
334
390
|
this.playNextSubject.complete();
|
|
391
|
+
this.liveMetadataSubject.complete();
|
|
335
392
|
this.titleSummarySubject.complete();
|
|
336
393
|
this.releasePlayerObserver?.();
|
|
337
394
|
this.clearFeedDataInterval();
|
|
395
|
+
this.clearLiveMetadataUpdateInterval();
|
|
338
396
|
this.releasePlayerObserver = null;
|
|
339
397
|
};
|
|
340
398
|
|
|
@@ -367,4 +425,21 @@ export class OverlaysObserver {
|
|
|
367
425
|
(prev, curr) => prev?.triggerTime === curr?.triggerTime
|
|
368
426
|
)
|
|
369
427
|
);
|
|
428
|
+
|
|
429
|
+
private onLiveMetadataUpdated = (liveMetadataEvent: LiveMetadataEvent) => {
|
|
430
|
+
this.liveMetadataSubject.next(liveMetadataEvent);
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
public getLiveMetadataObservable = (): Observable<LiveMetadataEvent> => {
|
|
434
|
+
return this.liveMetadataSubject.pipe(
|
|
435
|
+
distinctUntilChanged(
|
|
436
|
+
(prev, curr) =>
|
|
437
|
+
prev?.programId === curr?.programId && prev?.assetId === curr?.assetId
|
|
438
|
+
)
|
|
439
|
+
);
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
public getLiveMetadataValue = (): LiveMetadataEvent => {
|
|
443
|
+
return this.liveMetadataSubject.value;
|
|
444
|
+
};
|
|
370
445
|
}
|
|
@@ -92,22 +92,26 @@ export const prefetchImage = (playableItem: ZappEntry, config: any = {}) => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Loads a feed entry from the given feed URL using the provided Zapp entry as context.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} feedUrl - The URL of the feed to load the entry from.
|
|
99
|
+
* @param {ZappEntry} entry - The Zapp entry to use as context for the request.
|
|
100
|
+
* @returns {Promise<ZappEntry>} A promise that resolves to the loaded Zapp entry.
|
|
101
|
+
* @throws {Error} If the feed loading fails or no entry is found in the response.
|
|
102
|
+
*/
|
|
103
|
+
export const loadFeedEntry = async (feedUrl: string, entry: ZappEntry) => {
|
|
100
104
|
const requestBuilder = new RequestBuilder()
|
|
101
105
|
.setEntryContext(entry)
|
|
102
106
|
.setScreenContext({} as ZappRiver)
|
|
103
|
-
.setUrl(
|
|
107
|
+
.setUrl(feedUrl);
|
|
104
108
|
|
|
105
109
|
const responseObject = await requestBuilder.call<ZappEntry>();
|
|
106
110
|
const responseHelper = new PipesClientResponseHelper(responseObject);
|
|
107
111
|
|
|
108
112
|
if (responseHelper.error) {
|
|
109
113
|
log_error(
|
|
110
|
-
`
|
|
114
|
+
`loadFeedEntry: loading failed with error: ${responseHelper.error.message}. Observer will not be executed`,
|
|
111
115
|
{
|
|
112
116
|
response: responseHelper.getLogsData(),
|
|
113
117
|
}
|
|
@@ -116,29 +120,37 @@ export const loadFeedAndPrefetchThumbnailImage = async (
|
|
|
116
120
|
throw responseHelper.error;
|
|
117
121
|
} else {
|
|
118
122
|
log_info(
|
|
119
|
-
`
|
|
123
|
+
`loadFeedEntry: Feed was successfully loaded for url: ${feedUrl}`,
|
|
120
124
|
responseHelper.getLogsData()
|
|
121
125
|
);
|
|
122
126
|
|
|
123
|
-
const
|
|
127
|
+
const entry = responseHelper.responseData?.entry[0];
|
|
124
128
|
|
|
125
|
-
if (!
|
|
126
|
-
|
|
127
|
-
"
|
|
128
|
-
responseHelper.getLogsData()
|
|
129
|
-
);
|
|
129
|
+
if (!entry) {
|
|
130
|
+
const error =
|
|
131
|
+
"loadFeedEntry: Can not retrieve entry, feed was loaded but no entry was found";
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
"Can not retrieve play next entry, feed was loaded but no entry was found"
|
|
133
|
-
);
|
|
134
|
-
}
|
|
133
|
+
log_error(error, responseHelper.getLogsData());
|
|
135
134
|
|
|
136
|
-
|
|
135
|
+
throw new Error(error);
|
|
136
|
+
}
|
|
137
137
|
|
|
138
|
-
return
|
|
138
|
+
return entry;
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
+
export const loadFeedAndPrefetchThumbnailImage = async (
|
|
143
|
+
playNextFeedUrl: string,
|
|
144
|
+
entry: ZappEntry,
|
|
145
|
+
playNextPlugin
|
|
146
|
+
) => {
|
|
147
|
+
const playNextEntry = await loadFeedEntry(playNextFeedUrl, entry);
|
|
148
|
+
|
|
149
|
+
prefetchImage(playNextEntry, playNextPlugin?.configuration);
|
|
150
|
+
|
|
151
|
+
return playNextEntry;
|
|
152
|
+
};
|
|
153
|
+
|
|
142
154
|
export const findPluginByIdentifier = (
|
|
143
155
|
identifier: string,
|
|
144
156
|
plugins: ZappPlugin[]
|
|
@@ -2,6 +2,27 @@ export const userPreferencesNamespace = "user_preferences";
|
|
|
2
2
|
|
|
3
3
|
export const skipActionType = "show_skip";
|
|
4
4
|
|
|
5
|
+
export class PlayerError
|
|
6
|
+
extends Error
|
|
7
|
+
implements QuickBrickPlayer.PlayerErrorI
|
|
8
|
+
{
|
|
9
|
+
description: string;
|
|
10
|
+
|
|
11
|
+
constructor(message: string, description: string) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.description = description;
|
|
14
|
+
|
|
15
|
+
Object.setPrototypeOf(this, PlayerError.prototype);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
toObject() {
|
|
19
|
+
return {
|
|
20
|
+
error: this.message,
|
|
21
|
+
message: this.description,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
5
26
|
export enum SharedPlayerCallBacksKeys {
|
|
6
27
|
OnPlayerResume = "onPlayerResume",
|
|
7
28
|
OnPlayerPause = "onPlayerPause",
|
|
@@ -5,6 +5,9 @@ import { playerManager } from "./index";
|
|
|
5
5
|
import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
|
|
6
6
|
import { PlayerRole } from "./conts";
|
|
7
7
|
import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
|
|
8
|
+
import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
|
|
9
|
+
import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
|
|
10
|
+
import { isTV } from "../../reactUtils";
|
|
8
11
|
|
|
9
12
|
// TODO: Rename to ControllerType
|
|
10
13
|
export const usePlayerControllerSetup = ({
|
|
@@ -76,5 +79,18 @@ export const usePlayerControllerSetup = ({
|
|
|
76
79
|
};
|
|
77
80
|
}, [playerId, playerController]);
|
|
78
81
|
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!isTV()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (playerController) {
|
|
88
|
+
const seekController = new TVSeekController(playerController);
|
|
89
|
+
playerController.seekController = seekController;
|
|
90
|
+
|
|
91
|
+
return KeyInputHandler.getInstance().addListener(seekController);
|
|
92
|
+
}
|
|
93
|
+
}, [playerController]);
|
|
94
|
+
|
|
79
95
|
return playerController;
|
|
80
96
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { allTruthy } from "..";
|
|
2
|
+
|
|
3
|
+
describe("allTruthy", () => {
|
|
4
|
+
it("should return true when all values are true", () => {
|
|
5
|
+
expect(allTruthy([true, true, true])).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should return false when at least one value is false", () => {
|
|
9
|
+
expect(allTruthy([true, false, true])).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should return false when all values are false", () => {
|
|
13
|
+
expect(allTruthy([false, false, false])).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should return false for an empty array", () => {
|
|
17
|
+
expect(allTruthy([])).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should handle single-element arrays correctly", () => {
|
|
21
|
+
expect(allTruthy([true])).toBe(true);
|
|
22
|
+
expect(allTruthy([false])).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { anyTruthy } from "..";
|
|
2
|
+
|
|
3
|
+
describe("anyTruthy", () => {
|
|
4
|
+
it("should return true when at least one value is true", () => {
|
|
5
|
+
expect(anyTruthy([false, true, false])).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should return false when all values are false", () => {
|
|
9
|
+
expect(anyTruthy([false, false, false])).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should return true when all values are true", () => {
|
|
13
|
+
expect(anyTruthy([true, true, true])).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should return false for an empty array", () => {
|
|
17
|
+
expect(anyTruthy([])).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should handle single-element arrays correctly", () => {
|
|
21
|
+
expect(anyTruthy([true])).toBe(true);
|
|
22
|
+
expect(anyTruthy([false])).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isEmptyArray } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isEmptyArray", () => {
|
|
4
|
+
it("non-empty array is not empty", () => {
|
|
5
|
+
const value = [1, 2, 3];
|
|
6
|
+
|
|
7
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("empty array is empty", () => {
|
|
11
|
+
const value = [];
|
|
12
|
+
|
|
13
|
+
expect(isEmptyArray(value)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("number is not array", () => {
|
|
17
|
+
const value = 123;
|
|
18
|
+
|
|
19
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("string is not array", () => {
|
|
23
|
+
const value = "vfnjdk";
|
|
24
|
+
|
|
25
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("empty string is not array", () => {
|
|
29
|
+
const value = "";
|
|
30
|
+
|
|
31
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("NaN is not array", () => {
|
|
35
|
+
const value = NaN;
|
|
36
|
+
|
|
37
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("object is not array", () => {
|
|
41
|
+
const value = { test: 1 };
|
|
42
|
+
|
|
43
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("empty object is not array", () => {
|
|
47
|
+
const value = {};
|
|
48
|
+
|
|
49
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("undefined is not array", () => {
|
|
53
|
+
const value = undefined;
|
|
54
|
+
|
|
55
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("null is not array", () => {
|
|
59
|
+
const value = null;
|
|
60
|
+
|
|
61
|
+
expect(isEmptyArray(value)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
package/arrayUtils/index.ts
CHANGED
|
@@ -93,21 +93,31 @@ export const isIndexInRange = (index: number, length: number): boolean => {
|
|
|
93
93
|
export const makeListOfIndexes = (size: number): number[] =>
|
|
94
94
|
Array.from({ length: size }, (_, index) => index);
|
|
95
95
|
|
|
96
|
-
export const makeListOf = (value:
|
|
96
|
+
export const makeListOf = <T>(value: T, size: number): T[] => {
|
|
97
97
|
return Array(size).fill(value);
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
/** Checks if a value is a non-empty array */
|
|
101
101
|
export function isFilledArray(value: unknown): boolean {
|
|
102
|
-
return
|
|
102
|
+
return Array.isArray(value) && value.length > 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Checks if a value is a empty array */
|
|
106
|
+
export function isEmptyArray(value: unknown): boolean {
|
|
107
|
+
return Array.isArray(value) && value.length === 0;
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
// get random item from the list
|
|
106
111
|
export const sample = (xs: unknown[]): unknown => {
|
|
107
|
-
invariant(
|
|
112
|
+
invariant(Array.isArray(xs), `input value is not an array: ${xs}`);
|
|
108
113
|
invariant(isFilledArray(xs), `input array is empty: ${xs}`);
|
|
109
114
|
|
|
110
115
|
const index = Math.floor(Math.random() * xs.length);
|
|
111
116
|
|
|
112
117
|
return xs[index];
|
|
113
118
|
};
|
|
119
|
+
|
|
120
|
+
export const allTruthy = (xs: boolean[]) =>
|
|
121
|
+
isFilledArray(xs) && xs.every(Boolean);
|
|
122
|
+
|
|
123
|
+
export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { getArtworkImage } from "..";
|
|
2
|
+
import { DEFAULT_IMAGE } from "../assets";
|
|
3
|
+
|
|
4
|
+
describe("getArtworkImage", () => {
|
|
5
|
+
const entryWithImage = {
|
|
6
|
+
media_group: [
|
|
7
|
+
{
|
|
8
|
+
type: "image",
|
|
9
|
+
media_item: [
|
|
10
|
+
{ key: "artwork_key", src: "image_from_entry" },
|
|
11
|
+
{ key: "other_key", src: "other_image" },
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
extensions: {
|
|
16
|
+
artwork_key: "artwork_key",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const entryWithoutImage = {
|
|
21
|
+
media_group: [
|
|
22
|
+
{
|
|
23
|
+
type: "image",
|
|
24
|
+
media_item: [{ key: "other_key", src: "other_image" }],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
extensions: {
|
|
28
|
+
artwork_key: "artwork_key",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const pluginConfigWithImage = {
|
|
33
|
+
artwork_key: "plugin_artwork_key",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
it("returns image from entry extensions key", () => {
|
|
37
|
+
const result = getArtworkImage({
|
|
38
|
+
key: "artwork_key",
|
|
39
|
+
entry: entryWithImage,
|
|
40
|
+
plugin_configuration: {},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(result).toBe("image_from_entry");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns image from plugin configuration key if not in entry", () => {
|
|
47
|
+
const entryNoMatch = {
|
|
48
|
+
...entryWithoutImage,
|
|
49
|
+
extensions: { artwork_key: "not_found_key" },
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const pluginConfig = {
|
|
53
|
+
artwork_key: "plugin_artwork_key",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const entryWithPluginImage = {
|
|
57
|
+
...entryNoMatch,
|
|
58
|
+
media_group: [
|
|
59
|
+
{
|
|
60
|
+
type: "image",
|
|
61
|
+
media_item: [{ key: "plugin_artwork_key", src: "image_from_plugin" }],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const result = getArtworkImage({
|
|
67
|
+
key: "artwork_key",
|
|
68
|
+
entry: entryWithPluginImage,
|
|
69
|
+
plugin_configuration: pluginConfig,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(result).toBe("image_from_plugin");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("returns DEFAULT_IMAGE if neither entry nor plugin configuration has image", () => {
|
|
76
|
+
const entryNoImage = {
|
|
77
|
+
media_group: [
|
|
78
|
+
{
|
|
79
|
+
type: "image",
|
|
80
|
+
media_item: [{ key: "other_key", src: "other_image" }],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
extensions: { artwork_key: "not_found_key" },
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const pluginConfig = { artwork_key: "not_found_key" };
|
|
87
|
+
|
|
88
|
+
const result = getArtworkImage({
|
|
89
|
+
key: "artwork_key",
|
|
90
|
+
entry: entryNoImage,
|
|
91
|
+
plugin_configuration: pluginConfig,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(result).toBe(DEFAULT_IMAGE);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("handles undefined key gracefully", () => {
|
|
98
|
+
const result = getArtworkImage({
|
|
99
|
+
key: undefined,
|
|
100
|
+
entry: entryWithImage,
|
|
101
|
+
plugin_configuration: pluginConfigWithImage,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(result).toBe(DEFAULT_IMAGE);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("handles missing entry or plugin_configuration gracefully", () => {
|
|
108
|
+
const result = getArtworkImage({
|
|
109
|
+
key: "artwork_key",
|
|
110
|
+
entry: undefined,
|
|
111
|
+
plugin_configuration: undefined,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(result).toBe(DEFAULT_IMAGE);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("handles empty media_group", () => {
|
|
118
|
+
const entryEmptyMedia = {
|
|
119
|
+
media_group: [],
|
|
120
|
+
extensions: { artwork_key: "artwork_key" },
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const result = getArtworkImage({
|
|
124
|
+
key: "artwork_key",
|
|
125
|
+
entry: entryEmptyMedia,
|
|
126
|
+
plugin_configuration: pluginConfigWithImage,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(result).toBe(DEFAULT_IMAGE);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("handles missing extensions/config keys", () => {
|
|
133
|
+
const entryNoExt = { media_group: [], extensions: {} };
|
|
134
|
+
const pluginConfig = {};
|
|
135
|
+
|
|
136
|
+
const result = getArtworkImage({
|
|
137
|
+
key: "artwork_key",
|
|
138
|
+
entry: entryNoExt,
|
|
139
|
+
plugin_configuration: pluginConfig,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
expect(result).toBe(DEFAULT_IMAGE);
|
|
143
|
+
});
|
|
144
|
+
});
|