@applicaster/zapp-react-native-utils 16.0.0-rc.2 → 16.0.0-rc.20

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.
Files changed (34) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +4 -3
  2. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  3. package/analyticsUtils/PlayerAnalyticsManager.ts +11 -1
  4. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  5. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  6. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  7. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  8. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  9. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  10. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  11. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  12. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  13. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  14. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  15. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  16. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  17. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  18. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  19. package/analyticsUtils/analyticsMapper.ts +4 -1
  20. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  21. package/appUtils/HooksManager/index.ts +6 -17
  22. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  23. package/appUtils/platform/platformUtils.ts +11 -0
  24. package/appUtils/playerManager/__tests__/playerFactory.test.ts +150 -0
  25. package/appUtils/playerManager/playerFactory.ts +17 -34
  26. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  27. package/package.json +2 -2
  28. package/playerUtils/index.ts +24 -2
  29. package/reactHooks/cell-click/index.ts +15 -7
  30. package/reactHooks/screen/__tests__/useIsStandaloneFullscreen.test.ts +114 -0
  31. package/reactHooks/screen/index.ts +2 -0
  32. package/reactHooks/screen/useIsStandaloneFullscreen.ts +12 -0
  33. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  34. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +1 -1
@@ -44,7 +44,7 @@ export const { log_error, log_info, log_debug } = createLogger({
44
44
  category: "General",
45
45
  });
46
46
 
47
- type ActionExecutorContextType = {
47
+ export type ActionExecutorContextType = {
48
48
  registerAction: (
49
49
  type: string,
50
50
  handler: (
@@ -66,6 +66,7 @@ type ActionExecutorContextType = {
66
66
  context?: Record<string, any>
67
67
  ) => Promise<ActionResult>;
68
68
  };
69
+
69
70
  type Props = {
70
71
  children: React.ReactNode;
71
72
  };
@@ -129,7 +130,7 @@ const prepareDefaultActions = (actionExecutor) => {
129
130
  getInflatedDataSourceUrl({
130
131
  source,
131
132
  contexts: {
132
- entry: context?.entryContext,
133
+ entry: context?.screenEntry,
133
134
  screen: context?.screenData,
134
135
  search: getSearchContext(null, mapping),
135
136
  },
@@ -198,7 +199,7 @@ const prepareDefaultActions = (actionExecutor) => {
198
199
 
199
200
  const entry = context?.entry || {};
200
201
  const entryResolver = new EntryResolver(entry);
201
- const screenData = context?.screenStateStore.getState().data || {};
202
+ const screenData = context?.screenStateStore?.getState().data || {};
202
203
  const screenResolver = new EntryResolver(screenData || {});
203
204
 
204
205
  const data =
@@ -6,9 +6,9 @@ import { postAnalyticEvent } from "../manager";
6
6
  import { ANALYTICS_CORE_EVENTS } from "../events";
7
7
 
8
8
  type AnalyticsDefaultHelperProperties = {
9
- analyticsScreenData: AnalyticsScreenProperties;
9
+ analyticsScreenData?: AnalyticsScreenProperties;
10
10
  extraProps: any;
11
- props;
11
+ props?: any;
12
12
  };
13
13
 
14
14
  export const sendMenuClickEvent = ({
@@ -23,6 +23,15 @@ class PlayerAnalyticsTrackerFactory {
23
23
  return new PlayerAnalyticsTracker();
24
24
  }
25
25
  }
26
+
27
+ onPlayerRegistered(tracker: PlayerAnalyticsTrackerI, player: Player) {
28
+ tracker.setPlayer(player);
29
+ tracker.onPlayerPresented();
30
+ }
31
+
32
+ onPlayerUnRegistered(tracker?: PlayerAnalyticsTrackerI) {
33
+ tracker?.onPlayerClosed();
34
+ }
26
35
  }
27
36
 
28
37
  export class PlayerAnalyticsManager implements PlayerLifecycleListener {
@@ -70,7 +79,7 @@ export class PlayerAnalyticsManager implements PlayerLifecycleListener {
70
79
  }
71
80
 
72
81
  const tracker = this.getTracker(player.playerId);
73
- tracker.setPlayer(player);
82
+ this.trackerFactory.onPlayerRegistered(tracker, player);
74
83
 
75
84
  const analyticsListener = new AnalyticPlayerListener({
76
85
  analyticsTracker: tracker,
@@ -84,6 +93,7 @@ export class PlayerAnalyticsManager implements PlayerLifecycleListener {
84
93
  };
85
94
 
86
95
  onUnRegistered = (player: Player) => {
96
+ this.trackerFactory.onPlayerUnRegistered(this.trackers[player.playerId]);
87
97
  player.removeListener(AnalyticPlayerListener.analyticsListenerID);
88
98
  delete this.trackers[player.playerId];
89
99
  };
@@ -74,4 +74,39 @@ describe("Analytics Mapper", () => {
74
74
  const rules = fixtures.ACPEventRules;
75
75
  await setConfigRunMapTest(rules, fixtures.ACPEventEvents);
76
76
  });
77
+
78
+ it("Does not let an ignore rule short-circuit later events", async () => {
79
+ await setConfigRunMapTest(
80
+ fixtures.ignoreOrderingRules,
81
+ fixtures.ignoreOrderingEvents
82
+ );
83
+ });
84
+
85
+ it("Keeps the original name when rename is empty", async () => {
86
+ await setConfigRunMapTest(
87
+ fixtures.emptyRenameRules,
88
+ fixtures.emptyRenameEvents
89
+ );
90
+ });
91
+
92
+ it("Renames via a regex with no named groups", async () => {
93
+ await setConfigRunMapTest(
94
+ fixtures.regexNonNamedFullMatchRules,
95
+ fixtures.regexNonNamedFullMatchEvents
96
+ );
97
+ });
98
+
99
+ it("Substitutes every named group in a regex rename", async () => {
100
+ await setConfigRunMapTest(
101
+ fixtures.regexMultiGroupRenameRules,
102
+ fixtures.regexMultiGroupRenameEvents
103
+ );
104
+ });
105
+
106
+ it("Does not fall back to event match when a regex rule does not match", async () => {
107
+ await setConfigRunMapTest(
108
+ fixtures.regexEventNoFallbackRules,
109
+ fixtures.regexEventNoFallbackEvents
110
+ );
111
+ });
77
112
  });
@@ -23,7 +23,7 @@
23
23
  "second": {
24
24
  "name": "EventName",
25
25
  "params": {
26
- "acp": 1
26
+ "acp": "1"
27
27
  }
28
28
  }
29
29
  }
@@ -12,4 +12,4 @@
12
12
  }
13
13
  ],
14
14
  "strategy": "allowUnlisted"
15
- }
15
+ }
@@ -0,0 +1,4 @@
1
+ [
2
+ { "first": { "name": "keep_me", "params": {} },
3
+ "second": { "name": "keep_me", "params": {} } }
4
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": [
3
+ { "event": "keep_me", "ignore": false, "rename": "", "strategy": "allowUnlisted" }
4
+ ],
5
+ "strategy": "allowUnlisted"
6
+ }
@@ -2,17 +2,11 @@
2
2
  {
3
3
  "first": {
4
4
  "name": "Screen viewed: Ads & redirects",
5
- "params": {
6
- "ignored_param": "removed_value",
7
- "kept_param": "kept_value"
8
- }
5
+ "params": {}
9
6
  },
10
7
  "second": {
11
8
  "name": "Screen Ads & redirects",
12
- "params": {
13
- "ignored_param": "removed_value",
14
- "kept_param": "kept_value"
15
- }
9
+ "params": {}
16
10
  }
17
11
  }
18
- ]
12
+ ]
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "first": {
4
+ "name": "screen_view",
5
+ "params": {}
6
+ },
7
+ "second": {
8
+ "name": "page_view",
9
+ "params": {}
10
+ }
11
+ },
12
+ {
13
+ "first": {
14
+ "name": "player_presented",
15
+ "params": {}
16
+ }
17
+ }
18
+ ]
@@ -0,0 +1,16 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "event": "player_presented",
5
+ "ignore": true,
6
+ "strategy": "allowUnlisted"
7
+ },
8
+ {
9
+ "event": "screen_view",
10
+ "ignore": false,
11
+ "rename": "page_view",
12
+ "strategy": "allowUnlisted"
13
+ }
14
+ ],
15
+ "strategy": "allowUnlisted"
16
+ }
@@ -0,0 +1,4 @@
1
+ [
2
+ { "first": { "name": "my_event", "params": {} },
3
+ "second": { "name": "my_event", "params": {} } }
4
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": [
3
+ { "event": "my_event", "ignore": false, "rename": "should_not_apply", "regex": "wont_match_.*", "strategy": "allowUnlisted" }
4
+ ],
5
+ "strategy": "allowUnlisted"
6
+ }
@@ -0,0 +1,4 @@
1
+ [
2
+ { "first": { "name": "play-video", "params": {} },
3
+ "second": { "name": "play_video", "params": {} } }
4
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": [
3
+ { "ignore": false, "rename": "$<first>_$<second>", "regex": "(?<first>[a-z]+)-(?<second>[a-z]+)", "strategy": "allowUnlisted" }
4
+ ],
5
+ "strategy": "allowUnlisted"
6
+ }
@@ -0,0 +1,4 @@
1
+ [
2
+ { "first": { "name": "screen_view", "params": {} },
3
+ "second": { "name": "renamed", "params": {} } }
4
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": [
3
+ { "ignore": false, "rename": "renamed", "regex": "screen_view", "strategy": "allowUnlisted" }
4
+ ],
5
+ "strategy": "allowUnlisted"
6
+ }
@@ -14,6 +14,16 @@ import blockUnlistedEventEvents from "./analytics_mapper_testBlockUnlistedEvents
14
14
  import blockUnlistedEventRules from "./analytics_mapper_testBlockUnlistedEvents_rules.json";
15
15
  import ACPEventEvents from "./analytics_mapper_testACP_events.json";
16
16
  import ACPEventRules from "./analytics_mapper_testACP_rules.json";
17
+ import emptyRenameRules from "./analytics_mapper_testEmptyRenameKeepsName_rules.json";
18
+ import emptyRenameEvents from "./analytics_mapper_testEmptyRenameKeepsName_events.json";
19
+ import ignoreOrderingRules from "./analytics_mapper_testIgnoreOrdering_rules.json";
20
+ import ignoreOrderingEvents from "./analytics_mapper_testIgnoreOrdering_events.json";
21
+ import regexEventNoFallbackRules from "./analytics_mapper_testRegexEventNoFallback_rules.json";
22
+ import regexEventNoFallbackEvents from "./analytics_mapper_testRegexEventNoFallback_events.json";
23
+ import regexMultiGroupRenameRules from "./analytics_mapper_testRegexMultiGroupRename_rules.json";
24
+ import regexMultiGroupRenameEvents from "./analytics_mapper_testRegexMultiGroupRename_events.json";
25
+ import regexNonNamedFullMatchRules from "./analytics_mapper_testRegexNonNamedFullMatch_rules.json";
26
+ import regexNonNamedFullMatchEvents from "./analytics_mapper_testRegexNonNamedFullMatch_events.json";
17
27
 
18
28
  export const fixtures = {
19
29
  renameRules,
@@ -32,4 +42,14 @@ export const fixtures = {
32
42
  blockUnlistedEventRules,
33
43
  ACPEventEvents,
34
44
  ACPEventRules,
45
+ emptyRenameRules,
46
+ emptyRenameEvents,
47
+ ignoreOrderingRules,
48
+ ignoreOrderingEvents,
49
+ regexEventNoFallbackRules,
50
+ regexEventNoFallbackEvents,
51
+ regexMultiGroupRenameRules,
52
+ regexMultiGroupRenameEvents,
53
+ regexNonNamedFullMatchRules,
54
+ regexNonNamedFullMatchEvents,
35
55
  };
@@ -76,7 +76,10 @@ class StateHolder {
76
76
  delete this.pluckedParams[prefix];
77
77
  }
78
78
 
79
- return this._cap?.[suffix];
79
+ // Stringify so values match the native iOS/Android mappers (which coerce
80
+ // analyticsCustomProperties values to strings) — keeps GA4 data consistent
81
+ // across web/LG/Samsung and native platforms.
82
+ return this._cap?.[suffix]?.toString() ?? null;
80
83
  }
81
84
 
82
85
  private async getFromLocalAndSession(
@@ -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 { AD_EVENT, EVENT_TYPES, PLAYER_DISPLAY_STATES } from "./events";
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 streamType = isLive(this.entry) ? "live" : "vod"; // Todo: determine other types, channel, podcast, aod
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
- duration: mediaDuration,
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,
@@ -1,14 +1,11 @@
1
1
  import * as R from "ramda";
2
2
 
3
3
  import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
4
- import {
5
- QUICK_BRICK_EVENTS,
6
- sendQuickBrickEvent,
7
- } from "@applicaster/zapp-react-native-bridge/QuickBrick";
8
-
9
4
  import { Hook } from "./Hook";
10
5
  import { HOOKS_EVENTS, HOOKS_TYPE } from "./constants";
11
6
 
7
+ import { platformToBackground } from "../platform";
8
+
12
9
  import { hooksManagerLogger } from "./logger";
13
10
  import { HookManager, HookManagerArgs } from "./types";
14
11
  import {
@@ -90,7 +87,7 @@ export function HooksManager({
90
87
  }: HookManagerArgs): HookManager {
91
88
  hooksManagerLogger.addContext({ targetScreenId: targetScreen.id });
92
89
 
93
- function logHookEvent(func, message, data) {
90
+ function logHookEvent(func, message, data = {}) {
94
91
  func({
95
92
  message,
96
93
  data: __DEV__ ? data : null,
@@ -347,14 +344,10 @@ export function HooksManager({
347
344
  `hookCallback: send app to background, cancelled flow blocker hook ${hookPlugin.identifier} on home screen`,
348
345
  {
349
346
  payload,
350
- hook: hookPlugin,
351
347
  }
352
348
  );
353
349
 
354
- // TODO: Add this logic to platformBack and rename platformBack to platformToBackground for all platforms
355
- sendQuickBrickEvent(QUICK_BRICK_EVENTS.MOVE_APP_TO_BACKGROUND, {
356
- MOVE_APP_TO_BACKGROUND: true,
357
- });
350
+ platformToBackground();
358
351
  }
359
352
  } else {
360
353
  logHookEvent(
@@ -362,17 +355,13 @@ export function HooksManager({
362
355
  `hookCallback: hook successfully finished: ${hookPlugin.identifier}`,
363
356
  {
364
357
  payload,
365
- hook: hookPlugin,
366
358
  }
367
359
  );
368
360
 
369
361
  if (!callback) {
370
362
  logHookEvent(
371
- hooksManagerLogger.warn,
372
- `hookCallback: ${hookPlugin.identifier} is missing \`callback\`, using hookCallback(default one)`,
373
- {
374
- hookPlugin,
375
- }
363
+ hooksManagerLogger.debug,
364
+ `hookCallback: ${hookPlugin.identifier} is missing \`callback\`, using hookCallback(default one)`
376
365
  );
377
366
 
378
367
  callback = hookCallback;
@@ -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
- const namespacedKeyProps = namespacedKey.includes(".")
12
- ? splitByLastDot(namespacedKey)
13
- : [DEFAULT_NAMESPACE, namespacedKey];
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 R.zipObj(["namespace", "key"], namespacedKeyProps);
14
+ return {
15
+ namespace: namespacedKey.slice(0, lastDotIndex),
16
+ key: namespacedKey.slice(lastDotIndex + 1),
17
+ };
16
18
  }
17
19
 
18
- const propIsNotNullOrUndefined = (prop) =>
19
- R.compose(R.not, R.isNil, R.prop(prop));
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 propIsNotEmpty = (prop) => R.compose(R.not, R.isEmpty, R.prop(prop));
40
+ const obj = parsedKey as Record<string, unknown>;
22
41
 
23
- export const keyIsValid = R.allPass([
24
- R.compose(R.not, R.isNil),
25
- R.compose(R.not, R.is(String)),
26
- R.compose(R.not, R.is(Array)),
27
- R.has("key"),
28
- R.has("namespace"),
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
- return R.is(Boolean, result) && !!result;
40
- };
52
+ export const savingResultIsSuccess = (result: unknown): boolean =>
53
+ typeof result === "boolean" && result === true;
@@ -1,6 +1,11 @@
1
1
  import { BehaviorSubject } from "rxjs";
2
2
 
3
3
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
4
+ import {
5
+ QUICK_BRICK_EVENTS,
6
+ sendQuickBrickEvent,
7
+ } from "@applicaster/zapp-react-native-bridge/QuickBrick";
8
+
4
9
  import {
5
10
  isLgPlatform,
6
11
  isSamsungPlatform,
@@ -18,6 +23,12 @@ const { log_debug } = createLogger({
18
23
  parent: utilsLogger,
19
24
  });
20
25
 
26
+ export const platformToBackground = () => {
27
+ sendQuickBrickEvent(QUICK_BRICK_EVENTS.MOVE_APP_TO_BACKGROUND, {
28
+ MOVE_APP_TO_BACKGROUND: true,
29
+ });
30
+ };
31
+
21
32
  export const getZappPlatform = (): ZappPlatform => {
22
33
  const platform = appStore.get("appData")?.platform;
23
34
 
@@ -0,0 +1,150 @@
1
+ const mockAppStoreGet = jest.fn();
2
+ const mockFindPluginByIdentifier = jest.fn();
3
+
4
+ jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
5
+ appStore: { get: (key: string) => mockAppStoreGet(key) },
6
+ }));
7
+
8
+ jest.mock("@applicaster/zapp-react-native-utils/pluginUtils", () => ({
9
+ findPluginByIdentifier: (id: string, plugins: any) =>
10
+ mockFindPluginByIdentifier(id, plugins),
11
+ }));
12
+
13
+ import { PlayerRole } from "../conts";
14
+ import { playerFactory } from "../playerFactory";
15
+
16
+ const fakeComponent = () => null;
17
+
18
+ class FakeController {
19
+ receivedConfig: any;
20
+ constructor(config: any) {
21
+ this.receivedConfig = config;
22
+ }
23
+ }
24
+
25
+ const baseConfig = {
26
+ player: {},
27
+ playerId: "p1",
28
+ autoplay: false,
29
+ entry: { id: "entry-1" } as any,
30
+ muted: false,
31
+ playerPluginId: "test-plugin",
32
+ screenConfig: { foo: "bar" },
33
+ playerRole: PlayerRole.Cell,
34
+ };
35
+
36
+ const installPluginWithProtocol = (
37
+ protocolReturn: any | ((screenConfig: any, entry: any) => any)
38
+ ) => {
39
+ const playerProtocol =
40
+ typeof protocolReturn === "function"
41
+ ? protocolReturn
42
+ : () => protocolReturn;
43
+
44
+ mockAppStoreGet.mockImplementation((key: string) =>
45
+ key === "plugins" ? { "test-plugin": {} } : null
46
+ );
47
+
48
+ mockFindPluginByIdentifier.mockReturnValue({
49
+ module: { playerProtocol },
50
+ });
51
+ };
52
+
53
+ describe("playerFactory", () => {
54
+ beforeEach(() => {
55
+ mockAppStoreGet.mockReset();
56
+ mockFindPluginByIdentifier.mockReset();
57
+ });
58
+
59
+ it("resolves with controller and Component when playerProtocol returns synchronously", async () => {
60
+ installPluginWithProtocol({
61
+ Component: fakeComponent,
62
+ controllerClass: FakeController,
63
+ });
64
+
65
+ const item = await playerFactory(baseConfig);
66
+
67
+ expect(item).not.toBeNull();
68
+ expect(item?.Component).toBe(fakeComponent);
69
+ expect(item?.controller).toBeInstanceOf(FakeController);
70
+
71
+ expect((item?.controller as FakeController).receivedConfig).toBe(
72
+ baseConfig
73
+ );
74
+ });
75
+
76
+ it("resolves with controller and Component when playerProtocol returns a Promise (delayed import)", async () => {
77
+ installPluginWithProtocol(async () => ({
78
+ Component: fakeComponent,
79
+ controllerClass: FakeController,
80
+ }));
81
+
82
+ const item = await playerFactory(baseConfig);
83
+
84
+ expect(item).not.toBeNull();
85
+ expect(item?.Component).toBe(fakeComponent);
86
+ expect(item?.controller).toBeInstanceOf(FakeController);
87
+ });
88
+
89
+ it("passes screenConfig and entry through to playerProtocol", async () => {
90
+ const playerProtocol = jest.fn(() => ({
91
+ Component: fakeComponent,
92
+ controllerClass: FakeController,
93
+ }));
94
+
95
+ mockAppStoreGet.mockImplementation((key: string) =>
96
+ key === "plugins" ? { "test-plugin": {} } : null
97
+ );
98
+
99
+ mockFindPluginByIdentifier.mockReturnValue({ module: { playerProtocol } });
100
+
101
+ await playerFactory(baseConfig);
102
+
103
+ expect(playerProtocol).toHaveBeenCalledWith(
104
+ baseConfig.screenConfig,
105
+ baseConfig.entry
106
+ );
107
+ });
108
+
109
+ it("resolves to null when playerPluginId is missing", async () => {
110
+ expect(
111
+ await playerFactory({ ...baseConfig, playerPluginId: "" } as any)
112
+ ).toBeNull();
113
+ });
114
+
115
+ it("resolves to null when appStore has no plugins", async () => {
116
+ mockAppStoreGet.mockReturnValue(null);
117
+
118
+ expect(await playerFactory(baseConfig)).toBeNull();
119
+ });
120
+
121
+ it("resolves to null when the plugin has no playerProtocol", async () => {
122
+ mockAppStoreGet.mockImplementation((key: string) =>
123
+ key === "plugins" ? { "test-plugin": {} } : null
124
+ );
125
+
126
+ mockFindPluginByIdentifier.mockReturnValue({ module: {} });
127
+
128
+ expect(await playerFactory(baseConfig)).toBeNull();
129
+ });
130
+
131
+ it("resolves to null when playerProtocol returns without a Component", async () => {
132
+ installPluginWithProtocol({ controllerClass: FakeController });
133
+
134
+ expect(await playerFactory(baseConfig)).toBeNull();
135
+ });
136
+
137
+ it("resolves to null when playerProtocol returns without a controllerClass", async () => {
138
+ installPluginWithProtocol({ Component: fakeComponent });
139
+
140
+ expect(await playerFactory(baseConfig)).toBeNull();
141
+ });
142
+
143
+ it("rejects when playerProtocol throws synchronously", async () => {
144
+ installPluginWithProtocol(() => {
145
+ throw new Error("boom");
146
+ });
147
+
148
+ await expect(playerFactory(baseConfig)).rejects.toThrow("boom");
149
+ });
150
+ });
@@ -19,52 +19,35 @@ type PlayerFactoryProps = {
19
19
  playerRole: PlayerRole;
20
20
  };
21
21
 
22
- interface PlayerConstructor {
22
+ interface PlayerControllerConstructor {
23
23
  new (params: any): Player;
24
24
  }
25
25
 
26
- export const playerFactory = (
27
- config: PlayerFactoryProps
28
- ): PlayerFactoryItem | null => {
29
- const IDENTIFIER = config?.playerPluginId;
26
+ type PlayerProtocol = {
27
+ Component: any;
28
+ controllerClass: PlayerControllerConstructor;
29
+ };
30
30
 
31
- if (!IDENTIFIER) {
32
- return null;
33
- }
31
+ export const playerFactory = async (
32
+ config: PlayerFactoryProps
33
+ ): Promise<PlayerFactoryItem | null> => {
34
+ if (!config?.playerPluginId) return null;
34
35
 
35
36
  const plugins = appStore.get("plugins");
37
+ if (!plugins) return null;
36
38
 
37
- if (!plugins) {
38
- return null;
39
- }
40
-
41
- const playerPlugin = findPluginByIdentifier(IDENTIFIER, plugins);
39
+ const playerPlugin = findPluginByIdentifier(config.playerPluginId, plugins);
40
+ if (!playerPlugin?.module?.playerProtocol) return null;
42
41
 
43
- if (!playerPlugin?.module?.playerProtocol) {
44
- return null;
45
- }
46
-
47
- const playerProtocol: PlayerConstructor = playerPlugin.module.playerProtocol(
48
- config?.screenConfig,
49
- config?.entry
50
- );
42
+ const playerProtocol: PlayerProtocol | null =
43
+ await playerPlugin.module.playerProtocol(config.screenConfig, config.entry);
51
44
 
52
- const playerView = (playerProtocol as any)?.Component || null;
53
-
54
- if (!playerView) {
45
+ if (!playerProtocol?.Component || !playerProtocol.controllerClass) {
55
46
  return null;
56
47
  }
57
48
 
58
- const Controller = (playerProtocol as any)?.controllerClass || null;
59
-
60
- if (Controller === null) {
61
- return null;
62
- }
63
-
64
- const controller = new Controller(config);
65
-
66
49
  return {
67
- controller,
68
- Component: playerView,
50
+ controller: new playerProtocol.controllerClass(config),
51
+ Component: playerProtocol.Component,
69
52
  };
70
53
  };
@@ -308,6 +308,41 @@ const generalContent = () => ({
308
308
  key: "pull_to_refresh_enabled",
309
309
  initial_value: false,
310
310
  },
311
+ {
312
+ type: "switch",
313
+ label: "Allow using this screen as a hook",
314
+ label_tooltip:
315
+ "Make sure that screen uses 'finishHook' action or performs navigation action to exit the screen after performing the hook action, or user will be stuck on the screen", // eslint-disable-line max-len
316
+ key: "available_as_hook",
317
+ initial_value: false,
318
+ },
319
+ {
320
+ type: "data_source_selector",
321
+ label: "Skip hook endpoint",
322
+ key: "skip_hook_endpoint",
323
+ label_tooltip:
324
+ "If set, this endpoint will check with the server whether the hook should be skipped",
325
+ conditional_fields: [
326
+ {
327
+ key: "rules/available_as_hook",
328
+ condition_value: true,
329
+ },
330
+ ],
331
+ },
332
+ {
333
+ key: "skip_hook_storage_key",
334
+ type: "text_input",
335
+ label: "Hook will be skipped if storage key is set",
336
+ initial_value: "",
337
+ label_tooltip:
338
+ "Comma-separated keys in namespace.key format (key without a dot uses the default namespace)", // eslint-disable-line max-len
339
+ conditional_fields: [
340
+ {
341
+ key: "rules/available_as_hook",
342
+ condition_value: true,
343
+ },
344
+ ],
345
+ },
311
346
  ],
312
347
  },
313
348
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.2",
3
+ "version": "16.0.0-rc.20",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-rc.2",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.20",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -9,6 +9,16 @@ import { Dimensions } from "react-native";
9
9
 
10
10
  export { getPlayerActionButtons } from "./getPlayerActionButtons";
11
11
 
12
+ export const HLS_MIME_TYPES = [
13
+ "application/x-mpegURL",
14
+ "application/vnd.apple.mpegurl",
15
+ ];
16
+
17
+ export const STREAMING_VIDEO_MIME_TYPES = [
18
+ ...HLS_MIME_TYPES,
19
+ "application/dash+xml",
20
+ ];
21
+
12
22
  /**
13
23
  * Gets duration value from player manager, and from extensions
14
24
  * then checks whether the value from either is a not a valid number
@@ -27,7 +37,7 @@ export function isLiveLegacy(content) {
27
37
  ]);
28
38
 
29
39
  const durationFromExt = R.path(["extensions", "duration"], content);
30
- const durationFromMgr = playerManager.getDuration();
40
+ const durationFromMgr = playerManager.getInstanceController()?.getDuration();
31
41
  const duration = Math.floor(durationFromExt || durationFromMgr);
32
42
 
33
43
  const isLive = R.anyPass([isNotaValidNumber, R.lte(R.__, 0)])(duration);
@@ -71,7 +81,9 @@ function isLiveByManager(): boolean {
71
81
  return true;
72
82
  }
73
83
 
74
- const durationFromPlayerManager = playerManager.getDuration();
84
+ const durationFromPlayerManager = playerManager
85
+ .getInstanceController()
86
+ ?.getDuration();
75
87
 
76
88
  return isLiveByDuration(durationFromPlayerManager);
77
89
  }
@@ -80,6 +92,16 @@ export function isLive(entry: ZappEntry): boolean {
80
92
  return isEntryLive(entry) || isLiveByManager();
81
93
  }
82
94
 
95
+ export const isVideoItem = (item: Option<ZappEntry>) => {
96
+ const contentType = item?.content?.type;
97
+
98
+ return (
99
+ isString(contentType) &&
100
+ (contentType.includes("video") ||
101
+ STREAMING_VIDEO_MIME_TYPES.includes(contentType))
102
+ );
103
+ };
104
+
83
105
  export const isAudioItem = (item: Option<ZappEntry>) => {
84
106
  if (
85
107
  isString(item?.content?.type) &&
@@ -49,12 +49,13 @@ export const useCellClick = ({
49
49
  const actionExecutor = React.useContext(ActionExecutorContext);
50
50
  const screenData = useCurrentScreenData();
51
51
  const screenState = useScreenContext()?.options;
52
+ const entry = useScreenContext()?.entry;
52
53
 
53
54
  const cellSelectable = toBooleanWithDefaultTrue(
54
55
  component?.rules?.component_cells_selectable
55
56
  );
56
57
 
57
- const [entryContext, setEntryContext] =
58
+ const [_entryContext, setEntryContext] =
58
59
  ZappPipesEntryContext.useZappPipesContext(pathname);
59
60
 
60
61
  const logTimestamp = useProfilerLogging();
@@ -89,7 +90,8 @@ export const useCellClick = ({
89
90
  screenState,
90
91
  screenRoute: pathname,
91
92
  screenStateStore,
92
- entryContext,
93
+ entryContext: selectedItem,
94
+ screenEntry: entry,
93
95
  });
94
96
  }
95
97
 
@@ -117,14 +119,20 @@ export const useCellClick = ({
117
119
  }
118
120
  },
119
121
  [
120
- onCellTap,
121
- currentRoute,
122
+ item,
122
123
  setEntryContext,
123
- pathname,
124
- push,
125
124
  sendAnalyticsOnPress,
125
+ logTimestamp,
126
+ pathname,
127
+ component,
128
+ onCellTap,
129
+ entry,
130
+ actionExecutor,
126
131
  screenData,
127
132
  screenState,
133
+ screenStateStore,
134
+ currentRoute,
135
+ push,
128
136
  ]
129
137
  );
130
138
 
@@ -138,5 +146,5 @@ export const useCellClick = ({
138
146
  onPressRef.current = onPress;
139
147
  }
140
148
 
141
- return React.useCallback(onPressRef.current, []);
149
+ return React.useCallback(onPressRef.current, [item]);
142
150
  };
@@ -0,0 +1,114 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useIsStandaloneFullscreen } from "../useIsStandaloneFullscreen";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
6
+
7
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
8
+ jest.mock("@applicaster/zapp-react-native-utils/booleanUtils");
9
+
10
+ const mockUseNavigation = useNavigation as jest.Mock;
11
+ const mockToBoolean = toBooleanWithDefaultFalse as jest.Mock;
12
+
13
+ describe("useIsStandaloneFullscreen", () => {
14
+ beforeEach(() => {
15
+ jest.clearAllMocks();
16
+
17
+ mockUseNavigation.mockReturnValue({
18
+ canGoBack: jest.fn().mockReturnValue(false),
19
+ screenData: {
20
+ general: { allow_screen_plugin_presentation: true },
21
+ },
22
+ });
23
+
24
+ mockToBoolean.mockReturnValue(false);
25
+ });
26
+
27
+ it("returns true when cannot go back and screen plugin presentation is allowed", () => {
28
+ mockToBoolean.mockReturnValue(true);
29
+
30
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
31
+
32
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
33
+ expect(result.current).toBe(true);
34
+ });
35
+
36
+ it("returns false when can go back even if screen plugin presentation is allowed", () => {
37
+ mockUseNavigation.mockReturnValue({
38
+ canGoBack: jest.fn().mockReturnValue(true),
39
+ screenData: {
40
+ general: { allow_screen_plugin_presentation: true },
41
+ },
42
+ });
43
+
44
+ mockToBoolean.mockReturnValue(false);
45
+
46
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
47
+
48
+ expect(mockToBoolean).toHaveBeenCalledWith(false);
49
+ expect(result.current).toBe(false);
50
+ });
51
+
52
+ it("returns false when cannot go back but screen plugin presentation is not allowed", () => {
53
+ mockUseNavigation.mockReturnValue({
54
+ canGoBack: jest.fn().mockReturnValue(false),
55
+ screenData: {
56
+ general: { allow_screen_plugin_presentation: false },
57
+ },
58
+ });
59
+
60
+ mockToBoolean.mockReturnValue(false);
61
+
62
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
63
+
64
+ expect(mockToBoolean).toHaveBeenCalledWith(false);
65
+ expect(result.current).toBe(false);
66
+ });
67
+
68
+ it("returns false when screen plugin presentation flag is undefined", () => {
69
+ mockUseNavigation.mockReturnValue({
70
+ canGoBack: jest.fn().mockReturnValue(false),
71
+ screenData: { general: {} },
72
+ });
73
+
74
+ mockToBoolean.mockReturnValue(false);
75
+
76
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
77
+
78
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
79
+ expect(result.current).toBe(false);
80
+ });
81
+
82
+ it("returns false when navigator is undefined", () => {
83
+ mockUseNavigation.mockReturnValue(undefined);
84
+ mockToBoolean.mockReturnValue(false);
85
+
86
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
87
+
88
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
89
+ expect(result.current).toBe(false);
90
+ });
91
+
92
+ it("returns false when screenData is undefined", () => {
93
+ mockUseNavigation.mockReturnValue({
94
+ canGoBack: jest.fn().mockReturnValue(false),
95
+ screenData: undefined,
96
+ });
97
+
98
+ mockToBoolean.mockReturnValue(false);
99
+
100
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
101
+
102
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
103
+ expect(result.current).toBe(false);
104
+ });
105
+
106
+ it("passes the combined condition through toBooleanWithDefaultFalse", () => {
107
+ mockToBoolean.mockImplementation((val) => Boolean(val));
108
+
109
+ const { result } = renderHook(() => useIsStandaloneFullscreen());
110
+
111
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
112
+ expect(result.current).toBe(true);
113
+ });
114
+ });
@@ -16,3 +16,5 @@ export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
16
16
  export { useCurrentScreenIsHook } from "./useCurrentScreenIsHook";
17
17
 
18
18
  export { useCurrentScreenIsStartupHook } from "./useCurrentScreenIsStartupHook";
19
+
20
+ export { useIsStandaloneFullscreen } from "./useIsStandaloneFullscreen";
@@ -0,0 +1,12 @@
1
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
2
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
+
4
+ export const useIsStandaloneFullscreen = (): boolean => {
5
+ const navigator = useNavigation();
6
+
7
+ return toBooleanWithDefaultFalse(
8
+ !navigator?.canGoBack() &&
9
+ // @ts-ignore
10
+ navigator?.screenData?.general?.allow_screen_plugin_presentation
11
+ );
12
+ };
@@ -2,6 +2,12 @@ import React from "react";
2
2
  import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
3
3
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
4
4
  import { useRivers } from "../../state";
5
+ import { createLogger } from "../../../logger";
6
+
7
+ const { log_warning } = createLogger({
8
+ subsystem: "zapp-react-native-utils/reactHooks/videoModal",
9
+ category: "useVideoModalScreenData",
10
+ });
5
11
 
6
12
  export const useVideoModalScreenData = ():
7
13
  | (ZappEntry & { targetScreen: any }) // TODO: fix ZappEntry type ( was ZappRiver but conflict )
@@ -14,10 +20,22 @@ export const useVideoModalScreenData = ():
14
20
  const rivers = useRivers();
15
21
 
16
22
  return React.useMemo(() => {
17
- if (item?.type?.value) {
18
- const screenId = contentTypes[item?.type?.value].screen_id;
23
+ const itemType = item?.type?.value;
24
+
25
+ if (!itemType) {
26
+ return;
27
+ }
19
28
 
20
- return { ...item, targetScreen: rivers?.[screenId] };
29
+ const screenId = contentTypes[itemType]?.screen_id;
30
+
31
+ if (!screenId) {
32
+ log_warning(
33
+ `Type mapping is missing for item type: ${itemType}, title: ${item.title}`
34
+ );
35
+
36
+ return;
21
37
  }
22
- }, [item]);
38
+
39
+ return { ...item, targetScreen: rivers?.[screenId] };
40
+ }, [contentTypes, item, rivers]);
23
41
  };
@@ -197,7 +197,7 @@ export const useCallbackNavigationAction = (
197
197
  }
198
198
  }
199
199
 
200
- hookCallback?.({ ...args, success: false, cancelled: true });
200
+ hookCallback?.({ ...args, success: false, abort: true });
201
201
  const currentNavigation = navigationRef.current;
202
202
 
203
203
  switch (data.action) {