@applicaster/zapp-react-native-utils 16.0.0-alpha.2434153375 → 16.0.0-alpha.2500443242

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 (97) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +10 -1
  3. package/actionsExecutor/ActionExecutorContext.tsx +29 -1
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +139 -5
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +201 -1
  11. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  12. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  13. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  14. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  15. package/actionsExecutor/actions/goBack.ts +60 -0
  16. package/actionsExecutor/actions/goHome.ts +31 -0
  17. package/actionsExecutor/actions/index.ts +8 -0
  18. package/actionsExecutor/actions/navigateToScreen.ts +29 -45
  19. package/actionsExecutor/actions/openBottomSheet.ts +35 -16
  20. package/actionsExecutor/actions/presentScreen.ts +78 -0
  21. package/actionsExecutor/actions/showAlert.ts +51 -0
  22. package/actionsExecutor/actions/showToast.ts +2 -2
  23. package/actionsExecutor/consts.ts +4 -0
  24. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
  25. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  26. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
  27. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +15 -2
  28. package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
  29. package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
  30. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  31. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  32. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  33. package/appUtils/playerManager/const.ts +13 -0
  34. package/appUtils/playerManager/index.ts +7 -0
  35. package/appUtils/playerManager/player.ts +10 -0
  36. package/appUtils/playerManager/playerNative.ts +22 -0
  37. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  38. package/appUtils/playerManager/playerToolbox.ts +157 -0
  39. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  40. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  41. package/arrayUtils/index.ts +26 -43
  42. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  43. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  44. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  45. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  46. package/cellUtils/index.ts +74 -19
  47. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  48. package/configurationUtils/__tests__/modalBlocksParser.test.ts +286 -1
  49. package/configurationUtils/index.ts +77 -73
  50. package/configurationUtils/manifestKeyParser.ts +12 -1
  51. package/configurationUtils/modalBlocksParser.ts +78 -4
  52. package/entryActions/__tests__/buildEntryActions.test.ts +97 -18
  53. package/entryActions/aliasPresentation.ts +26 -42
  54. package/entryActions/buildEntryActions.ts +1 -0
  55. package/entryActions/index.ts +0 -2
  56. package/focusManager/FocusManager.ts +26 -0
  57. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  58. package/localizationUtils/index.ts +12 -6
  59. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  60. package/logger/xrayToolbox.ts +67 -0
  61. package/manifestUtils/_internals/index.js +8 -3
  62. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  63. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  64. package/manifestUtils/keys.js +6 -1
  65. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  66. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  67. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  68. package/modalState/ModalOrchestrator.ts +22 -9
  69. package/modalState/RemoteEditableCollection.ts +9 -1
  70. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +16 -0
  71. package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
  72. package/modalState/__tests__/index.test.ts +30 -1
  73. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  74. package/modalState/index.ts +6 -1
  75. package/modalState/store.ts +9 -2
  76. package/modalState/types.ts +31 -2
  77. package/modalState/useBottomSheetContent.ts +24 -17
  78. package/navigationUtils/xrayNavigator.ts +12 -0
  79. package/package.json +2 -2
  80. package/perfTracker.ts +206 -0
  81. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  82. package/pluginUtils/index.ts +29 -0
  83. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  84. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  85. package/reactHooks/cell-click/index.ts +21 -14
  86. package/reactHooks/connection/index.tsx +8 -5
  87. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  88. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  89. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  90. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  91. package/reactHooks/navigation/index.ts +2 -0
  92. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  93. package/reactHooks/navigation/useRoute.ts +22 -5
  94. package/reactHooks/usePluginConfiguration.ts +84 -46
  95. package/riverComponetsMeasurementProvider/index.tsx +8 -1
  96. package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
  97. package/uiActionsRegistrator/registry.ts +16 -0
@@ -9,6 +9,9 @@ export const ACTION_TYPES = {
9
9
  PRESENT_SUB_MENU: "presentSubMenu",
10
10
  SEND_CLOUD_EVENT: "sendCloudEvent",
11
11
  NAVIGATE_TO_SCREEN: "navigateToScreen",
12
+ PRESENT_SCREEN: "presentScreen",
13
+ GO_BACK: "goBack",
14
+ GO_HOME: "goHome",
12
15
  SHOW_TOAST: "showToast",
13
16
  LOCAL_STORAGE_SET: "localStorageSet",
14
17
  LOCAL_STORAGE_REMOVE: "localStorageRemove",
@@ -20,6 +23,7 @@ export const ACTION_TYPES = {
20
23
  SWITCH_LAYOUT: "switchLayout",
21
24
  APP_RESTART: "appRestart",
22
25
  CONFIRM_DIALOG: "confirmDialog",
26
+ SHOW_ALERT: "showAlert",
23
27
  SCREEN_SET_VARIABLE: "screenSetVariable",
24
28
  SCREEN_TOGGLE_FLAG: "screenToggleFlag",
25
29
  } as const;
@@ -2,8 +2,7 @@ import { BehaviorSubject, Observable } from "rxjs";
2
2
  import { distinctUntilChanged } from "rxjs/operators";
3
3
  import { Player } from "../player";
4
4
  import { createLogger, utilsLogger } from "../../../logger";
5
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
6
- import { findPluginByIdentifier } from "../../../pluginUtils";
5
+ import { getPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
7
6
  import {
8
7
  loadFeedEntry,
9
8
  loadFeedAndPrefetchThumbnailImage,
@@ -237,11 +236,8 @@ export class OverlaysObserver {
237
236
 
238
237
  preparePlayNext = async () => {
239
238
  try {
240
- const plugins = appStore.get("plugins");
241
-
242
- const playNextPlugin: any = findPluginByIdentifier(
243
- "QuickBrickPlayNextOverlay",
244
- plugins
239
+ const playNextPlugin: any = getPluginByIdentifier(
240
+ "QuickBrickPlayNextOverlay"
245
241
  );
246
242
 
247
243
  if (!playNextPlugin) {
@@ -252,10 +248,7 @@ export class OverlaysObserver {
252
248
  return;
253
249
  }
254
250
 
255
- const playNextFeedUrl: string = await retrieveFeedUrl(
256
- this.entry,
257
- plugins
258
- );
251
+ const playNextFeedUrl: string = await retrieveFeedUrl(this.entry);
259
252
 
260
253
  if (!playNextFeedUrl || typeof playNextFeedUrl !== "string") {
261
254
  log_debug(
@@ -0,0 +1,67 @@
1
+ import { getUpcomingQueue } from "../getUpcomingQueue";
2
+
3
+ describe("getUpcomingQueue", () => {
4
+ it("returns null when plugin is not provided or has no module", async () => {
5
+ expect(await getUpcomingQueue(undefined)).toBeNull();
6
+ expect(await getUpcomingQueue({} as any)).toBeNull();
7
+ });
8
+
9
+ it("returns null when QueueManager is not present on module", async () => {
10
+ const plugin = {
11
+ identifier: "queue-action",
12
+ module: {},
13
+ } as any;
14
+
15
+ expect(await getUpcomingQueue(plugin)).toBeNull();
16
+ });
17
+
18
+ it("calls setupQuickBrickQueue when QueueManager is not initialized", async () => {
19
+ const setupQuickBrickQueue = jest.fn();
20
+ const mockUpcoming = [{ id: "item_1" }];
21
+
22
+ const QueueManager = {
23
+ isInitialized: jest
24
+ .fn()
25
+ .mockReturnValueOnce(false)
26
+ .mockReturnValueOnce(true),
27
+ instance: {
28
+ getUpcomingQueue: jest.fn().mockResolvedValue(mockUpcoming),
29
+ },
30
+ };
31
+
32
+ const plugin = {
33
+ identifier: "queue-action",
34
+ module: {
35
+ QueueManager,
36
+ setupQuickBrickQueue,
37
+ },
38
+ } as any;
39
+
40
+ const result = await getUpcomingQueue(plugin);
41
+
42
+ expect(setupQuickBrickQueue).toHaveBeenCalled();
43
+ expect(result).toEqual(mockUpcoming);
44
+ });
45
+
46
+ it("returns upcoming items when QueueManager is already initialized", async () => {
47
+ const mockUpcoming = [{ id: "item_1" }, { id: "item_2" }];
48
+
49
+ const QueueManager = {
50
+ isInitialized: jest.fn().mockReturnValue(true),
51
+ instance: {
52
+ getUpcomingQueue: jest.fn().mockResolvedValue(mockUpcoming),
53
+ },
54
+ };
55
+
56
+ const plugin = {
57
+ identifier: "queue-action",
58
+ module: {
59
+ QueueManager,
60
+ },
61
+ } as any;
62
+
63
+ const result = await getUpcomingQueue(plugin);
64
+
65
+ expect(result).toEqual(mockUpcoming);
66
+ });
67
+ });
@@ -1,5 +1,12 @@
1
1
  import { retrieveFeedUrl, retrievePlayPreviousFeedUrl } from "../utils";
2
2
 
3
+ // mock for import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
4
+ jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
5
+ appStore: {
6
+ get: jest.fn(() => []),
7
+ },
8
+ }));
9
+
3
10
  const entryWith = (extensions: Record<string, unknown>): ZappEntry =>
4
11
  ({ id: "1", type: { value: "video" }, extensions }) as ZappEntry;
5
12
 
@@ -7,14 +14,14 @@ describe("playlist feed url accessors", () => {
7
14
  it("returns the next feed url when present", async () => {
8
15
  const entry = entryWith({ play_next_feed_url: "https://feeds/next.json" });
9
16
 
10
- await expect(retrieveFeedUrl(entry, [])).resolves.toBe(
17
+ await expect(retrieveFeedUrl(entry)).resolves.toBe(
11
18
  "https://feeds/next.json"
12
19
  );
13
20
  });
14
21
 
15
22
  it("resolves to null for a missing entry", async () => {
16
23
  await expect(
17
- retrieveFeedUrl(undefined as unknown as ZappEntry, [])
24
+ retrieveFeedUrl(undefined as unknown as ZappEntry)
18
25
  ).resolves.toBeNull();
19
26
  });
20
27
 
@@ -1,9 +1,22 @@
1
1
  export const getUpcomingQueue = async (
2
2
  plugin?: QuickBrickPlugin | ZappPlugin
3
3
  ): Promise<unknown[] | null> => {
4
- const QueueManager = (plugin as any)?.module?.QueueManager;
4
+ const module = (plugin as any)?.module;
5
+ const QueueManager = module?.QueueManager;
6
+ const setupQuickBrickQueue = module?.setupQuickBrickQueue;
5
7
 
6
- if (!QueueManager?.instance) {
8
+ if (!QueueManager) {
9
+ return null;
10
+ }
11
+
12
+ if (
13
+ !QueueManager.isInitialized?.() &&
14
+ typeof setupQuickBrickQueue === "function"
15
+ ) {
16
+ setupQuickBrickQueue();
17
+ }
18
+
19
+ if (!QueueManager.isInitialized?.()) {
7
20
  return null;
8
21
  }
9
22
 
@@ -59,13 +59,10 @@ export const parseTimeToSeconds = (timeStr: string): number => {
59
59
  * on playerManager, decoupling Queue playback logic entirely from OverlaysObserver (which should
60
60
  * strictly focus on recommendation visuals and chapter markers).
61
61
  */
62
- export const retrieveFeedUrl = async (
63
- entry: ZappEntry,
64
- plugins?: ZappPlugin[]
65
- ): Promise<string> => {
62
+ export const retrieveFeedUrl = async (entry: ZappEntry): Promise<string> => {
66
63
  if (!entry) return null;
67
64
 
68
- const availablePlugins = plugins || appStore.get("plugins");
65
+ const availablePlugins = appStore.get("plugins");
69
66
 
70
67
  const queuePlugin = findPluginByIdentifier(
71
68
  "queue-action",
@@ -36,3 +36,79 @@ describe("PlayerNative.isAudioItem", () => {
36
36
  expect(playerWithEntry(null).isAudioItem()).toBe(false);
37
37
  });
38
38
  });
39
+
40
+ describe("PlayerNative.command", () => {
41
+ it("invokes native function with playerId on iOS platform", () => {
42
+ const player = new PlayerNative({
43
+ entry: null,
44
+ player: { current: {} } as any,
45
+ playerId: "test-player",
46
+ playerPluginId: "QuickBrickPlayerPlugin",
47
+ });
48
+
49
+ const commandSpy = jest.fn();
50
+
51
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({
52
+ command: commandSpy,
53
+ } as any);
54
+
55
+ player.command("setPlayerControls", { transport: ["play"] });
56
+
57
+ expect(commandSpy).toHaveBeenCalledWith(
58
+ "setPlayerControls",
59
+ "test-player",
60
+ {
61
+ transport: ["play"],
62
+ }
63
+ );
64
+ });
65
+
66
+ it("invokes native function with view tag on Android when method exists", () => {
67
+ const reactUtils = require("../../../reactUtils");
68
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
69
+
70
+ const player = new PlayerNative({
71
+ entry: null,
72
+ player: { current: {} } as any,
73
+ playerId: "test-player",
74
+ playerPluginId: "QuickBrickPlayerPlugin",
75
+ });
76
+
77
+ const commandSpy = jest.fn();
78
+
79
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({
80
+ command: commandSpy,
81
+ } as any);
82
+
83
+ jest.spyOn(player, "getComponentNode").mockReturnValue(12345 as any);
84
+
85
+ player.command("setPlayerControls", { transport: ["play"] });
86
+
87
+ expect(commandSpy).toHaveBeenCalledWith(12345, "setPlayerControls", {
88
+ transport: ["play"],
89
+ });
90
+
91
+ (reactUtils.isApplePlatform as jest.Mock).mockRestore();
92
+ });
93
+
94
+ it("handles when native module does not have command method on Android", () => {
95
+ const reactUtils = require("../../../reactUtils");
96
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
97
+
98
+ const player = new PlayerNative({
99
+ entry: null,
100
+ player: { current: {} } as any,
101
+ playerId: "test-player",
102
+ playerPluginId: "KalturaPlayerPlugin",
103
+ });
104
+
105
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({} as any);
106
+ jest.spyOn(player, "getComponentNode").mockReturnValue(12345 as any);
107
+
108
+ expect(() => {
109
+ player.command("setPlayerControls", { transport: ["play"] });
110
+ }).not.toThrow();
111
+
112
+ (reactUtils.isApplePlatform as jest.Mock).mockRestore();
113
+ });
114
+ });
@@ -0,0 +1,62 @@
1
+ import { NativeModules } from "react-native";
2
+ import {
3
+ PlayerNativeCommandTypes,
4
+ PlayerNativeSendCommand,
5
+ } from "../playerNativeCommand";
6
+
7
+ describe("PlayerNativeSendCommand", () => {
8
+ const reactUtils = require("../../../reactUtils");
9
+
10
+ afterEach(() => {
11
+ jest.restoreAllMocks();
12
+ });
13
+
14
+ it("calls NativeModules.PlayerModule.command on Apple platform with playerId", () => {
15
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(true);
16
+
17
+ NativeModules.PlayerModule = {
18
+ command: jest.fn(),
19
+ };
20
+
21
+ PlayerNativeSendCommand(
22
+ PlayerNativeCommandTypes.setPlayerControls,
23
+ "player-123",
24
+ { transport: ["play"] }
25
+ );
26
+
27
+ expect(NativeModules.PlayerModule.command).toHaveBeenCalledWith(
28
+ "setPlayerControls",
29
+ "player-123",
30
+ { transport: ["play"] }
31
+ );
32
+ });
33
+
34
+ it("does not call NativeModules.PlayerModule.command on non-Apple platform", () => {
35
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
36
+
37
+ NativeModules.PlayerModule = {
38
+ command: jest.fn(),
39
+ };
40
+
41
+ PlayerNativeSendCommand(
42
+ PlayerNativeCommandTypes.setPlayerControls,
43
+ "player-123",
44
+ { transport: ["play"] }
45
+ );
46
+
47
+ expect(NativeModules.PlayerModule.command).not.toHaveBeenCalled();
48
+ });
49
+
50
+ it("does nothing when playerId or command is missing", () => {
51
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(true);
52
+
53
+ NativeModules.PlayerModule = {
54
+ command: jest.fn(),
55
+ };
56
+
57
+ PlayerNativeSendCommand("", "player-123");
58
+ PlayerNativeSendCommand("setPlayerControls", "");
59
+
60
+ expect(NativeModules.PlayerModule.command).not.toHaveBeenCalled();
61
+ });
62
+ });
@@ -0,0 +1,97 @@
1
+ const mockRegister = jest.fn();
2
+ let mockXray: Record<string, unknown> | null = {};
3
+
4
+ jest.mock("../../../logger", () => ({
5
+ getXray: () => mockXray,
6
+ }));
7
+
8
+ const loadToolbox = () => {
9
+ let module;
10
+
11
+ jest.isolateModules(() => {
12
+ module = require("../playerToolbox");
13
+ });
14
+
15
+ return module as typeof import("../playerToolbox");
16
+ };
17
+
18
+ const player = (overrides = {}) => ({
19
+ getSeekableDuration: () => 100,
20
+ getContentPosition: () => 40,
21
+ seekTo: jest.fn(),
22
+ ...overrides,
23
+ });
24
+
25
+ const manager = (active) =>
26
+ ({ getActivePlayer: () => active, isCasting: () => false }) as any;
27
+
28
+ const registeredTools = async (active) => {
29
+ mockRegister.mockResolvedValue(undefined);
30
+ mockXray = { registerReactToolbox: mockRegister };
31
+ await loadToolbox().registerPlayerToolbox(manager(active));
32
+
33
+ const { tools } = mockRegister.mock.calls[0][0];
34
+
35
+ return Object.fromEntries(tools.map((tool) => [tool.name, tool.handler]));
36
+ };
37
+
38
+ describe("playerToolbox", () => {
39
+ beforeEach(() => {
40
+ mockRegister.mockReset();
41
+ });
42
+
43
+ it("does nothing when X-Ray has no React toolbox API", async () => {
44
+ mockXray = {};
45
+
46
+ await expect(
47
+ loadToolbox().registerPlayerToolbox(manager(null))
48
+ ).resolves.toBe(false);
49
+ });
50
+
51
+ it("does nothing when getXray returns null", async () => {
52
+ mockXray = null;
53
+
54
+ await expect(
55
+ loadToolbox().registerPlayerToolbox(manager(null))
56
+ ).resolves.toBe(false);
57
+ });
58
+
59
+ it("swallows a failed registration", async () => {
60
+ mockRegister.mockRejectedValue(new Error("no native bridge"));
61
+ mockXray = { registerReactToolbox: mockRegister };
62
+
63
+ await expect(
64
+ loadToolbox().registerPlayerToolbox(manager(null))
65
+ ).resolves.toBe(false);
66
+ });
67
+
68
+ it("seeks to an absolute position, from the end when negative, clamped", async () => {
69
+ const active = player();
70
+ const tools = await registeredTools(active);
71
+
72
+ expect(tools.seek({ position: 30 })).toEqual({ position: 30 });
73
+ expect(tools.seek({ position: -10 })).toEqual({ position: 90 });
74
+ expect(tools.seek({ position: 500 })).toEqual({ position: 100 });
75
+ expect(tools.seek({ position: -500 })).toEqual({ position: 0 });
76
+ expect(active.seekTo.mock.calls).toEqual([[30], [90], [100], [0]]);
77
+ });
78
+
79
+ it("offsets from the current position and refuses zero", async () => {
80
+ const tools = await registeredTools(player());
81
+
82
+ expect(tools.offset({ seconds: 15 })).toEqual({ from: 40, position: 55 });
83
+ expect(tools.offset({ seconds: -60 })).toEqual({ from: 40, position: 0 });
84
+
85
+ expect(() => tools.offset({ seconds: 0 })).toThrow(
86
+ "Ignored zero relative seek"
87
+ );
88
+ });
89
+
90
+ it("refuses to seek a stream that is not seekable", async () => {
91
+ const tools = await registeredTools(
92
+ player({ getSeekableDuration: () => 0 })
93
+ );
94
+
95
+ expect(() => tools.seek({ position: 10 })).toThrow("Seek is not supported");
96
+ });
97
+ });
@@ -0,0 +1,62 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+
3
+ import { usePlayerControllerSetup } from "../usePlayerControllerSetup";
4
+ import { PlayerAnalyticsManager } from "../../../analyticsUtils/PlayerAnalyticsManager";
5
+
6
+ const calls: string[] = [];
7
+
8
+ jest.mock("../index", () => ({
9
+ playerManager: {
10
+ isPlayerRegistered: jest.fn(() => false),
11
+ registerPlayer: jest.fn(() => calls.push("registerPlayer")),
12
+ unregisterPlayer: jest.fn(),
13
+ },
14
+ }));
15
+
16
+ jest.mock("../../../analyticsUtils/PlayerAnalyticsManager", () => ({
17
+ PlayerAnalyticsManager: {
18
+ getInstance: jest.fn(() => calls.push("analyticsManager")),
19
+ },
20
+ }));
21
+
22
+ jest.mock("../../../reactHooks/useConfiguration", () => ({
23
+ useConfiguration: () => ({}),
24
+ }));
25
+
26
+ jest.mock("../../../playerUtils/useValidatePlayerConfig", () => ({
27
+ useValidatePlayerConfig: jest.fn(),
28
+ }));
29
+
30
+ jest.mock("../../../reactUtils", () => ({
31
+ isTV: () => false,
32
+ }));
33
+
34
+ jest.mock(
35
+ "@applicaster/zapp-react-native-ui-components/Helpers/Platform",
36
+ () => ({
37
+ isAppleTV: () => false,
38
+ })
39
+ );
40
+
41
+ class Controller {
42
+ destroy = jest.fn();
43
+ }
44
+
45
+ describe("usePlayerControllerSetup", () => {
46
+ it("creates the analytics manager before the player registers", () => {
47
+ renderHook(() =>
48
+ usePlayerControllerSetup({
49
+ props: { playerId: "player-1", entry: { id: "entry-1" } },
50
+ ControllerType: Controller,
51
+ ref: null,
52
+ manifest: {},
53
+ pluginId: "plugin",
54
+ })
55
+ );
56
+
57
+ // The manager attaches analytics to players as they register, so a player
58
+ // registered before it exists would send no player analytics events
59
+ expect(PlayerAnalyticsManager.getInstance).toHaveBeenCalled();
60
+ expect(calls).toEqual(["analyticsManager", "registerPlayer"]);
61
+ });
62
+ });
@@ -59,6 +59,19 @@ export enum SharedPlayerCallBacksKeys {
59
59
  // PIP
60
60
  OnPlayerDetached = "onPlayerDetached",
61
61
  OnPlayerAttached = "onPlayerAttached",
62
+
63
+ OnRemoteCommand = "onRemoteCommand",
64
+ }
65
+
66
+ // Ids native sends in onRemoteCommand (lock screen / Control Center / CarPlay buttons)
67
+ export enum RemoteCommand {
68
+ Play = "play",
69
+ Pause = "pause",
70
+ Stop = "stop",
71
+ NextTrack = "nextTrack",
72
+ PreviousTrack = "previousTrack",
73
+ SkipForward = "skipForward",
74
+ SkipBackward = "skipBackward",
62
75
  }
63
76
 
64
77
  export enum PlayerRole {
@@ -11,6 +11,7 @@ import {
11
11
  import { setUserLanguagePreference } from "./userLanguagePreference";
12
12
  import { PlayerRole } from "./const";
13
13
  import { RNPlayerManager } from "./nativePlayerManager";
14
+ import { registerPlayerToolbox } from "./playerToolbox";
14
15
 
15
16
  const { log_error, log_debug, log_warning } = createLogger({
16
17
  category: "General",
@@ -54,6 +55,7 @@ export class PlayerManager {
54
55
  public static getInstance() {
55
56
  if (!PlayerManager.instance) {
56
57
  PlayerManager.instance = new PlayerManager();
58
+ registerPlayerToolbox(PlayerManager.instance);
57
59
  }
58
60
 
59
61
  return PlayerManager.instance;
@@ -395,6 +397,11 @@ export class PlayerManager {
395
397
  return this.manager.removeHandler(event, handler);
396
398
  }
397
399
 
400
+ /** Whether anything handles `event` now, e.g. a mounted PlayerContainer for "toggleFullscreen". */
401
+ public hasHandler(event: string) {
402
+ return this.manager.handlers[event]?.length > 0;
403
+ }
404
+
398
405
  // TODO: should not be
399
406
  public invokeHandler(event, ...args) {
400
407
  return this.manager.invokeHandler(event, ...args);
@@ -746,6 +746,13 @@ export class Player {
746
746
  });
747
747
  };
748
748
 
749
+ onRemoteCommand = (event: QuickBrickPlayer.RemoteCommandEvent) => {
750
+ this.invokeListenersUpdate({
751
+ callbackName: SharedPlayerCallBacksKeys.OnRemoteCommand,
752
+ event,
753
+ });
754
+ };
755
+
749
756
  getTracksState = (): QuickBrickPlayer.TracksState =>
750
757
  this.playerState.trackState;
751
758
 
@@ -823,6 +830,8 @@ export class Player {
823
830
  // PIP
824
831
  onPlayerDetached: this.onPlayerDetached,
825
832
  onPlayerAttached: this.onPlayerAttached,
833
+
834
+ onRemoteCommand: this.onRemoteCommand,
826
835
  });
827
836
 
828
837
  play = () => {};
@@ -832,6 +841,7 @@ export class Player {
832
841
  setPlaybackRate = (_rate) => {};
833
842
  startSleepTimer = (_timestamp) => {};
834
843
  cancelSleepTimer = () => {};
844
+ command = (_command: string, _userInfo?: Record<string, any>) => {};
835
845
 
836
846
  getPluginConfiguration = () => null;
837
847
  appStateChange = (_appState, _previousAppState) => {};
@@ -6,6 +6,7 @@ import { findNodeHandle } from "react-native";
6
6
  import { PlayerRole } from "./const";
7
7
  import { toBooleanWithDefaultFalse } from "../../booleanUtils";
8
8
  import { RNPlayerManager } from "./nativePlayerManager";
9
+ import { isApplePlatform } from "../../reactUtils";
9
10
 
10
11
  const logger = createLogger({
11
12
  category: "PlayerNativeController",
@@ -27,6 +28,7 @@ interface PlayerMethods {
27
28
  appStateChange?: (appState: string, previousAppState: string) => void;
28
29
  closeNativePlayer?: () => void;
29
30
  togglePlayPause?: () => void;
31
+ command?: (command: string, userInfo?: Record<string, any>) => void;
30
32
  }
31
33
 
32
34
  type PlayerComponent = ReactComponent<PlayerRefProps> & PlayerMethods;
@@ -52,6 +54,7 @@ const PlayerModuleFuncNames = {
52
54
  startSleepTimer: "startSleepTimer",
53
55
  cancelSleepTimer: "cancelSleepTimer",
54
56
  getSleepTimerEnd: "getSleepTimerEnd",
57
+ command: "command",
55
58
  };
56
59
 
57
60
  export class PlayerNative extends Player {
@@ -206,6 +209,25 @@ export class PlayerNative extends Player {
206
209
  }
207
210
  };
208
211
 
212
+ command = (command: string, userInfo?: Record<string, any>) => {
213
+ if (isApplePlatform()) {
214
+ const module = this.getPlayerModule();
215
+ module?.command?.(command, this.playerId, userInfo);
216
+
217
+ return true;
218
+ }
219
+
220
+ if (
221
+ !this.invokeNativeFunction(
222
+ PlayerModuleFuncNames.command,
223
+ command,
224
+ userInfo
225
+ )
226
+ ) {
227
+ this.currentPlayerComponent()?.command?.(command, userInfo);
228
+ }
229
+ };
230
+
209
231
  disableBufferAnimation = (): boolean => false;
210
232
 
211
233
  selectTrack = (
@@ -1,14 +1,11 @@
1
1
  import { isApplePlatform } from "../../reactUtils";
2
2
  import { NativeModules } from "react-native";
3
3
 
4
- const NativePlayerModule = isApplePlatform()
5
- ? NativeModules.PlayerModule
6
- : NativeModules.QuickBrickDefaultPlayerModule;
7
-
8
4
  const PlayerNativeCommandTypes = {
9
5
  pause: "pause",
10
6
  clearPlayerData: "clearPlayerData",
11
7
  removeViewByNativeId: "removeViewByNativeId",
8
+ setPlayerControls: "setPlayerControls",
12
9
  };
13
10
 
14
11
  const PlayerNativeSendCommand = (
@@ -16,8 +13,8 @@ const PlayerNativeSendCommand = (
16
13
  playerId: string,
17
14
  userInfo?: Record<string, any>
18
15
  ) => {
19
- if (playerId && command) {
20
- NativePlayerModule?.command?.(command, playerId, userInfo);
16
+ if (isApplePlatform() && playerId && command) {
17
+ NativeModules.PlayerModule?.command?.(command, playerId, userInfo);
21
18
  }
22
19
  };
23
20