@applicaster/zapp-react-native-utils 16.0.0-alpha.2851031376 → 16.0.0-alpha.2963644197

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 (186) hide show
  1. package/actionsExecutor/ActionExecutor.ts +57 -12
  2. package/actionsExecutor/ActionExecutorContext.tsx +111 -313
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -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__/loadItemsFromSource.test.ts +88 -0
  9. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  12. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  13. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  14. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  15. package/actionsExecutor/actions/appRestart.ts +24 -0
  16. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  17. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  18. package/actionsExecutor/actions/goBack.ts +60 -0
  19. package/actionsExecutor/actions/goHome.ts +31 -0
  20. package/actionsExecutor/actions/index.ts +42 -0
  21. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  22. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  23. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  24. package/actionsExecutor/actions/navigateToScreen.ts +137 -0
  25. package/actionsExecutor/actions/openBottomSheet.ts +338 -0
  26. package/actionsExecutor/actions/presentScreen.ts +78 -0
  27. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  28. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  29. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  30. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  31. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  32. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  33. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  34. package/actionsExecutor/actions/showAlert.ts +51 -0
  35. package/actionsExecutor/actions/showToast.ts +87 -0
  36. package/actionsExecutor/actions/switchLayout.ts +40 -0
  37. package/actionsExecutor/consts.ts +27 -0
  38. package/actionsExecutor/feedDecorator.ts +6 -6
  39. package/actionsExecutor/types.ts +59 -0
  40. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  41. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  42. package/appUtils/HooksManager/index.ts +9 -0
  43. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  44. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  45. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  46. package/appUtils/contextKeysManager/index.ts +1 -1
  47. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  48. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  49. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  50. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  51. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  52. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  53. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  54. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  55. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  56. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  57. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  58. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  59. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  60. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  61. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  62. package/appUtils/playerManager/index.ts +1 -1
  63. package/appUtils/playerManager/player.ts +125 -3
  64. package/appUtils/playerManager/playerFactory.ts +1 -1
  65. package/appUtils/playerManager/playerNative.ts +28 -4
  66. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  67. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  68. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  69. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  70. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  71. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  72. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  73. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  74. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  75. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  76. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  77. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  78. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  79. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  80. package/arrayUtils/__tests__/sample.test.ts +61 -0
  81. package/arrayUtils/index.ts +136 -20
  82. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  83. package/bottomSheet/index.ts +17 -0
  84. package/cellUtils/index.ts +33 -8
  85. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  86. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  87. package/colorUtils/index.ts +50 -0
  88. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  89. package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
  90. package/configurationUtils/manifestKeyParser.ts +50 -10
  91. package/configurationUtils/modalBlocksParser.ts +214 -0
  92. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  93. package/entryActions/aliasPresentation.ts +108 -0
  94. package/entryActions/buildEntryActions.ts +167 -0
  95. package/entryActions/index.ts +15 -0
  96. package/entryActions/types.ts +39 -0
  97. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  98. package/manifestUtils/_internals/index.js +14 -3
  99. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  100. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  101. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  102. package/manifestUtils/fieldUtils/index.js +125 -0
  103. package/manifestUtils/index.js +3 -0
  104. package/manifestUtils/keys.js +8 -0
  105. package/manifestUtils/mobileAction/button/index.js +16 -0
  106. package/manifestUtils/mobileAction/container/index.js +3 -1
  107. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  108. package/manifestUtils/modalBlocks.js +304 -0
  109. package/modalState/ContentViewModel.ts +113 -0
  110. package/modalState/EditableCollection.ts +17 -0
  111. package/modalState/EditableCollectionRegistry.ts +51 -0
  112. package/modalState/ModalOrchestrator.ts +212 -0
  113. package/modalState/RemoteEditableCollection.ts +235 -0
  114. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  115. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  116. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  117. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  118. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  119. package/modalState/__tests__/index.test.ts +30 -1
  120. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  121. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  122. package/modalState/index.ts +35 -83
  123. package/modalState/store.ts +109 -0
  124. package/modalState/types.ts +162 -0
  125. package/modalState/useBottomSheetContent.ts +109 -0
  126. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  127. package/numberUtils/__tests__/isZero.test.ts +27 -0
  128. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  129. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  130. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  131. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  132. package/numberUtils/index.ts +27 -8
  133. package/package.json +2 -2
  134. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  135. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  136. package/pipesUtils/index.ts +1 -0
  137. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  138. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  139. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  140. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  141. package/playerUtils/contentDataKeys.ts +134 -0
  142. package/playerUtils/index.ts +37 -16
  143. package/playerUtils/isAudioItem.ts +26 -0
  144. package/playerUtils/resolvePlayerActions.ts +71 -0
  145. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  146. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  147. package/pluginUtils/index.ts +29 -0
  148. package/reactHooks/actions/index.ts +117 -2
  149. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  150. package/reactHooks/cell-click/index.ts +24 -17
  151. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  152. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  153. package/reactHooks/feed/index.ts +5 -1
  154. package/reactHooks/feed/useBatchLoading.ts +9 -1
  155. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  156. package/reactHooks/index.ts +2 -0
  157. package/reactHooks/layout/index.ts +1 -1
  158. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  159. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  160. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  161. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  162. package/reactHooks/navigation/index.ts +3 -1
  163. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  164. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  165. package/reactHooks/navigation/useRoute.ts +22 -5
  166. package/reactHooks/state/useComponentScreenState.ts +1 -1
  167. package/reactHooks/usePluginConfiguration.ts +4 -1
  168. package/reactHooks/utils/__tests__/index.test.js +22 -2
  169. package/reactHooks/utils/index.ts +13 -2
  170. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  171. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  172. package/stringUtils/index.ts +2 -2
  173. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  174. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  175. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  176. package/uiActionsRegistrator/index.ts +25 -0
  177. package/uiActionsRegistrator/registry.ts +335 -0
  178. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  179. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  180. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  181. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  182. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  183. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  184. package/playerUtils/getPlayerActionButtons.ts +0 -17
  185. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  186. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,114 @@
1
+ import { PlayerNative } from "../playerNative";
2
+
3
+ const playerWithEntry = (entry: any) =>
4
+ new PlayerNative({
5
+ entry,
6
+ player: null as any,
7
+ playerId: "test-player",
8
+ });
9
+
10
+ describe("PlayerNative.isAudioItem", () => {
11
+ it.each(["audio", "audio-player", "audio-detail", "audio-show", "audio-hub"])(
12
+ "treats the %s content type as audio",
13
+ (type) => {
14
+ expect(playerWithEntry({ type: { value: type } }).isAudioItem()).toBe(
15
+ true
16
+ );
17
+ }
18
+ );
19
+
20
+ it.each(["video", "video-detail", "comic-detail", "article-show"])(
21
+ "does not treat the %s content type as audio",
22
+ (type) => {
23
+ expect(playerWithEntry({ type: { value: type } }).isAudioItem()).toBe(
24
+ false
25
+ );
26
+ }
27
+ );
28
+
29
+ it("falls back to the media type when the content type says nothing", () => {
30
+ const entry = { content: { type: "audio/mpeg" }, type: { value: "link" } };
31
+
32
+ expect(playerWithEntry(entry).isAudioItem()).toBe(true);
33
+ });
34
+
35
+ it("returns false when there is no entry", () => {
36
+ expect(playerWithEntry(null).isAudioItem()).toBe(false);
37
+ });
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,64 @@
1
+ import { renderHook, act } from "@testing-library/react-native";
2
+ import { BehaviorSubject } from "rxjs";
3
+
4
+ import { usePlayerContent } from "../usePlayerContent";
5
+
6
+ const mockPlayer: any = {
7
+ subject: null as BehaviorSubject<any> | null,
8
+ getContent: jest.fn(),
9
+ getContentObservable: jest.fn(),
10
+ };
11
+
12
+ jest.mock("../usePlayer", () => ({
13
+ usePlayer: () => mockPlayer,
14
+ }));
15
+
16
+ describe("usePlayerContent", () => {
17
+ beforeEach(() => {
18
+ mockPlayer.subject = new BehaviorSubject({
19
+ title: "First Title",
20
+ summary: "First Summary",
21
+ });
22
+
23
+ mockPlayer.getContent = jest.fn(() => mockPlayer.subject.getValue());
24
+
25
+ mockPlayer.getContentObservable = jest.fn(() =>
26
+ mockPlayer.subject.asObservable()
27
+ );
28
+ });
29
+
30
+ it("returns the player's current content", () => {
31
+ const { result } = renderHook(() => usePlayerContent());
32
+
33
+ expect(result.current).toEqual({
34
+ title: "First Title",
35
+ summary: "First Summary",
36
+ });
37
+ });
38
+
39
+ it("re-renders when the player publishes new content", () => {
40
+ const { result } = renderHook(() => usePlayerContent());
41
+
42
+ act(() => {
43
+ mockPlayer.subject.next({
44
+ title: "Second Title",
45
+ summary: "Second Summary",
46
+ });
47
+ });
48
+
49
+ expect(result.current).toEqual({
50
+ title: "Second Title",
51
+ summary: "Second Summary",
52
+ });
53
+ });
54
+
55
+ it("unsubscribes on unmount", () => {
56
+ const { unmount } = renderHook(() => usePlayerContent());
57
+
58
+ expect(mockPlayer.subject.observed).toBe(true);
59
+
60
+ unmount();
61
+
62
+ expect(mockPlayer.subject.observed).toBe(false);
63
+ });
64
+ });
@@ -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 {
@@ -67,3 +80,23 @@ export enum PlayerRole {
67
80
  Chromecast = "Chromecast",
68
81
  Unspecified = "Unspecified",
69
82
  }
83
+
84
+ /**
85
+ * The playback engine backing a web player. Published on
86
+ * `window.applicaster.playerType` when a player is created, so that plugins
87
+ * observing the player can tell which engine they are looking at instead of
88
+ * inferring it from the API the instance happens to expose.
89
+ *
90
+ * Keep in sync with `ApplicasterGlobals["playerType"]` in applicaster-types.
91
+ */
92
+ export enum WebPlayerEngine {
93
+ Videojs = "videojs",
94
+ Hlsjs = "hlsjs",
95
+ Dashjs = "dashjs",
96
+ }
97
+
98
+ export enum PLAYER_EVENTS {
99
+ PlayNextTriggered = "play_next_triggered",
100
+ }
101
+
102
+ export type PlayNextTriggeredEvent = { id: string };
@@ -9,7 +9,7 @@ import {
9
9
  unsubscribeToDeviceNetworkChanges,
10
10
  } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
11
11
  import { setUserLanguagePreference } from "./userLanguagePreference";
12
- import { PlayerRole } from "./conts";
12
+ import { PlayerRole } from "./const";
13
13
  import { RNPlayerManager } from "./nativePlayerManager";
14
14
 
15
15
  const { log_error, log_debug, log_warning } = createLogger({
@@ -1,9 +1,22 @@
1
1
  import * as R from "ramda";
2
- import { BehaviorSubject } from "rxjs";
2
+ import { BehaviorSubject, Observable } from "rxjs";
3
+ import { distinctUntilChanged } from "rxjs/operators";
3
4
  import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
4
5
  import { createLogger, utilsLogger } from "../../logger";
5
- import { getBoolFromConfigValue } from "../../configurationUtils";
6
- import { PlayerRole, SharedPlayerCallBacksKeys } from "./conts";
6
+ import {
7
+ getBoolFromConfigValue,
8
+ imageSrcFromMediaItem,
9
+ } from "../../configurationUtils";
10
+ // Imported from the leaf modules rather than the `playerUtils` barrel: that
11
+ // barrel imports `playerManager`, so going through it would create a require
12
+ // cycle (playerManager/index -> player -> playerUtils/index -> playerManager).
13
+ import {
14
+ resolvePlayerTitleSubtitle,
15
+ getPlayerContentDataKeys,
16
+ } from "../../playerUtils/resolvePlayerTitleSubtitle";
17
+ import { isAudioItem } from "../../playerUtils/isAudioItem";
18
+ import { isTV } from "../../reactUtils";
19
+ import { PlayerRole, SharedPlayerCallBacksKeys } from "./const";
7
20
  import { OverlaysObserver } from "./OverlayObserver/OverlaysObserver";
8
21
  import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
9
22
 
@@ -19,6 +32,23 @@ export declare type PlayerControllerListenerData = {
19
32
  id: string;
20
33
  listener: QuickBrickPlayer.SharedPlayerCallBacks;
21
34
  };
35
+
36
+ /**
37
+ * The player's resolved Title/Subtitle text, published by the player the same
38
+ * way duration and progress are. Consumers render these values as-is rather
39
+ * than reading `entry` or the plugin configuration themselves.
40
+ */
41
+ export type PlayerContent = {
42
+ title: Option<string | number>;
43
+ summary: Option<string | number>;
44
+ /**
45
+ * Cover art for the content currently playing. Published alongside the text
46
+ * (rather than read from `entry` by whoever needs it) so it follows the same
47
+ * entry: on live audio that means the programme's own artwork, refreshed
48
+ * with every feed poll, instead of the channel's.
49
+ */
50
+ imageUrl: Option<string>;
51
+ };
22
52
  /**
23
53
  * Player Instance Controller
24
54
  * Instance exposes utility methods that will help set or get state
@@ -45,6 +75,7 @@ export class Player {
45
75
  readonly playerRole: PlayerRole = PlayerRole.Unspecified;
46
76
  private overlaysObserver?: OverlaysObserver | null;
47
77
  private entryObservable?: BehaviorSubject<ZappEntry> | null;
78
+ private contentSubject?: BehaviorSubject<PlayerContent> | null;
48
79
 
49
80
  protected listeners: {
50
81
  [key: string]: QuickBrickPlayer.SharedPlayerCallBacks;
@@ -58,7 +89,17 @@ export class Player {
58
89
 
59
90
  set entry(newEntry: ZappEntry | null) {
60
91
  this._entry = newEntry;
92
+ // The live entry is scoped to the entry it overlays - see
93
+ // `OverlaysObserver.clearLiveEntry`. No-op when there is no observer,
94
+ // which is every non-live player.
95
+ this.overlaysObserver?.clearLiveEntry();
61
96
  this.entryObservable?.next(newEntry);
97
+ // Optional chaining short-circuits the whole call expression, so
98
+ // `getContent()` is NOT evaluated while no subscriber exists. That
99
+ // matters: `PlayerNative` assigns `this.entry` in its constructor, before
100
+ // subclass arrow-function properties such as `getPluginConfiguration`
101
+ // have been assigned.
102
+ this.contentSubject?.next(this.getContent());
62
103
  }
63
104
 
64
105
  constructor(props) {
@@ -117,6 +158,77 @@ export class Player {
117
158
  return this.entryObservable;
118
159
  };
119
160
 
161
+ /**
162
+ * The player's resolved Title/Subtitle.
163
+ *
164
+ * Resolved on demand rather than cached: the plugin configuration arrives
165
+ * asynchronously on both the native and cast paths, so a value computed once
166
+ * at entry-set time would be stale for whichever arrives first.
167
+ *
168
+ * Every fallback (no config, empty/whitespace key, unresolvable key, key
169
+ * resolving to an empty string or to a non-string/non-number) lives in
170
+ * `resolvePlayerContentText` and is never reimplemented here.
171
+ */
172
+ getContent = (): PlayerContent => {
173
+ // Live audio keeps playing one channel while the programme on air
174
+ // changes, so the observer's freshly-loaded programme entry wins when
175
+ // there is one. Read through `?.` so this never constructs an observer:
176
+ // a VOD or cast player has none and falls straight through to its entry.
177
+ const entry = this.overlaysObserver?.liveEntry ?? this.entry;
178
+
179
+ return {
180
+ ...resolvePlayerTitleSubtitle({
181
+ entry,
182
+ pluginConfiguration: this.getPluginConfiguration(),
183
+ dataKeys: getPlayerContentDataKeys({
184
+ isTV: isTV(),
185
+ isAudioContent: isAudioItem(entry),
186
+ }),
187
+ }),
188
+ // Same selection Android's `EntryHelpers.extractCoverImage` makes:
189
+ // prefer the `image_base` media item, otherwise the first one available.
190
+ // Reused rather than reimplemented so the two platforms cannot drift.
191
+ imageUrl: entry ? imageSrcFromMediaItem(entry, []) : undefined,
192
+ };
193
+ };
194
+
195
+ /**
196
+ * Created lazily, like `entryObservable`. An eagerly created subject would
197
+ * resolve during `PlayerNative`'s constructor and call a not-yet-assigned
198
+ * `getPluginConfiguration`.
199
+ *
200
+ * The seed is produced by calling the resolver, never from raw entry fields:
201
+ * a `BehaviorSubject` replays its seed synchronously on subscribe, so a raw
202
+ * seed would overwrite correctly-resolved text at mount.
203
+ */
204
+ getContentObservable = (): Observable<PlayerContent> => {
205
+ if (!this.contentSubject) {
206
+ this.contentSubject = new BehaviorSubject<PlayerContent>(
207
+ this.getContent()
208
+ );
209
+ }
210
+
211
+ return this.contentSubject.asObservable().pipe(
212
+ // `resolvePlayerTitleSubtitle` returns a fresh object every call, so
213
+ // reference equality would never dedupe. Compare by value.
214
+ distinctUntilChanged(
215
+ (previous, next) =>
216
+ previous.title === next.title &&
217
+ previous.summary === next.summary &&
218
+ previous.imageUrl === next.imageUrl
219
+ )
220
+ );
221
+ };
222
+
223
+ /**
224
+ * Re-resolves and publishes the current content. Called when something the
225
+ * resolution depends on changed without `entry` itself being reassigned -
226
+ * today that is the observer swapping in a newly-loaded live programme.
227
+ */
228
+ publishContent = () => {
229
+ this.contentSubject?.next(this.getContent());
230
+ };
231
+
120
232
  /**
121
233
  * ---------------------------------------- PLAYER SETTERS GETTERS ----------------------------------------
122
234
  * These methods let you get information about the content / ad playing
@@ -634,6 +746,13 @@ export class Player {
634
746
  });
635
747
  };
636
748
 
749
+ onRemoteCommand = (event: QuickBrickPlayer.RemoteCommandEvent) => {
750
+ this.invokeListenersUpdate({
751
+ callbackName: SharedPlayerCallBacksKeys.OnRemoteCommand,
752
+ event,
753
+ });
754
+ };
755
+
637
756
  getTracksState = (): QuickBrickPlayer.TracksState =>
638
757
  this.playerState.trackState;
639
758
 
@@ -711,6 +830,8 @@ export class Player {
711
830
  // PIP
712
831
  onPlayerDetached: this.onPlayerDetached,
713
832
  onPlayerAttached: this.onPlayerAttached,
833
+
834
+ onRemoteCommand: this.onRemoteCommand,
714
835
  });
715
836
 
716
837
  play = () => {};
@@ -720,6 +841,7 @@ export class Player {
720
841
  setPlaybackRate = (_rate) => {};
721
842
  startSleepTimer = (_timestamp) => {};
722
843
  cancelSleepTimer = () => {};
844
+ command = (_command: string, _userInfo?: Record<string, any>) => {};
723
845
 
724
846
  getPluginConfiguration = () => null;
725
847
  appStateChange = (_appState, _previousAppState) => {};
@@ -1,7 +1,7 @@
1
1
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
2
2
  import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
3
3
  import { Player } from "./player";
4
- import { PlayerRole } from "./conts";
4
+ import { PlayerRole } from "./const";
5
5
 
6
6
  type PlayerFactoryItem = {
7
7
  Component: any;
@@ -3,9 +3,10 @@ import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
3
3
  import { createLogger, utilsLogger } from "../../logger";
4
4
  import { Player } from "./player";
5
5
  import { findNodeHandle } from "react-native";
6
- import { PlayerRole } from "./conts";
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 = (
@@ -296,9 +318,11 @@ export class PlayerNative extends Player {
296
318
  }, listeners);
297
319
  };
298
320
 
299
- isAudioItem = () =>
300
- this.getEntry()?.content?.type?.includes?.("audio") ||
301
- this.getEntry()?.type?.value === "audio";
321
+ isAudioItem = (): boolean =>
322
+ Boolean(
323
+ this.getEntry()?.content?.type?.includes?.("audio") ||
324
+ this.getEntry()?.type?.value?.includes?.("audio")
325
+ );
302
326
 
303
327
  isFullScreenSupported = (): boolean => {
304
328
  const config = this.getConfig();
@@ -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
 
@@ -0,0 +1,43 @@
1
+ import * as React from "react";
2
+ import { Player, PlayerContent } from "./player";
3
+ import { usePlayer } from "./usePlayer";
4
+
5
+ const EMPTY_CONTENT: PlayerContent = {
6
+ title: null,
7
+ summary: null,
8
+ imageUrl: null,
9
+ };
10
+
11
+ /**
12
+ * Subscribes to the player's resolved Title/Subtitle, the same way
13
+ * `usePlayerState` subscribes to playback state. Modeled on that hook
14
+ * deliberately: one React bridge pattern for everything the manager publishes.
15
+ *
16
+ * Passing no `playerId` uses the active player, which is the right default -
17
+ * only one player instance is live at a time. `usePlayer` additionally swaps
18
+ * to the casting receiver while casting, so this follows cast handover
19
+ * automatically.
20
+ */
21
+ export const usePlayerContent = (playerId?: string): PlayerContent => {
22
+ const player: Player = usePlayer(playerId);
23
+
24
+ const [content, setContent] = React.useState<PlayerContent>(
25
+ () => player?.getContent() ?? EMPTY_CONTENT
26
+ );
27
+
28
+ React.useEffect(() => {
29
+ if (!player) {
30
+ setContent(EMPTY_CONTENT);
31
+
32
+ return;
33
+ }
34
+
35
+ const subscription = player
36
+ .getContentObservable()
37
+ .subscribe((next) => setContent(next));
38
+
39
+ return () => subscription.unsubscribe();
40
+ }, [player]);
41
+
42
+ return content;
43
+ };
@@ -3,7 +3,7 @@ import { useConfiguration } from "../../reactHooks/useConfiguration";
3
3
  import { useEffect } from "react";
4
4
  import { playerManager } from "./index";
5
5
  import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
6
- import { PlayerRole } from "./conts";
6
+ import { PlayerRole } from "./const";
7
7
  import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
8
8
  import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
9
9
  import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
@@ -1,7 +1,7 @@
1
1
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
2
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
3
3
  import { createLogger, utilsLogger } from "../../logger";
4
- import { userPreferencesNamespace } from "./conts";
4
+ import { userPreferencesNamespace } from "./const";
5
5
 
6
6
  export const preferredAudioLanguageStorageKey = "preferred_audio_language";
7
7
 
@@ -21,4 +21,12 @@ describe("anyTruthy", () => {
21
21
  expect(anyTruthy([true])).toBe(true);
22
22
  expect(anyTruthy([false])).toBe(false);
23
23
  });
24
+
25
+ it("should return true when the first value is true", () => {
26
+ expect(anyTruthy([true, false, false])).toBe(true);
27
+ });
28
+
29
+ it("should return true when only the last value is true", () => {
30
+ expect(anyTruthy([false, false, true])).toBe(true);
31
+ });
24
32
  });