@applicaster/zapp-react-native-utils 12.0.0-alpha.4757075613 → 12.0.0-alpha.4796013211

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 (88) hide show
  1. package/analyticsUtils/AnalyticPlayerListener.ts +141 -0
  2. package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
  5. package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
  6. package/analyticsUtils/analyticsPlugins.ts +25 -0
  7. package/analyticsUtils/events.ts +12 -0
  8. package/analyticsUtils/index.tsx +12 -0
  9. package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
  10. package/appUtils/accessibilityManager/const.ts +50 -0
  11. package/appUtils/accessibilityManager/hooks.ts +40 -0
  12. package/appUtils/accessibilityManager/index.ts +166 -0
  13. package/appUtils/accessibilityManager/logger.ts +5 -0
  14. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  15. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  16. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  17. package/appUtils/focusManager/index.ts +76 -57
  18. package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -44
  19. package/appUtils/focusManager/utils/index.ts +100 -0
  20. package/appUtils/focusManagerAux/index.ts +76 -0
  21. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  22. package/appUtils/index.js +2 -0
  23. package/appUtils/keyCodes/keys.web.js +8 -0
  24. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  25. package/appUtils/platform/const.ts +25 -0
  26. package/appUtils/platform/index.ts +3 -0
  27. package/appUtils/platform/platformUtils.ts +217 -0
  28. package/appUtils/playerManager/conts.ts +1 -0
  29. package/appUtils/playerManager/index.ts +20 -32
  30. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  31. package/appUtils/playerManager/player.ts +10 -3
  32. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
  33. package/appUtils/playerManager/playerNative.ts +11 -15
  34. package/appUtils/playerManager/usePlayerControllerSetup.tsx +8 -2
  35. package/appUtils/playerManager/usePlayerState.tsx +19 -34
  36. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  37. package/arrayUtils/index.ts +5 -0
  38. package/booleanUtils/index.ts +4 -4
  39. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  40. package/cellUtils/index.ts +44 -17
  41. package/dateUtils/index.ts +11 -0
  42. package/functionUtils/index.ts +38 -0
  43. package/headersUtils/index.ts +1 -0
  44. package/index.d.ts +15 -0
  45. package/inflatedUrlUtils/index.ts +4 -4
  46. package/keyboardState/index.ts +0 -0
  47. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  48. package/localizationUtils/index.ts +13 -22
  49. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  50. package/navigationUtils/index.ts +48 -0
  51. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  52. package/numberUtils/__tests__/toNumber.test.ts +2 -2
  53. package/numberUtils/index.ts +9 -18
  54. package/package.json +2 -2
  55. package/playerUtils/imaScriptDom.ts +59 -0
  56. package/pluginUtils/index.ts +9 -0
  57. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +16 -1
  58. package/reactHooks/cell-click/__tests__/index.test.js +10 -1
  59. package/reactHooks/cell-click/index.ts +12 -12
  60. package/reactHooks/debugging/__tests__/index.test.js +81 -11
  61. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  62. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  63. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  64. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  65. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  66. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  67. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +43 -29
  68. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  69. package/reactHooks/layout/types/index.ts +1 -0
  70. package/reactHooks/layout/useDimensions/useDimensions.ts +7 -2
  71. package/reactHooks/navigation/__mocks__/index.ts +13 -0
  72. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  73. package/reactHooks/navigation/__tests__/index.test.tsx +11 -8
  74. package/reactHooks/navigation/index.ts +60 -67
  75. package/reactHooks/resolvers/useCellResolver.ts +5 -1
  76. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  77. package/reactHooks/screen/index.ts +2 -0
  78. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  79. package/reactHooks/screen/useScreenContext.ts +3 -3
  80. package/reactUtils/index.ts +104 -0
  81. package/screenState/index.ts +0 -8
  82. package/stringUtils/index.ts +5 -0
  83. package/testUtils/getByTestId.ts +14 -0
  84. package/testUtils/index.tsx +24 -22
  85. package/types.ts +4 -0
  86. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  87. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  88. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -0,0 +1,100 @@
1
+ import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
2
+ import { find, last, startsWith, pathOr } from "ramda";
3
+ import {
4
+ QUICK_BRICK_NAVBAR,
5
+ QUICK_BRICK_CONTENT,
6
+ } from "@applicaster/quick-brick-core/const";
7
+
8
+ // run check each 300 ms
9
+ // run this check too often could lead to performance penalty on low-end devices
10
+ const HOW_OFTEN_TO_CHECK_CONDITION = 300; // ms
11
+
12
+ type Props = {
13
+ maxTimeout: number;
14
+ conditionFn: () => boolean;
15
+ };
16
+
17
+ export const waitUntil = ({ maxTimeout, conditionFn }: Props) => {
18
+ let interval;
19
+ let timeout;
20
+
21
+ return new Promise((resolve, reject) => {
22
+ // run interval check
23
+ interval = setInterval(() => {
24
+ if (conditionFn()) {
25
+ clearInterval(interval);
26
+ clearTimeout(timeout);
27
+
28
+ resolve(undefined);
29
+ }
30
+ }, HOW_OFTEN_TO_CHECK_CONDITION);
31
+
32
+ // max timeout when we need to stop interval check
33
+ timeout = setTimeout(() => {
34
+ clearInterval(interval);
35
+ clearTimeout(timeout);
36
+
37
+ const error = Error(
38
+ "Failed to wait satisfy condition. Max timeout is reached."
39
+ );
40
+
41
+ reject(error);
42
+ }, maxTimeout);
43
+ });
44
+ };
45
+
46
+ export const waitForActiveScreen = (currentRoute: string, focusableTree) => {
47
+ const isActiveScreenAvailableToFocus = (): boolean => {
48
+ const routes = focusableTree.root.children;
49
+
50
+ const route = find((route) => route.id === currentRoute, routes);
51
+
52
+ return isNotNil(route);
53
+ };
54
+
55
+ return waitUntil({
56
+ maxTimeout: HOW_OFTEN_TO_CHECK_CONDITION * 10, // ms
57
+ conditionFn: isActiveScreenAvailableToFocus,
58
+ });
59
+ };
60
+
61
+ const getActiveScreenChildren = (focusableTree) => {
62
+ return pathOr([], ["children"], last(focusableTree.root.children));
63
+ };
64
+
65
+ export const getContentNode = (focusableTree) => {
66
+ const content = find(
67
+ (child) =>
68
+ startsWith(QUICK_BRICK_CONTENT, child.id) ||
69
+ startsWith("player", child.id),
70
+ getActiveScreenChildren(focusableTree)
71
+ );
72
+
73
+ return content;
74
+ };
75
+
76
+ export const getNavbarNode = (focusableTree) => {
77
+ const navbar = find(
78
+ (child) => startsWith(QUICK_BRICK_NAVBAR, child.id),
79
+ getActiveScreenChildren(focusableTree)
80
+ );
81
+
82
+ return navbar;
83
+ };
84
+
85
+ export const waitForContent = (focusableTree) => {
86
+ const contentHasAnyChildren = (): boolean => {
87
+ const countOfChildren = pathOr(
88
+ 0,
89
+ ["children", "length"],
90
+ getContentNode(focusableTree)
91
+ );
92
+
93
+ return countOfChildren > 0;
94
+ };
95
+
96
+ return waitUntil({
97
+ maxTimeout: HOW_OFTEN_TO_CHECK_CONDITION * 10, // ms
98
+ conditionFn: contentHasAnyChildren,
99
+ });
100
+ };
package/appUtils/index.js CHANGED
@@ -9,6 +9,8 @@ export { KEYS, ARROW_KEYS } from "./keyCodes/keys";
9
9
 
10
10
  export { playerManager } from "./playerManager";
11
11
 
12
+ export { accessibilityManager } from "./accessibilityManager";
13
+
12
14
  export function deprecationMessage(fn, replacement) {
13
15
  if (__DEV__ && process.env.NODE_ENV !== "test") {
14
16
  console.warn("/** DEPRECATION WARNING **/");
@@ -1,6 +1,7 @@
1
1
  /* global tizen */
2
2
  const isTizen = typeof tizen !== "undefined";
3
3
 
4
+ import { isVizioPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
4
5
  import * as platformKeys from "./keysByPlatform";
5
6
  import { Platform } from "react-native";
6
7
 
@@ -21,6 +22,13 @@ export const ARROW_KEYS = [
21
22
  KEYS.ArrowRight,
22
23
  ];
23
24
 
25
+ /**
26
+ * Platform.OS currently identifies Vizio as LG_TV, therefore we are using isVizioPlatform to identify platform and add keys.
27
+ */
28
+ if (isVizioPlatform()) {
29
+ Object.assign(KEYS, platformKeys.vizio);
30
+ }
31
+
24
32
  /**
25
33
  * In TizenOS we need to register all of the keys that we are going to use.
26
34
  * You need to register using the name Tizen has for the key.
@@ -102,4 +102,14 @@ const tvos = {
102
102
  Menu: { code: "Menu", eventType: "menu" },
103
103
  };
104
104
 
105
- export { lg_tv, samsung_tv, web, tvos, android_tv };
105
+ const vizio = {
106
+ ...samsung_tv,
107
+ Exit: { code: "Exit", keyCode: 27 },
108
+ PageUp: { code: "PageUp", keyCode: 33 },
109
+ PageDown: { code: "PageDown", keyCode: 34 },
110
+ MediaTrackNext: { code: "MediaTrackNext", keyCode: 418 },
111
+ MediaTrackPrevious: { code: "MediaTrackPrevious", keyCode: 419 },
112
+ PrevCh: { code: "PrevCh", keyCode: 500 },
113
+ };
114
+
115
+ export { lg_tv, samsung_tv, web, tvos, android_tv, vizio };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Platforms found in userAgent string, please note that simulators
3
+ * might not have the same agents that the devices have
4
+ */
5
+ export const PLATFORMS = {
6
+ webos: "Web0S",
7
+ tizen: "Tizen",
8
+ samsung: "SMART-TV",
9
+ mac: "Mac",
10
+ win: "Win",
11
+ linux: "Linux",
12
+ iphone: "iPhone",
13
+ android: "Android",
14
+ mobile: "Mobile",
15
+ vizio: "VIZIO",
16
+ smartcast: "SmartCast",
17
+ conjure: "Conjure",
18
+ };
19
+
20
+ /**
21
+ * Keys used to store the platform / device state in the session storage
22
+ */
23
+ export const PLATFORM_KEYS = {
24
+ deviceClosedCaptioningEnabled: "device_closed_captioning_enabled",
25
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./platformUtils";
2
+
3
+ export * from "./const";
@@ -0,0 +1,217 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+
3
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
4
+ import {
5
+ isLgPlatform,
6
+ isSamsungPlatform,
7
+ } from "@applicaster/zapp-react-dom-app/App/Loader/utils/platform";
8
+
9
+ import { PLATFORM_KEYS, PLATFORMS } from "./const";
10
+ import { createLogger, utilsLogger } from "../../logger";
11
+
12
+ declare global {
13
+ interface Window {
14
+ VIZIO?: {
15
+ exitApplication: () => void;
16
+ Chromevox: {
17
+ play: (text: string) => void;
18
+ };
19
+ setClosedCaptionHandler: (
20
+ callback: (isCCEnabled: boolean) => void
21
+ ) => void;
22
+ };
23
+ }
24
+ }
25
+
26
+ const { log_debug } = createLogger({
27
+ category: "General",
28
+ subsystem: "PlatformUtils",
29
+ parent: utilsLogger,
30
+ });
31
+
32
+ export const getUserAgent = () =>
33
+ window?.navigator?.userAgent || global?.navigator?.userAgent;
34
+
35
+ /** VIZIO UTILS */
36
+
37
+ /**
38
+ * Checks if we are on the Vizio platform by using the userAgent string
39
+ *
40
+ * Use this method when you need to identify the platform on runtime
41
+ * before the VIZIO Companion Library has loaded
42
+ */
43
+ export const isVizioPlatform = () => {
44
+ const userAgent = getUserAgent();
45
+
46
+ const isVizioAgent =
47
+ userAgent.includes(PLATFORMS.vizio) ||
48
+ userAgent.includes(PLATFORMS.smartcast) ||
49
+ userAgent.includes(PLATFORMS.conjure);
50
+
51
+ return isVizioAgent;
52
+ };
53
+
54
+ /**
55
+ * Checks if we are on the Vizio platform by checking for the global VIZIO object
56
+ * and the VIZIO Companion Library. This method does not use the userAgent string,
57
+ * because it mainly checks whether we have access to apis, which may not be available yet
58
+ */
59
+ export const hasVizioAPIs = () => {
60
+ const hasAPIs =
61
+ typeof window.VIZIO !== "undefined" &&
62
+ window?.applicaster?.vizioLibraryDidLoad;
63
+
64
+ return hasAPIs;
65
+ };
66
+
67
+ /**
68
+ * Manages device based closed captioning state
69
+ * Returns an observable that emits the current state and updates whenever it changes
70
+ */
71
+ export class ClosedCaptioningManager {
72
+ private ccState$ = new BehaviorSubject<boolean>(false);
73
+ private static ccManagerInstance: ClosedCaptioningManager;
74
+
75
+ private constructor() {
76
+ this.initialize();
77
+ }
78
+
79
+ static getInstance(): ClosedCaptioningManager {
80
+ if (!ClosedCaptioningManager.ccManagerInstance) {
81
+ ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
82
+ }
83
+
84
+ return ClosedCaptioningManager.ccManagerInstance;
85
+ }
86
+
87
+ async initialize() {
88
+ const existingState = await sessionStorage.getItem(
89
+ PLATFORM_KEYS.deviceClosedCaptioningEnabled
90
+ );
91
+
92
+ log_debug("Initializing closed captioning manager", { existingState });
93
+
94
+ if (existingState !== null) {
95
+ this.ccState$.next(existingState === "true" || existingState === true);
96
+ }
97
+
98
+ if (hasVizioAPIs()) {
99
+ window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
100
+ log_debug("CC state changed", { isCCEnabled });
101
+
102
+ sessionStorage.setItem(
103
+ PLATFORM_KEYS.deviceClosedCaptioningEnabled,
104
+ isCCEnabled
105
+ );
106
+
107
+ this.ccState$.next(isCCEnabled);
108
+ });
109
+ }
110
+ }
111
+
112
+ getCurrentState(): boolean {
113
+ return this.ccState$.getValue();
114
+ }
115
+
116
+ getStateAsObservable() {
117
+ return this.ccState$.asObservable();
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Subscribe to closed captioning state changes
123
+ * @returns Observable<boolean>
124
+ * @example
125
+ * const subscription = getClosedCaptionState().subscribe(
126
+ * isEnabled => setClosedCaptionState(isEnabled)
127
+ * );
128
+ * subscription.unsubscribe(), []);
129
+ */
130
+ export const getClosedCaptionState = () => {
131
+ const ccManager = ClosedCaptioningManager.getInstance();
132
+
133
+ return ccManager.getStateAsObservable();
134
+ };
135
+
136
+ /**
137
+ * Manages device based closed captioning state
138
+ * Returns an observable that emits the current state and updates whenever it changes
139
+ */
140
+ export class TTSManager {
141
+ private ttsState$ = new BehaviorSubject<boolean>(false);
142
+ private static ttsManagerInstance: TTSManager;
143
+
144
+ private constructor() {
145
+ this.initialize();
146
+ }
147
+
148
+ static getInstance(): TTSManager {
149
+ if (!TTSManager.ttsManagerInstance) {
150
+ TTSManager.ttsManagerInstance = new TTSManager();
151
+ }
152
+
153
+ return TTSManager.ttsManagerInstance;
154
+ }
155
+
156
+ async initialize() {
157
+ if (!isVizioPlatform()) return;
158
+
159
+ document.addEventListener(
160
+ "VIZIO_TTS_ENABLED",
161
+ () => {
162
+ this.ttsState$.next(true);
163
+ },
164
+ false
165
+ );
166
+
167
+ document.addEventListener(
168
+ "VIZIO_TTS_DISABLED",
169
+ () => {
170
+ this.ttsState$.next(false);
171
+ },
172
+ false
173
+ );
174
+ }
175
+
176
+ getCurrentState(): boolean {
177
+ return this.ttsState$.getValue();
178
+ }
179
+
180
+ getStateAsObservable() {
181
+ return this.ttsState$.asObservable();
182
+ }
183
+
184
+ readText(text: string) {
185
+ if (isSamsungPlatform() && window.speechSynthesis) {
186
+ const utterance = new SpeechSynthesisUtterance(text);
187
+ window.speechSynthesis.speak(utterance);
188
+ }
189
+
190
+ if (isLgPlatform() && window.webOS?.service) {
191
+ try {
192
+ window.webOS.service.request("luna://com.webos.service.tts", {
193
+ method: "speak",
194
+ onFailure(error: any) {
195
+ log_debug("There was a failure setting up webOS TTS service", {
196
+ error,
197
+ });
198
+ },
199
+ onSuccess(response: any) {
200
+ log_debug("webOS TTS service is configured successfully", {
201
+ response,
202
+ });
203
+ },
204
+ parameters: {
205
+ text,
206
+ },
207
+ });
208
+ } catch (error) {
209
+ log_debug("webOS TTS service error", { error });
210
+ }
211
+ }
212
+
213
+ if (!window.VIZIO?.Chromevox) return;
214
+
215
+ window.VIZIO.Chromevox.play(text);
216
+ }
217
+ }
@@ -7,6 +7,7 @@ export enum SharedPlayerCallBacksKeys {
7
7
  OnPlayerPause = "onPlayerPause",
8
8
  OnLoad = "onLoad",
9
9
  OnError = "onError",
10
+ OnVideoError = "onVideoError",
10
11
  OnVideoEnd = "onVideoEnd",
11
12
  OnPlaybackRateChange = "onPlaybackRateChange",
12
13
  OnVideoLoad = "onVideoLoad",
@@ -3,7 +3,6 @@ import * as R from "ramda";
3
3
  import { subscriber } from "../../functionUtils";
4
4
  import { utilsLogger, createLogger } from "../../logger";
5
5
  import { Player } from "./player";
6
- import { AnalyticsTracker } from "../../analyticsUtils/analyticsTracker";
7
6
  import {
8
7
  hasTizenAPIs,
9
8
  subscribeToDeviceNetworkChanges,
@@ -11,6 +10,7 @@ import {
11
10
  } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
12
11
  import { setUserLanguagePreference } from "./userLanguagePreference";
13
12
  import { PlayerRole } from "./conts";
13
+ import { RNPlayerManager } from "./nativePlayerManager";
14
14
 
15
15
  const { log_error, log_debug, log_warning } = createLogger({
16
16
  category: "General",
@@ -36,7 +36,10 @@ export interface PlayerLifecycleListener {
36
36
  }
37
37
 
38
38
  type PlayersMap = {
39
- [id: string]: { player: Player; isInViewport: boolean };
39
+ [id: string]: {
40
+ player: Player;
41
+ isInViewport: boolean;
42
+ };
40
43
  };
41
44
 
42
45
  export class PlayerManager {
@@ -45,7 +48,6 @@ export class PlayerManager {
45
48
  private playersMap: PlayersMap = {};
46
49
  private manager = subscriber();
47
50
  private castingReceiver: Player;
48
- private analyticsTracker: AnalyticsTracker;
49
51
  private lifecycleListeners: PlayerLifecycleListener[] = [];
50
52
 
51
53
  public static getInstance() {
@@ -56,7 +58,7 @@ export class PlayerManager {
56
58
  return PlayerManager.instance;
57
59
  }
58
60
 
59
- public getActivePlayerId = (): String | null => {
61
+ public getActivePlayerId = (): string | null => {
60
62
  return this.activePlayerId;
61
63
  };
62
64
 
@@ -101,7 +103,10 @@ export class PlayerManager {
101
103
  }
102
104
 
103
105
  private addPlayer = (id: string, player: Player) => {
104
- this.playersMap[id] = { player: player, isInViewport: false };
106
+ this.playersMap[id] = {
107
+ player: player,
108
+ isInViewport: false,
109
+ };
105
110
  };
106
111
 
107
112
  public isPlayerRegistered = (id: string) => !!this.playersMap[id];
@@ -164,6 +169,10 @@ export class PlayerManager {
164
169
  this.addPlayer(id, playerController);
165
170
 
166
171
  if (playerController.playerRole === PlayerRole.Primary) {
172
+ if (playerController.playerPluginId !== "QuickBrickPlayerPlugin") {
173
+ RNPlayerManager?.["QuickBrickPlayerPlugin"]?.stopBackgroundPlayback?.();
174
+ }
175
+
167
176
  playerController.addListener({
168
177
  id: this.getPlayerListenerId(id),
169
178
  listener: {
@@ -246,28 +255,6 @@ export class PlayerManager {
246
255
  this.castingReceiver = null;
247
256
  }
248
257
 
249
- /**
250
- * Handles analytic events, generates a new analytics tracker and transmits events
251
- * Passes entry data, and playerState to the tracker for additional context
252
- * The end result is an event formatted and passed to AnalyticsBridge.postEvent
253
- * When we get the synthetic event we need to pull the data in the e object
254
- * e contains the return value from native
255
- */
256
- public handleAnalyticEvent(event, data = {}, entry: ZappEntry) {
257
- const playerState = this.getActivePlayer()?.getState();
258
-
259
- if (!this.analyticsTracker?.handleAnalyticEvent) {
260
- this.analyticsTracker = new AnalyticsTracker(entry);
261
- }
262
-
263
- this.analyticsTracker?.handleAnalyticEvent?.(
264
- event,
265
- data,
266
- entry,
267
- playerState
268
- );
269
- }
270
-
271
258
  /**
272
259
  * Method retrieves the instantiated player instance controller
273
260
  * Instance controller exposes methods like getContentDuration, getContentPosision
@@ -361,9 +348,9 @@ export class PlayerManager {
361
348
  // TODO: Remove
362
349
  if (this.castingReceiver) {
363
350
  this.castingReceiver.rewind(deltaTime);
351
+ } else {
352
+ this.getActivePlayer()?.rewind(deltaTime);
364
353
  }
365
-
366
- this.getActivePlayer()?.rewind(deltaTime);
367
354
  }
368
355
 
369
356
  public forward(deltaTime = null) {
@@ -371,9 +358,9 @@ export class PlayerManager {
371
358
 
372
359
  if (this.castingReceiver) {
373
360
  this.castingReceiver.forward(deltaTime);
361
+ } else {
362
+ this.getActivePlayer()?.forward(deltaTime);
374
363
  }
375
-
376
- this.getActivePlayer()?.forward(deltaTime);
377
364
  }
378
365
 
379
366
  public seeking(time) {
@@ -436,7 +423,7 @@ export class PlayerManager {
436
423
  }
437
424
 
438
425
  // Call method on player just in case
439
- return this.getActivePlayer()?.setLanguage(track);
426
+ return this.getActivePlayer()?.selectTrack(track);
440
427
  }
441
428
 
442
429
  public isRegistered() {
@@ -461,6 +448,7 @@ export class PlayerManager {
461
448
  if (this.castingReceiver) {
462
449
  this.castingReceiver.closeNativePlayer();
463
450
  } else {
451
+ this.getActivePlayer().closeNativePlayer();
464
452
  this.invokeHandler("close");
465
453
  }
466
454
  }
@@ -0,0 +1,12 @@
1
+ import { NativeModules } from "react-native";
2
+ import { isApplePlatform } from "../../reactUtils";
3
+
4
+ export const RNPlayerManager = {
5
+ QuickBrickPlayerPlugin: isApplePlatform()
6
+ ? NativeModules.PlayerModule
7
+ : NativeModules.QuickBrickDefaultPlayerModule,
8
+ KalturaPlayerPlugin: isApplePlatform()
9
+ ? NativeModules.KalturaPlayerModule
10
+ : NativeModules.QBKalturaPlayerModule,
11
+ "quick-brick-player-brightcove": NativeModules.BrightcovePlayerModule,
12
+ };
@@ -359,6 +359,13 @@ export class Player {
359
359
  });
360
360
  };
361
361
 
362
+ onVideoError = (error: Error) => {
363
+ this.invokeListenersUpdate({
364
+ callbackName: SharedPlayerCallBacksKeys.OnVideoError,
365
+ event: error,
366
+ });
367
+ };
368
+
362
369
  onError = (error: Error) => {
363
370
  this.invokeListenersUpdate({
364
371
  callbackName: SharedPlayerCallBacksKeys.OnError,
@@ -650,6 +657,7 @@ export class Player {
650
657
  onPlayerSeekComplete: this.onSeekComplete,
651
658
  onVideoEnd: this.onVideoEnd,
652
659
  onError: this.onError,
660
+ onVideoError: this.onVideoError,
653
661
  onLoad: this.onLoad,
654
662
  onPlayerPause: this.onPlayerPause,
655
663
  onPlayerResume: this.onPlayerResume,
@@ -684,9 +692,6 @@ export class Player {
684
692
  play = () => {};
685
693
  pause = () => {};
686
694
  disableBufferAnimation = (): boolean => true;
687
- setLanguage = (
688
- _selected?: QuickBrickPlayer.TextTrack | QuickBrickPlayer.AudioTrack
689
- ) => {};
690
695
 
691
696
  setPlaybackRate = (_rate) => {};
692
697
  startSleepTimer = (_timestamp) => {};
@@ -727,4 +732,6 @@ export class Player {
727
732
  }
728
733
 
729
734
  public supportsNativeControls = (): boolean => false;
735
+ public supportNativeCast = (): boolean => false;
736
+ public destroy = () => {};
730
737
  }
@@ -0,0 +1,57 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { Player } from "../player";
3
+ import { usePlayer } from "../usePlayer";
4
+ import { useThrottle } from "../../../functionUtils";
5
+
6
+ /**
7
+ *
8
+ * @param listenerId - A unique identifier for the listener.
9
+ * @param playerId - (Optional) The ID of the player to observe.
10
+ * @returns The current playback time in seconds.
11
+ */
12
+ export const usePlayerCurrentTime = (
13
+ listenerId: string,
14
+ playerId?: string
15
+ ): number | null => {
16
+ const [currentTime, setCurrentTime] = useState<number | null>(null);
17
+ const player: Player = usePlayer(playerId);
18
+
19
+ const updateCurrentTime = useCallback(() => {
20
+ if (player) {
21
+ const newCurrentTime = player.getContentPosition();
22
+
23
+ setCurrentTime((prevTime) =>
24
+ prevTime !== newCurrentTime ? newCurrentTime : prevTime
25
+ );
26
+ }
27
+ }, [player]);
28
+
29
+ const { throttledFunction: throttledUpdate, cancel } = useThrottle(
30
+ updateCurrentTime,
31
+ 1000
32
+ );
33
+
34
+ useEffect(() => {
35
+ if (player) {
36
+ throttledUpdate();
37
+
38
+ const listeners = {
39
+ onVideoProgress: throttledUpdate,
40
+ };
41
+
42
+ const id = `${listenerId}_player_current_time`;
43
+
44
+ player.addListener({
45
+ id: id,
46
+ listener: listeners,
47
+ });
48
+
49
+ return () => {
50
+ player.removeListener(id);
51
+ cancel();
52
+ };
53
+ }
54
+ }, [player, listenerId, throttledUpdate, cancel]);
55
+
56
+ return currentTime;
57
+ };