@applicaster/zapp-react-native-utils 16.0.0-rc.7 → 16.0.0-rc.71
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 +47 -11
- package/actionsExecutor/ActionExecutorContext.tsx +87 -316
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -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 +100 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
- package/actionsExecutor/actions/index.ts +34 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +137 -0
- package/actionsExecutor/actions/openBottomSheet.ts +320 -0
- package/actionsExecutor/actions/refreshComponent.ts +85 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/showToast.ts +87 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/consts.ts +23 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +59 -0
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
- package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
- package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/index.js +20 -0
- package/analyticsUtils/analyticsMapper.ts +4 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
- package/appUtils/HooksManager/index.ts +12 -8
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/index.ts +1 -1
- package/appUtils/contextKeysManager/utils/index.ts +38 -25
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -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 +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +150 -0
- 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 +18 -35
- 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__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +136 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/index.ts +33 -8
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
- package/configurationUtils/manifestKeyParser.ts +38 -9
- package/configurationUtils/modalBlocksParser.ts +178 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +327 -19
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/keys.js +9 -0
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/defaults.js +3 -1
- package/manifestUtils/modalBlocks.js +304 -0
- package/manifestUtils/platformIsTV.js +1 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +199 -0
- package/modalState/RemoteEditableCollection.ts +227 -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 +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/index.ts +30 -83
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +133 -0
- package/modalState/useBottomSheetContent.ts +102 -0
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
- package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
- package/pipesUtils/index.ts +1 -0
- package/pipesUtils/withPipesEndpoint.tsx +54 -0
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +41 -14
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/actions/index.ts +51 -1
- package/reactHooks/cell-click/index.ts +18 -10
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/feed/index.ts +5 -1
- package/reactHooks/feed/useBatchLoading.ts +9 -1
- package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/index.ts +1 -1
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +13 -2
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
- package/riverComponetsMeasurementProvider/index.tsx +12 -8
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/index.ts +203 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -4,8 +4,14 @@ import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
|
4
4
|
import { postAnalyticEvent } from "./manager";
|
|
5
5
|
import { isLive } from "../playerUtils";
|
|
6
6
|
import { extensionsEvents } from "./AnalyticsEvents/helper";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
AD_EVENT,
|
|
9
|
+
EVENT_TYPES,
|
|
10
|
+
GENERAL_EVENT,
|
|
11
|
+
PLAYER_DISPLAY_STATES,
|
|
12
|
+
} from "./events";
|
|
8
13
|
import { Player } from "../appUtils/playerManager/player";
|
|
14
|
+
import { isNil } from "@applicaster/zapp-react-native-utils/utils";
|
|
9
15
|
|
|
10
16
|
export interface PlayerAnalyticsTrackerI {
|
|
11
17
|
handleAnalyticEvent(
|
|
@@ -13,6 +19,8 @@ export interface PlayerAnalyticsTrackerI {
|
|
|
13
19
|
eventData?: QuickBrickPlayer.EventData
|
|
14
20
|
): void;
|
|
15
21
|
setPlayer(player: Player): void;
|
|
22
|
+
onPlayerPresented(): void;
|
|
23
|
+
onPlayerClosed(): void;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
@@ -26,6 +34,15 @@ export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
|
26
34
|
this.player = player;
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
onPlayerPresented() {
|
|
38
|
+
this.handleAnalyticEvent(GENERAL_EVENT.player_presented);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onPlayerClosed() {
|
|
42
|
+
this.handleAnalyticEvent(GENERAL_EVENT.session_end);
|
|
43
|
+
this.handleAnalyticEvent(GENERAL_EVENT.player_closed);
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
isAdBreak(event: string): boolean {
|
|
30
47
|
const adBreakEvents = [
|
|
31
48
|
AD_EVENT.ad_break_start,
|
|
@@ -180,7 +197,8 @@ export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
|
180
197
|
this.entry?.extensions?.free || this.entry?.extensions?.isFree;
|
|
181
198
|
|
|
182
199
|
const title = this.entry?.title;
|
|
183
|
-
const
|
|
200
|
+
const isStreamLive = isLive(this.entry);
|
|
201
|
+
const streamType = isStreamLive ? "live" : "vod"; // Todo: determine other types, channel, podcast, aod
|
|
184
202
|
|
|
185
203
|
const currentPosition = this.getCurrentPosition(
|
|
186
204
|
event,
|
|
@@ -201,6 +219,7 @@ export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
|
201
219
|
);
|
|
202
220
|
|
|
203
221
|
const playerState = this.getPlayerState();
|
|
222
|
+
const playerType = this.player?.playerPluginId;
|
|
204
223
|
|
|
205
224
|
const analyticsCustomProperties = extensionsEvents(this.entry?.extensions);
|
|
206
225
|
|
|
@@ -210,7 +229,11 @@ export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
|
210
229
|
name: title,
|
|
211
230
|
media_type: mediaType,
|
|
212
231
|
stream_type: streamType,
|
|
213
|
-
|
|
232
|
+
player_type: playerType,
|
|
233
|
+
// We do not pass duration for live streams anymore (it's now seekableDuration),
|
|
234
|
+
// but we can't mark it as optional in Analytics Mapper yet,
|
|
235
|
+
// so we set it to -1 for live streams
|
|
236
|
+
duration: isStreamLive && isNil(mediaDuration) ? -1 : mediaDuration,
|
|
214
237
|
current_position: currentPosition,
|
|
215
238
|
player_state: playerState,
|
|
216
239
|
stream_format: contentType,
|
|
@@ -87,7 +87,7 @@ export function HooksManager({
|
|
|
87
87
|
}: HookManagerArgs): HookManager {
|
|
88
88
|
hooksManagerLogger.addContext({ targetScreenId: targetScreen.id });
|
|
89
89
|
|
|
90
|
-
function logHookEvent(func, message, data) {
|
|
90
|
+
function logHookEvent(func, message, data = {}) {
|
|
91
91
|
func({
|
|
92
92
|
message,
|
|
93
93
|
data: __DEV__ ? data : null,
|
|
@@ -344,7 +344,6 @@ export function HooksManager({
|
|
|
344
344
|
`hookCallback: send app to background, cancelled flow blocker hook ${hookPlugin.identifier} on home screen`,
|
|
345
345
|
{
|
|
346
346
|
payload,
|
|
347
|
-
hook: hookPlugin,
|
|
348
347
|
}
|
|
349
348
|
);
|
|
350
349
|
|
|
@@ -356,17 +355,13 @@ export function HooksManager({
|
|
|
356
355
|
`hookCallback: hook successfully finished: ${hookPlugin.identifier}`,
|
|
357
356
|
{
|
|
358
357
|
payload,
|
|
359
|
-
hook: hookPlugin,
|
|
360
358
|
}
|
|
361
359
|
);
|
|
362
360
|
|
|
363
361
|
if (!callback) {
|
|
364
362
|
logHookEvent(
|
|
365
|
-
hooksManagerLogger.
|
|
366
|
-
`hookCallback: ${hookPlugin.identifier} is missing \`callback\`, using hookCallback(default one)
|
|
367
|
-
{
|
|
368
|
-
hookPlugin,
|
|
369
|
-
}
|
|
363
|
+
hooksManagerLogger.debug,
|
|
364
|
+
`hookCallback: ${hookPlugin.identifier} is missing \`callback\`, using hookCallback(default one)`
|
|
370
365
|
);
|
|
371
366
|
|
|
372
367
|
callback = hookCallback;
|
|
@@ -503,6 +498,15 @@ export function HooksManager({
|
|
|
503
498
|
presentUI
|
|
504
499
|
);
|
|
505
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
|
+
|
|
506
510
|
hookPlugin.setStateAndNotify(HOOKS_EVENTS.ERROR, {
|
|
507
511
|
error: e,
|
|
508
512
|
hookPlugin,
|
|
@@ -46,7 +46,7 @@ describe("Context Keys Manager - getKey", () => {
|
|
|
46
46
|
|
|
47
47
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
48
48
|
message:
|
|
49
|
-
"Provided key is not valid -
|
|
49
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
50
50
|
data: { key: invalidKey },
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -47,7 +47,7 @@ describe("Context Keys Manager - removeKey", () => {
|
|
|
47
47
|
|
|
48
48
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
49
49
|
message:
|
|
50
|
-
"Provided key is not valid -
|
|
50
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
51
51
|
data: { key },
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -48,7 +48,7 @@ describe("Context Keys Manager - setKey", () => {
|
|
|
48
48
|
|
|
49
49
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
50
50
|
message:
|
|
51
|
-
"Provided key is not valid -
|
|
51
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
52
52
|
data: { key },
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -105,7 +105,7 @@ describe("Context Keys Manager - setKey", () => {
|
|
|
105
105
|
|
|
106
106
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
107
107
|
message:
|
|
108
|
-
"Provided key is not valid -
|
|
108
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
109
109
|
data: { key },
|
|
110
110
|
});
|
|
111
111
|
|
|
@@ -162,7 +162,7 @@ describe("Context Keys Manager - setKey", () => {
|
|
|
162
162
|
|
|
163
163
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
164
164
|
message:
|
|
165
|
-
"Provided key is not valid -
|
|
165
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
166
166
|
data: { key },
|
|
167
167
|
});
|
|
168
168
|
|
|
@@ -217,7 +217,7 @@ describe("Context Keys Manager - setKey", () => {
|
|
|
217
217
|
|
|
218
218
|
expect(mockedLogger.warn).toHaveBeenCalledWith({
|
|
219
219
|
message:
|
|
220
|
-
"Provided key is not valid -
|
|
220
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
221
221
|
data: { key },
|
|
222
222
|
});
|
|
223
223
|
|
|
@@ -109,7 +109,7 @@ export class ContextKeysManager {
|
|
|
109
109
|
if (!keyIsValid(parsedKey)) {
|
|
110
110
|
this._logger.warn({
|
|
111
111
|
message:
|
|
112
|
-
"Provided key is not valid -
|
|
112
|
+
"Provided key is not valid - expecting an object with namespace and key properties",
|
|
113
113
|
data: { key },
|
|
114
114
|
});
|
|
115
115
|
|
|
@@ -1,40 +1,53 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
1
|
import { DEFAULT_NAMESPACE } from "../consts";
|
|
3
2
|
import { KeyName, KeyNameObj } from "../index";
|
|
4
3
|
|
|
5
|
-
const lastDotRegex = /\.([^.]+)$/;
|
|
6
|
-
const splitByLastDot = R.compose(R.init, R.split(lastDotRegex));
|
|
7
|
-
|
|
8
4
|
export function getNamespaceAndKey(namespacedKey: KeyName): KeyNameObj {
|
|
9
5
|
if (typeof namespacedKey !== "string") return namespacedKey;
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
if (!namespacedKey.includes(".")) {
|
|
8
|
+
return { namespace: DEFAULT_NAMESPACE, key: namespacedKey };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// split on the last dot - the namespace itself may contain dots
|
|
12
|
+
const lastDotIndex = namespacedKey.lastIndexOf(".");
|
|
14
13
|
|
|
15
|
-
return
|
|
14
|
+
return {
|
|
15
|
+
namespace: namespacedKey.slice(0, lastDotIndex),
|
|
16
|
+
key: namespacedKey.slice(lastDotIndex + 1),
|
|
17
|
+
};
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
+
const hasOwn = (obj: object, prop: string): boolean =>
|
|
21
|
+
Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
|
|
23
|
+
const isEmpty = (value: unknown): boolean => {
|
|
24
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
25
|
+
return value.length === 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (value !== null && typeof value === "object") {
|
|
29
|
+
return Object.keys(value).length === 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const keyIsValid = (parsedKey: unknown): boolean => {
|
|
36
|
+
if (parsedKey == null) return false;
|
|
37
|
+
if (typeof parsedKey === "string") return false;
|
|
38
|
+
if (Array.isArray(parsedKey)) return false;
|
|
20
39
|
|
|
21
|
-
const
|
|
40
|
+
const obj = parsedKey as Record<string, unknown>;
|
|
22
41
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
propIsNotNullOrUndefined("key"),
|
|
30
|
-
propIsNotNullOrUndefined("namespace"),
|
|
31
|
-
propIsNotEmpty("key"),
|
|
32
|
-
propIsNotEmpty("namespace"),
|
|
33
|
-
]);
|
|
42
|
+
if (!hasOwn(obj, "key") || !hasOwn(obj, "namespace")) return false;
|
|
43
|
+
if (obj.key == null || obj.namespace == null) return false;
|
|
44
|
+
if (isEmpty(obj.key) || isEmpty(obj.namespace)) return false;
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
34
48
|
|
|
35
49
|
export const buildNamespaceKey = (key: string, namespace: string) =>
|
|
36
50
|
`${namespace}.${key}`;
|
|
37
51
|
|
|
38
|
-
export const savingResultIsSuccess = (result: unknown): boolean =>
|
|
39
|
-
|
|
40
|
-
};
|
|
52
|
+
export const savingResultIsSuccess = (result: unknown): boolean =>
|
|
53
|
+
typeof result === "boolean" && result === true;
|
|
@@ -3,8 +3,8 @@ import { distinctUntilChanged } from "rxjs/operators";
|
|
|
3
3
|
import { Player } from "../player";
|
|
4
4
|
import { createLogger, utilsLogger } from "../../../logger";
|
|
5
5
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
6
|
+
import { findPluginByIdentifier } from "../../../pluginUtils";
|
|
6
7
|
import {
|
|
7
|
-
findPluginByIdentifier,
|
|
8
8
|
loadFeedEntry,
|
|
9
9
|
loadFeedAndPrefetchThumbnailImage,
|
|
10
10
|
parseTimeToSeconds,
|
|
@@ -19,6 +19,12 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
|
|
|
19
19
|
parent: utilsLogger,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Mirrors `initial_value` for `audio_live_player_update_interval` in
|
|
24
|
+
* `defaultManifestConfigurations/player.js`.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS = 60;
|
|
27
|
+
|
|
22
28
|
type ChapterMarkerOriginal = {
|
|
23
29
|
id: string;
|
|
24
30
|
title: string;
|
|
@@ -40,11 +46,6 @@ export type LiveMetadataConfig = {
|
|
|
40
46
|
updateInterval: number;
|
|
41
47
|
};
|
|
42
48
|
|
|
43
|
-
export type TitleSummaryEvent = {
|
|
44
|
-
title: string | number;
|
|
45
|
-
summary: string | number;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
49
|
type ChapterMarkersObserverProps = {
|
|
49
50
|
player: Player;
|
|
50
51
|
};
|
|
@@ -59,24 +60,23 @@ type PlayNextConfig = {
|
|
|
59
60
|
export type PlayNextState = PlayNextConfig & {
|
|
60
61
|
triggerTime: number;
|
|
61
62
|
handleUserCancelPlayNext: () => void;
|
|
63
|
+
hidePlayNext: () => void;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export class OverlaysObserver {
|
|
65
67
|
readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
|
|
66
68
|
private playNextSubject: BehaviorSubject<PlayNextState>;
|
|
67
69
|
private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private updateTitleAndDescription: (data: any) => void;
|
|
72
|
-
private feedDataInterval: any;
|
|
70
|
+
private liveContentInterval: any;
|
|
71
|
+
private liveContentGeneration = 0;
|
|
72
|
+
private _liveEntry: ZappEntry | null = null;
|
|
73
73
|
private liveMetadataUpdateInterval: any;
|
|
74
74
|
private releasePlayerObserver?: () => void;
|
|
75
75
|
readonly entry: ZappEntry;
|
|
76
76
|
private chapterMarkerEvents: ChapterMarkerEvent[];
|
|
77
77
|
readonly player: Player;
|
|
78
78
|
private playNextConfig?: PlayNextConfig;
|
|
79
|
-
private
|
|
79
|
+
private isPlayNextSuppressed = false;
|
|
80
80
|
|
|
81
81
|
constructor({ player }: ChapterMarkersObserverProps) {
|
|
82
82
|
this.chapterSubject = new BehaviorSubject(null);
|
|
@@ -85,41 +85,140 @@ export class OverlaysObserver {
|
|
|
85
85
|
this.player = player;
|
|
86
86
|
this.entry = player.getEntry();
|
|
87
87
|
|
|
88
|
-
this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
|
|
89
|
-
title: this.entry?.title || "",
|
|
90
|
-
summary: this.entry?.summary || "",
|
|
91
|
-
});
|
|
92
|
-
|
|
93
88
|
this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
|
|
94
89
|
this.entry?.extensions?.liveMetadata || null
|
|
95
90
|
);
|
|
96
91
|
|
|
97
92
|
this.chapterMarkerEvents = this.prepareChapterMarkers();
|
|
98
93
|
this.releasePlayerObserver = this.subscribeToPlayerEvents();
|
|
99
|
-
this.
|
|
100
|
-
this.reloadData = () => {};
|
|
101
|
-
this.updateTitleAndDescription = () => {};
|
|
102
|
-
this.feedDataInterval = null;
|
|
94
|
+
this.liveContentInterval = null;
|
|
103
95
|
this.liveMetadataUpdateInterval = null;
|
|
104
96
|
void this.preparePlayNext();
|
|
105
97
|
void this.prepareLiveMetadata();
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Polls the live feed and pushes each loaded entry into the player, which
|
|
102
|
+
* re-resolves its Title/Subtitle and publishes on its content channel.
|
|
103
|
+
*
|
|
104
|
+
* Runs entirely outside React: `loadFeedEntry` builds its request through
|
|
105
|
+
* `RequestBuilder.setUrl`, which inflates URL macros with the entry and
|
|
106
|
+
* screen contexts, so no `useInflatedUrl` is needed. `prepareLiveMetadata`
|
|
107
|
+
* below already polls this way.
|
|
108
|
+
*/
|
|
109
|
+
public startLiveContentUpdates() {
|
|
110
|
+
this.stopLiveContentUpdates();
|
|
111
|
+
|
|
112
|
+
if (!this.player?.isLive?.()) {
|
|
113
|
+
log_debug("startLiveContentUpdates: Player is not live. Skipping...");
|
|
114
|
+
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const feedUrl = this.getLiveContentFeedUrl();
|
|
119
|
+
|
|
120
|
+
if (!feedUrl) {
|
|
121
|
+
log_debug(
|
|
122
|
+
"startLiveContentUpdates: Entry carries no live channel feed. Skipping..."
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return;
|
|
113
126
|
}
|
|
127
|
+
|
|
128
|
+
const intervalSeconds = this.getLiveContentUpdateInterval();
|
|
129
|
+
|
|
130
|
+
// Clearing the interval cannot cancel a request already in flight, so each
|
|
131
|
+
// run carries the generation it started in. A response that arrives after
|
|
132
|
+
// a stop or a restart belongs to a channel that is no longer playing and
|
|
133
|
+
// is dropped, rather than publishing the previous programme's title over
|
|
134
|
+
// the current one.
|
|
135
|
+
const generation = ++this.liveContentGeneration;
|
|
136
|
+
|
|
137
|
+
const load = async () => {
|
|
138
|
+
try {
|
|
139
|
+
const entry = await loadFeedEntry(feedUrl, this.entry);
|
|
140
|
+
|
|
141
|
+
if (generation !== this.liveContentGeneration) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this._liveEntry = entry;
|
|
146
|
+
this.player.publishContent();
|
|
147
|
+
} catch {
|
|
148
|
+
// `loadFeedEntry` already logs the failure. Keep whatever content is
|
|
149
|
+
// currently published rather than blanking the title on a transient
|
|
150
|
+
// network error.
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
void load();
|
|
155
|
+
|
|
156
|
+
this.liveContentInterval = setInterval(load, intervalSeconds * 1000);
|
|
114
157
|
}
|
|
115
158
|
|
|
116
|
-
public
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
159
|
+
public stopLiveContentUpdates() {
|
|
160
|
+
// Invalidates any in-flight request as well as the interval.
|
|
161
|
+
this.liveContentGeneration += 1;
|
|
162
|
+
|
|
163
|
+
if (this.liveContentInterval) {
|
|
164
|
+
clearInterval(this.liveContentInterval);
|
|
165
|
+
this.liveContentInterval = null;
|
|
120
166
|
}
|
|
121
167
|
}
|
|
122
168
|
|
|
169
|
+
/**
|
|
170
|
+
* The programme feed for the channel currently playing. Derived here rather
|
|
171
|
+
* than by the caller so no UI component needs to know where a live channel
|
|
172
|
+
* keeps its feed, or that the URL has to be rewritten to reach the
|
|
173
|
+
* programme ("livePage") view of it.
|
|
174
|
+
*/
|
|
175
|
+
private getLiveContentFeedUrl(): string {
|
|
176
|
+
const channelSrc =
|
|
177
|
+
this.player.getEntry()?.extensions?.live?.channel_src ?? "";
|
|
178
|
+
|
|
179
|
+
return channelSrc.replace(new RegExp("subClass", "g"), "livePage");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Falls back to the manifest's own `initial_value` when the app ships no
|
|
184
|
+
* value: `intervalSeconds * 1000` would otherwise be `NaN`, and
|
|
185
|
+
* `setInterval` treats `NaN` as `0` - a tight loop hammering the feed.
|
|
186
|
+
*/
|
|
187
|
+
private getLiveContentUpdateInterval(): number {
|
|
188
|
+
const configured =
|
|
189
|
+
this.player.getPluginConfiguration()?.audio_live_player_update_interval;
|
|
190
|
+
|
|
191
|
+
const seconds = Number(configured);
|
|
192
|
+
|
|
193
|
+
return Number.isFinite(seconds) && seconds > 0
|
|
194
|
+
? seconds
|
|
195
|
+
: DEFAULT_LIVE_CONTENT_UPDATE_INTERVAL_SECONDS;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The entry most recently loaded from the live channel feed - the programme
|
|
200
|
+
* currently on air, as opposed to `player.entry`, which is the channel and
|
|
201
|
+
* stays put for the whole listening session.
|
|
202
|
+
*
|
|
203
|
+
* Read by `Player.getContent()`, which prefers it over the player's own
|
|
204
|
+
* entry. It lives here rather than on `Player` because it is live-feed
|
|
205
|
+
* state, like `liveMetadata` and play-next: a VOD or cast player never has
|
|
206
|
+
* an observer at all, so it never carries this either.
|
|
207
|
+
*/
|
|
208
|
+
public get liveEntry(): ZappEntry | null {
|
|
209
|
+
return this._liveEntry;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Called by `Player`'s `entry` setter. The live entry is an overlay on the
|
|
214
|
+
* current entry, so its lifetime is scoped to that entry: without this, a
|
|
215
|
+
* programme from a previous channel would shadow the new one forever - the
|
|
216
|
+
* content would change but the title would not.
|
|
217
|
+
*/
|
|
218
|
+
public clearLiveEntry() {
|
|
219
|
+
this._liveEntry = null;
|
|
220
|
+
}
|
|
221
|
+
|
|
123
222
|
public clearLiveMetadataUpdateInterval() {
|
|
124
223
|
if (this.liveMetadataUpdateInterval) {
|
|
125
224
|
clearInterval(this.liveMetadataUpdateInterval);
|
|
@@ -127,25 +226,13 @@ export class OverlaysObserver {
|
|
|
127
226
|
}
|
|
128
227
|
}
|
|
129
228
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
updateTitleAndDescription: (data: any) => void
|
|
135
|
-
) {
|
|
136
|
-
this.feedUrl = feedUrl;
|
|
137
|
-
this.reloadData = reloadData;
|
|
138
|
-
this.updateTitleAndDescription = updateTitleAndDescription;
|
|
139
|
-
this.setupFeedDataInterval(interval);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public getTitleSummaryObservable(): Observable<TitleSummaryEvent> {
|
|
143
|
-
return this.titleSummarySubject.asObservable().pipe(distinctUntilChanged());
|
|
144
|
-
}
|
|
229
|
+
hidePlayNext = () => {
|
|
230
|
+
this.isPlayNextSuppressed = true;
|
|
231
|
+
this.playNextSubject.next(null);
|
|
232
|
+
};
|
|
145
233
|
|
|
146
234
|
handleUserCancelPlayNext = () => {
|
|
147
|
-
this.
|
|
148
|
-
this.playNextSubject.next(null);
|
|
235
|
+
this.hidePlayNext();
|
|
149
236
|
};
|
|
150
237
|
|
|
151
238
|
preparePlayNext = async () => {
|
|
@@ -165,7 +252,10 @@ export class OverlaysObserver {
|
|
|
165
252
|
return;
|
|
166
253
|
}
|
|
167
254
|
|
|
168
|
-
const playNextFeedUrl: string = retrieveFeedUrl(
|
|
255
|
+
const playNextFeedUrl: string = await retrieveFeedUrl(
|
|
256
|
+
this.entry,
|
|
257
|
+
plugins
|
|
258
|
+
);
|
|
169
259
|
|
|
170
260
|
if (!playNextFeedUrl || typeof playNextFeedUrl !== "string") {
|
|
171
261
|
log_debug(
|
|
@@ -270,7 +360,7 @@ export class OverlaysObserver {
|
|
|
270
360
|
|
|
271
361
|
// TODO: Hack for video end, will be replaced with playlist prev/next in the future
|
|
272
362
|
getPlayNextEntry = () =>
|
|
273
|
-
!this.
|
|
363
|
+
!this.isPlayNextSuppressed ? this.playNextConfig?.entry : null;
|
|
274
364
|
|
|
275
365
|
prepareChapterMarkers = () => {
|
|
276
366
|
const chapterMarkers: ChapterMarkerOriginal[] =
|
|
@@ -353,7 +443,7 @@ export class OverlaysObserver {
|
|
|
353
443
|
const shouldPlayNextBeVisible = currentTime > triggerTime;
|
|
354
444
|
|
|
355
445
|
if (shouldPlayNextBeVisible) {
|
|
356
|
-
if (this.
|
|
446
|
+
if (this.isPlayNextSuppressed) {
|
|
357
447
|
return;
|
|
358
448
|
}
|
|
359
449
|
|
|
@@ -361,10 +451,11 @@ export class OverlaysObserver {
|
|
|
361
451
|
...this.playNextConfig,
|
|
362
452
|
triggerTime,
|
|
363
453
|
handleUserCancelPlayNext: this.handleUserCancelPlayNext,
|
|
454
|
+
hidePlayNext: this.hidePlayNext,
|
|
364
455
|
});
|
|
365
456
|
} else {
|
|
366
457
|
this.playNextSubject.next(null);
|
|
367
|
-
this.
|
|
458
|
+
this.isPlayNextSuppressed = false;
|
|
368
459
|
}
|
|
369
460
|
};
|
|
370
461
|
|
|
@@ -389,9 +480,8 @@ export class OverlaysObserver {
|
|
|
389
480
|
this.chapterSubject.complete();
|
|
390
481
|
this.playNextSubject.complete();
|
|
391
482
|
this.liveMetadataSubject.complete();
|
|
392
|
-
this.titleSummarySubject.complete();
|
|
393
483
|
this.releasePlayerObserver?.();
|
|
394
|
-
this.
|
|
484
|
+
this.stopLiveContentUpdates();
|
|
395
485
|
this.clearLiveMetadataUpdateInterval();
|
|
396
486
|
this.releasePlayerObserver = null;
|
|
397
487
|
};
|