@applicaster/zapp-react-native-utils 12.0.0-alpha.4201443043 → 12.0.0-alpha.4220424021

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 (47) hide show
  1. package/analyticsUtils/AnalyticPlayerListener.ts +141 -0
  2. package/analyticsUtils/AnalyticsEvents/index.ts +7 -0
  3. package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
  4. package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
  5. package/analyticsUtils/events.ts +6 -0
  6. package/analyticsUtils/index.tsx +6 -0
  7. package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
  8. package/appUtils/accessibilityManager/const.ts +50 -0
  9. package/appUtils/accessibilityManager/hooks.ts +40 -0
  10. package/appUtils/accessibilityManager/index.ts +166 -0
  11. package/appUtils/accessibilityManager/logger.ts +5 -0
  12. package/appUtils/focusManager/index.ts +0 -1
  13. package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -1
  14. package/appUtils/index.js +2 -0
  15. package/appUtils/keyCodes/keys.web.js +8 -0
  16. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  17. package/appUtils/platform/const.ts +25 -0
  18. package/appUtils/platform/index.ts +3 -0
  19. package/appUtils/platform/platformUtils.ts +185 -0
  20. package/appUtils/playerManager/conts.ts +1 -0
  21. package/appUtils/playerManager/index.ts +20 -32
  22. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  23. package/appUtils/playerManager/player.ts +9 -3
  24. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
  25. package/appUtils/playerManager/playerNative.ts +6 -15
  26. package/appUtils/playerManager/usePlayerControllerSetup.tsx +2 -1
  27. package/appUtils/playerManager/usePlayerState.tsx +19 -34
  28. package/booleanUtils/index.ts +4 -4
  29. package/cellUtils/index.ts +38 -5
  30. package/functionUtils/index.ts +38 -0
  31. package/index.d.ts +15 -0
  32. package/keyboardState/index.ts +0 -0
  33. package/navigationUtils/index.ts +48 -0
  34. package/numberUtils/__tests__/toNumber.test.ts +2 -2
  35. package/package.json +2 -2
  36. package/playerUtils/imaScriptDom.ts +59 -0
  37. package/pluginUtils/index.ts +9 -0
  38. package/reactHooks/debugging/__tests__/index.test.js +81 -11
  39. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  40. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  41. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -0
  42. package/reactHooks/navigation/index.ts +13 -7
  43. package/reactHooks/resolvers/useCellResolver.ts +5 -1
  44. package/reactUtils/index.ts +104 -0
  45. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  46. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  47. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -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,185 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+
3
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
4
+
5
+ import { PLATFORM_KEYS, PLATFORMS } from "./const";
6
+ import { createLogger, utilsLogger } from "../../logger";
7
+
8
+ declare global {
9
+ interface Window {
10
+ VIZIO?: {
11
+ exitApplication: () => void;
12
+ Chromevox: {
13
+ play: (text: string) => void;
14
+ };
15
+ setClosedCaptionHandler: (
16
+ callback: (isCCEnabled: boolean) => void
17
+ ) => void;
18
+ };
19
+ }
20
+ }
21
+
22
+ const { log_debug } = createLogger({
23
+ category: "General",
24
+ subsystem: "PlatformUtils",
25
+ parent: utilsLogger,
26
+ });
27
+
28
+ export const getUserAgent = () =>
29
+ window?.navigator?.userAgent || global?.navigator?.userAgent;
30
+
31
+ /** VIZIO UTILS */
32
+
33
+ /**
34
+ * Checks if we are on the Vizio platform by using the userAgent string
35
+ *
36
+ * Use this method when you need to identify the platform on runtime
37
+ * before the VIZIO Companion Library has loaded
38
+ */
39
+ export const isVizioPlatform = () => {
40
+ const userAgent = getUserAgent();
41
+
42
+ const isVizioAgent =
43
+ userAgent.includes(PLATFORMS.vizio) ||
44
+ userAgent.includes(PLATFORMS.smartcast) ||
45
+ userAgent.includes(PLATFORMS.conjure);
46
+
47
+ return isVizioAgent;
48
+ };
49
+
50
+ /**
51
+ * Checks if we are on the Vizio platform by checking for the global VIZIO object
52
+ * and the VIZIO Companion Library. This method does not use the userAgent string,
53
+ * because it mainly checks whether we have access to apis, which may not be available yet
54
+ */
55
+ export const hasVizioAPIs = () => {
56
+ const hasAPIs =
57
+ typeof window.VIZIO !== "undefined" &&
58
+ window?.applicaster?.vizioLibraryDidLoad;
59
+
60
+ return hasAPIs;
61
+ };
62
+
63
+ /**
64
+ * Manages device based closed captioning state
65
+ * Returns an observable that emits the current state and updates whenever it changes
66
+ */
67
+ export class ClosedCaptioningManager {
68
+ private ccState$ = new BehaviorSubject<boolean>(false);
69
+ private static ccManagerInstance: ClosedCaptioningManager;
70
+
71
+ private constructor() {
72
+ this.initialize();
73
+ }
74
+
75
+ static getInstance(): ClosedCaptioningManager {
76
+ if (!ClosedCaptioningManager.ccManagerInstance) {
77
+ ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
78
+ }
79
+
80
+ return ClosedCaptioningManager.ccManagerInstance;
81
+ }
82
+
83
+ async initialize() {
84
+ const existingState = await sessionStorage.getItem(
85
+ PLATFORM_KEYS.deviceClosedCaptioningEnabled
86
+ );
87
+
88
+ log_debug("Initializing closed captioning manager", { existingState });
89
+
90
+ if (existingState !== null) {
91
+ this.ccState$.next(existingState === "true" || existingState === true);
92
+ }
93
+
94
+ if (hasVizioAPIs()) {
95
+ window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
96
+ log_debug("CC state changed", { isCCEnabled });
97
+
98
+ sessionStorage.setItem(
99
+ PLATFORM_KEYS.deviceClosedCaptioningEnabled,
100
+ isCCEnabled
101
+ );
102
+
103
+ this.ccState$.next(isCCEnabled);
104
+ });
105
+ }
106
+ }
107
+
108
+ getCurrentState(): boolean {
109
+ return this.ccState$.getValue();
110
+ }
111
+
112
+ getStateAsObservable() {
113
+ return this.ccState$.asObservable();
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Subscribe to closed captioning state changes
119
+ * @returns Observable<boolean>
120
+ * @example
121
+ * const subscription = getClosedCaptionState().subscribe(
122
+ * isEnabled => setClosedCaptionState(isEnabled)
123
+ * );
124
+ * subscription.unsubscribe(), []);
125
+ */
126
+ export const getClosedCaptionState = () => {
127
+ const ccManager = ClosedCaptioningManager.getInstance();
128
+
129
+ return ccManager.getStateAsObservable();
130
+ };
131
+
132
+ /**
133
+ * Manages device based closed captioning state
134
+ * Returns an observable that emits the current state and updates whenever it changes
135
+ */
136
+ export class TTSManager {
137
+ private ttsState$ = new BehaviorSubject<boolean>(false);
138
+ private static ttsManagerInstance: TTSManager;
139
+
140
+ private constructor() {
141
+ this.initialize();
142
+ }
143
+
144
+ static getInstance(): TTSManager {
145
+ if (!TTSManager.ttsManagerInstance) {
146
+ TTSManager.ttsManagerInstance = new TTSManager();
147
+ }
148
+
149
+ return TTSManager.ttsManagerInstance;
150
+ }
151
+
152
+ async initialize() {
153
+ if (!isVizioPlatform()) return;
154
+
155
+ document.addEventListener(
156
+ "VIZIO_TTS_ENABLED",
157
+ () => {
158
+ this.ttsState$.next(true);
159
+ },
160
+ false
161
+ );
162
+
163
+ document.addEventListener(
164
+ "VIZIO_TTS_DISABLED",
165
+ () => {
166
+ this.ttsState$.next(false);
167
+ },
168
+ false
169
+ );
170
+ }
171
+
172
+ getCurrentState(): boolean {
173
+ return this.ttsState$.getValue();
174
+ }
175
+
176
+ getStateAsObservable() {
177
+ return this.ttsState$.asObservable();
178
+ }
179
+
180
+ readText(text: string) {
181
+ if (!window.VIZIO?.Chromevox) return;
182
+
183
+ window.VIZIO.Chromevox.play(text);
184
+ }
185
+ }
@@ -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) => {};
@@ -728,4 +733,5 @@ export class Player {
728
733
 
729
734
  public supportsNativeControls = (): boolean => false;
730
735
  public supportNativeCast = (): boolean => false;
736
+ public destroy = () => {};
731
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
+ };
@@ -2,19 +2,10 @@ import * as R from "ramda";
2
2
  import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
3
3
  import { createLogger, utilsLogger } from "../../logger";
4
4
  import { Player } from "./player";
5
- import { findNodeHandle, NativeModules } from "react-native";
6
- import { isApplePlatform } from "../../reactUtils";
5
+ import { findNodeHandle } from "react-native";
7
6
  import { PlayerRole } from "./conts";
8
7
  import { toBooleanWithDefaultFalse } from "../../booleanUtils";
9
-
10
- const RNPlayerManager = {
11
- QuickBrickPlayerPlugin: isApplePlatform()
12
- ? NativeModules.PlayerModule
13
- : NativeModules.QuickBrickDefaultPlayerModule,
14
- KalturaPlayerPlugin: isApplePlatform()
15
- ? NativeModules.KalturaPlayerModule
16
- : NativeModules.QBKalturaPlayerModule,
17
- };
8
+ import { RNPlayerManager } from "./nativePlayerManager";
18
9
 
19
10
  const logger = createLogger({
20
11
  category: "PlayerNativeController",
@@ -70,7 +61,7 @@ export class PlayerNative extends Player {
70
61
  currentPlayerComponent = (): ReactComponent<PlayerProps> =>
71
62
  this.playerComponent?.current;
72
63
 
73
- getState = () => this.currentPlayerComponent()?.["getState"]?.() ?? {};
64
+ getState = () => this.playerState;
74
65
 
75
66
  // TODO: Try to add module interface
76
67
  invokeNativeFunction = (funcName: string, ...params: any[]): boolean => {
@@ -111,7 +102,7 @@ export class PlayerNative extends Player {
111
102
  return;
112
103
  }
113
104
 
114
- const newPosition = R.clamp(0, position, this.playerState.seekableDuration);
105
+ const newPosition = R.clamp(0, this.playerState.seekableDuration, position);
115
106
 
116
107
  if (
117
108
  !this.invokeNativeFunction(
@@ -197,10 +188,10 @@ export class PlayerNative extends Player {
197
188
 
198
189
  disableBufferAnimation = (): boolean => false;
199
190
 
200
- setLanguage = (
191
+ selectTrack = (
201
192
  selected: QuickBrickPlayer.TextTrack | QuickBrickPlayer.AudioTrack
202
193
  ) => {
203
- this.currentPlayerComponent()?.["setLanguage"]?.(selected);
194
+ this.currentPlayerComponent()?.["selectTrack"]?.(selected);
204
195
  };
205
196
 
206
197
  setPlaybackRate = (rate: number) => {
@@ -50,7 +50,7 @@ export const usePlayerControllerSetup = ({
50
50
  });
51
51
 
52
52
  setPlayerController(newPlayerController);
53
- }, [playerId, entry?.id]);
53
+ }, [playerId, entry?.id, ref.current]);
54
54
 
55
55
  React.useEffect(() => {
56
56
  if (!playerController) {
@@ -72,6 +72,7 @@ export const usePlayerControllerSetup = ({
72
72
 
73
73
  return () => {
74
74
  playerManager.unregisterPlayer(playerId);
75
+ playerController.destroy?.();
75
76
  };
76
77
  }, [playerId, playerController]);
77
78
 
@@ -16,24 +16,28 @@ export const usePlayerState = (
16
16
  listenerId: string,
17
17
  playerId?: string
18
18
  ): PlayerState => {
19
- const [currentTime, setCurrentTime] = React.useState<number>(null);
20
- const [duration, setDuration] = React.useState<number>(null);
21
- const [seekableDuration, setSeekableDuration] = React.useState<number>(null);
22
- const [isLive, setIsLive] = React.useState<boolean>(null);
23
- const [isBuffering, setIsBuffering] = React.useState<boolean>(false);
24
- const [isReadyToPlay, setIsReadyToPlay] = React.useState<boolean>(false);
25
- const [isPaused, setIsPaused] = React.useState<boolean>(false);
19
+ const [state, setState] = React.useState<PlayerState>({
20
+ currentTime: null,
21
+ duration: null,
22
+ seekableDuration: null,
23
+ isLive: null,
24
+ isPaused: null,
25
+ isBuffering: false,
26
+ isReadyToPlay: false,
27
+ });
26
28
 
27
29
  const player: Player = usePlayer(playerId);
28
30
 
29
31
  const onPlayerChangeState = React.useCallback(() => {
30
- setIsBuffering(player.isBuffering());
31
- setIsReadyToPlay(player.isReadyToPlay);
32
- setCurrentTime(player.getContentPosition());
33
- setDuration(player.getDuration());
34
- setSeekableDuration(player.getSeekableDuration());
35
- setIsLive(player.isLive());
36
- setIsPaused(player.isPaused());
32
+ setState({
33
+ currentTime: player.getContentPosition(),
34
+ duration: player.getDuration(),
35
+ seekableDuration: player.getSeekableDuration(),
36
+ isLive: player.isLive(),
37
+ isPaused: player.isPaused(),
38
+ isBuffering: player.isBuffering(),
39
+ isReadyToPlay: player.isReadyToPlay(),
40
+ });
37
41
  }, [player]);
38
42
 
39
43
  React.useEffect(() => {
@@ -55,24 +59,5 @@ export const usePlayerState = (
55
59
  }
56
60
  }, [player]);
57
61
 
58
- return React.useMemo(
59
- () => ({
60
- currentTime,
61
- duration,
62
- seekableDuration,
63
- isLive,
64
- isPaused,
65
- isBuffering,
66
- isReadyToPlay,
67
- }),
68
- [
69
- currentTime,
70
- duration,
71
- seekableDuration,
72
- isLive,
73
- isPaused,
74
- isBuffering,
75
- isReadyToPlay,
76
- ]
77
- );
62
+ return state;
78
63
  };
@@ -1,7 +1,7 @@
1
- import * as R from "ramda";
1
+ import { is, toLower } from "ramda";
2
2
 
3
3
  export const toBoolean = (value: any): boolean | undefined => {
4
- if (R.is(Boolean, value)) {
4
+ if (is(Boolean, value)) {
5
5
  return value;
6
6
  }
7
7
 
@@ -17,12 +17,12 @@ export const toBooleanWithDefaultTrue = toBooleanWithDefault(true);
17
17
 
18
18
  export const toBooleanWithDefaultFalse = toBooleanWithDefault(false);
19
19
 
20
- export const isTrue = (value: any): boolean => {
20
+ export const isTrue = (value: unknown): boolean => {
21
21
  if (value === true) {
22
22
  return true;
23
23
  }
24
24
 
25
- if (R.is(String, value) && value.toLowerCase() === "true") {
25
+ if (is(String, value) && toLower(value) === "true") {
26
26
  return true;
27
27
  }
28
28