@applicaster/zapp-react-native-utils 12.0.0-rc.9 → 12.0.0-rc.91

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 (109) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +16 -8
  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/__tests__/analyticsManager.test.js +75 -73
  6. package/analyticsUtils/analyticsPlugins.ts +25 -0
  7. package/analyticsUtils/events.ts +12 -0
  8. package/analyticsUtils/helpers/hooks.ts +1 -1
  9. package/analyticsUtils/index.tsx +12 -0
  10. package/appUtils/HooksManager/index.js +3 -1
  11. package/appUtils/accessibilityManager/const.ts +50 -0
  12. package/appUtils/accessibilityManager/hooks.ts +31 -0
  13. package/appUtils/accessibilityManager/index.ts +150 -0
  14. package/appUtils/accessibilityManager/logger.ts +5 -0
  15. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  16. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  17. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  18. package/appUtils/focusManager/index.ts +76 -57
  19. package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -35
  20. package/appUtils/focusManager/utils/index.ts +100 -0
  21. package/appUtils/focusManagerAux/index.ts +76 -0
  22. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  23. package/appUtils/index.js +2 -0
  24. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
  25. package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
  26. package/appUtils/keyCodes/keys.web.js +9 -0
  27. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  28. package/appUtils/platform/const.ts +25 -0
  29. package/appUtils/platform/index.ts +3 -0
  30. package/appUtils/platform/platformUtils.ts +185 -0
  31. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
  32. package/appUtils/playerManager/conts.ts +6 -0
  33. package/appUtils/playerManager/index.ts +11 -5
  34. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  35. package/appUtils/playerManager/player.ts +56 -7
  36. package/appUtils/playerManager/playerFactory.ts +15 -1
  37. package/appUtils/playerManager/playerNative.ts +40 -14
  38. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  39. package/appUtils/playerManager/usePlayerState.tsx +13 -1
  40. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
  41. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  42. package/arrayUtils/index.ts +5 -0
  43. package/booleanUtils/index.ts +4 -4
  44. package/cellUtils/__tests__/cellUtils.test.ts +48 -0
  45. package/cellUtils/__tests__/fixtures.ts +13 -0
  46. package/cellUtils/index.ts +40 -2
  47. package/dateUtils/index.ts +11 -0
  48. package/focusManager/index.ts +1 -1
  49. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
  50. package/functionUtils/__tests__/functionUtils.test.js +244 -248
  51. package/headersUtils/index.ts +1 -0
  52. package/inflatedUrlUtils/index.ts +4 -4
  53. package/keyboardState/index.ts +0 -0
  54. package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
  55. package/localizationUtils/index.ts +13 -19
  56. package/logger/index.ts +1 -1
  57. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  58. package/manifestUtils/defaultManifestConfigurations/player.js +10 -1
  59. package/manifestUtils/index.js +5 -1
  60. package/manifestUtils/secondaryImage/index.js +18 -15
  61. package/modalState/index.ts +57 -0
  62. package/navigationUtils/index.ts +56 -7
  63. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  64. package/numberUtils/index.ts +9 -18
  65. package/package.json +3 -2
  66. package/playerUtils/configurationGenerator.ts +11 -1
  67. package/pluginUtils/index.ts +20 -7
  68. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  69. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  70. package/reactHooks/cell-click/__tests__/index.test.js +16 -3
  71. package/reactHooks/cell-click/index.ts +14 -14
  72. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  73. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  74. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  75. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  76. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  77. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  78. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
  79. package/reactHooks/index.ts +2 -0
  80. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
  81. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  82. package/reactHooks/layout/types/index.ts +2 -0
  83. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
  84. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
  85. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  86. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  87. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  88. package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
  89. package/reactHooks/navigation/index.ts +239 -80
  90. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  91. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  92. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  93. package/reactHooks/screen/index.ts +4 -0
  94. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  95. package/reactHooks/screen/useScreenContext.ts +4 -4
  96. package/reactHooks/screen/useScreenData.ts +1 -1
  97. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  98. package/reactHooks/state/useRivers.ts +3 -1
  99. package/reactHooks/useListenEventBusEvent.ts +1 -4
  100. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
  101. package/reactUtils/index.ts +105 -0
  102. package/riverComponetsMeasurementProvider/index.tsx +2 -2
  103. package/stringUtils/index.ts +5 -0
  104. package/testUtils/getByTestId.ts +14 -0
  105. package/testUtils/index.tsx +38 -23
  106. package/types.ts +4 -0
  107. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  108. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  109. 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,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`keyCode returns an object for a given key event 1`] = `
3
+ exports[`keyCodes keyCode returns an object for a given key event 1`] = `
4
4
  Object {
5
5
  "direction": [Function],
6
6
  "matches": [Function],
@@ -1,3 +1,7 @@
1
+ const { Platform } = require("react-native");
2
+
3
+ Platform.OS = "web";
4
+
1
5
  import { directionHelper } from "../../directionHelper";
2
6
 
3
7
  const globalTizen = {
@@ -6,105 +10,96 @@ const globalTizen = {
6
10
  },
7
11
  };
8
12
 
9
- jest.mock("react-native", () => {
10
- return { Platform: { OS: "web" } };
11
- });
12
-
13
- describe("keyCode", () => {
14
- const { keyCode } = require("../index");
15
- const { KEYS } = require("../keys.web");
16
-
17
- it("returns an object for a given key event", () => {
18
- expect(keyCode(KEYS.Enter)).toMatchSnapshot();
19
- });
20
-
21
- it("has a matcher method for a single key", () => {
22
- expect(keyCode(KEYS.Enter).matches("Enter")).toBeTruthy();
23
- expect(keyCode(KEYS.Enter).matches(KEYS.Enter)).toBeTruthy();
24
- expect(keyCode(KEYS.Back).matches("Enter")).toBeFalsy();
25
- });
26
-
27
- it("has matcher for multiple keys", () => {
28
- expect(
29
- keyCode(KEYS.Enter).matchesAny("Enter", "Back", "ArrowUp")
30
- ).toBeTruthy();
13
+ describe("keyCodes", () => {
14
+ describe("keyCode", () => {
15
+ const { keyCode } = require("..");
16
+ const { KEYS } = require("../keys.web");
31
17
 
32
- expect(
33
- keyCode(KEYS.Enter).matchesAny("Back", "ArrowUp", "ArrowDown")
34
- ).toBeFalsy();
35
- });
18
+ it("returns an object for a given key event", () => {
19
+ expect(keyCode(KEYS.Enter)).toMatchSnapshot();
20
+ });
36
21
 
37
- it("returns the direction if it matches an arrow key", () => {
38
- expect(keyCode(KEYS.Enter).direction()).toBe(null);
22
+ it("has a matcher method for a single key", () => {
23
+ expect(keyCode(KEYS.Enter).matches("Enter")).toBeTruthy();
24
+ expect(keyCode(KEYS.Enter).matches(KEYS.Enter)).toBeTruthy();
25
+ expect(keyCode(KEYS.Back).matches("Enter")).toBeFalsy();
26
+ });
39
27
 
40
- expect(keyCode(KEYS.ArrowDown).direction()).toEqual(
41
- directionHelper(KEYS.ArrowDown)
42
- );
43
- });
28
+ it("has matcher for multiple keys", () => {
29
+ expect(
30
+ keyCode(KEYS.Enter).matchesAny("Enter", "Back", "ArrowUp")
31
+ ).toBeTruthy();
44
32
 
45
- describe("in web env", () => {
46
- it("uses the proper keyCode for the environment", () => {
47
- expect(keyCode({ keyCode: 13 }).matches(KEYS.Enter)).toBeTruthy();
33
+ expect(
34
+ keyCode(KEYS.Enter).matchesAny("Back", "ArrowUp", "ArrowDown")
35
+ ).toBeFalsy();
48
36
  });
49
- });
50
- });
51
37
 
52
- describe("in Tizen Env", () => {
53
- jest.mock("react-native", () => {
54
- return { Platform: { OS: "samsung_tv" } };
55
- });
38
+ it("returns the direction if it matches an arrow key", () => {
39
+ expect(keyCode(KEYS.Enter).direction()).toBe(null);
56
40
 
57
- beforeEach(() => {
58
- global.tizen = globalTizen;
59
- jest.resetModules();
60
- });
41
+ expect(keyCode(KEYS.ArrowDown).direction()).toEqual(
42
+ directionHelper(KEYS.ArrowDown)
43
+ );
44
+ });
61
45
 
62
- afterEach(() => {
63
- global.tizen = undefined;
46
+ describe("in web env", () => {
47
+ it("uses the proper keyCode for the environment", () => {
48
+ expect(keyCode({ keyCode: 13 }).matches(KEYS.Enter)).toBeTruthy();
49
+ });
50
+ });
64
51
  });
65
52
 
66
- it("uses the proper keyCode for the environment", () => {
67
- const { keyCode } = require("../index");
68
- const { KEYS } = require("../keys.web");
53
+ describe("in Tizen Env", () => {
54
+ beforeEach(() => {
55
+ jest.resetModules();
56
+ global.tizen = globalTizen;
57
+ });
69
58
 
70
- expect(globalTizen.tvinputdevice.registerKeyBatch).toHaveBeenCalledWith([
71
- "Back",
72
- "MediaPlay",
73
- "MediaPlayPause",
74
- "MediaPause",
75
- "MediaFastForward",
76
- "MediaRewind",
77
- "MediaStop",
78
- "Exit",
79
- "0",
80
- "1",
81
- "2",
82
- "3",
83
- "4",
84
- "5",
85
- "6",
86
- "7",
87
- "8",
88
- "9",
89
- ]);
90
-
91
- expect(keyCode({ keyCode: 10009 }).matches(KEYS.Back)).toBeTruthy();
92
- });
93
- });
59
+ afterEach(() => {
60
+ global.tizen = undefined;
61
+ });
94
62
 
95
- describe("in WebOS Env", () => {
96
- jest.mock("react-native", () => {
97
- return { Platform: { OS: "lg_tv" } };
63
+ it("uses the proper keyCode for the environment", () => {
64
+ Platform.OS = "samsung_tv";
65
+ const { keyCode } = require("../");
66
+ const { KEYS } = require("../keys.web");
67
+
68
+ expect(globalTizen.tvinputdevice.registerKeyBatch).toHaveBeenCalledWith([
69
+ "MediaPlay",
70
+ "MediaPlayPause",
71
+ "MediaPause",
72
+ "MediaFastForward",
73
+ "MediaRewind",
74
+ "MediaStop",
75
+ "Exit",
76
+ "0",
77
+ "1",
78
+ "2",
79
+ "3",
80
+ "4",
81
+ "5",
82
+ "6",
83
+ "7",
84
+ "8",
85
+ "9",
86
+ ]);
87
+
88
+ expect(keyCode({ keyCode: 10009 }).matches(KEYS.Back)).toBeTruthy();
89
+ });
98
90
  });
99
91
 
100
- beforeEach(() => {
101
- jest.resetModules();
102
- });
92
+ describe("in WebOS Env", () => {
93
+ beforeEach(() => {
94
+ jest.resetModules();
95
+ });
103
96
 
104
- it("uses the proper keyCode for the environment", () => {
105
- const { keyCode } = require("../index");
106
- const { KEYS } = require("../keys.web");
107
- // Back is reserved on LG
108
- expect(keyCode({ keyCode: 417 }).matches(KEYS.Forward)).toBeTruthy();
97
+ it("uses the proper keyCode for the environment", () => {
98
+ Platform.OS = "lg_tv";
99
+ const { keyCode } = require("..");
100
+ const { KEYS } = require("../keys.web");
101
+ // Back is reserved on LG
102
+ expect(keyCode({ keyCode: 417 }).matches(KEYS.Forward)).toBeTruthy();
103
+ });
109
104
  });
110
105
  });
@@ -1,5 +1,7 @@
1
1
  /* global tizen */
2
2
  const isTizen = typeof tizen !== "undefined";
3
+
4
+ import { isVizioPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
3
5
  import * as platformKeys from "./keysByPlatform";
4
6
  import { Platform } from "react-native";
5
7
 
@@ -20,6 +22,13 @@ export const ARROW_KEYS = [
20
22
  KEYS.ArrowRight,
21
23
  ];
22
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
+
23
32
  /**
24
33
  * In TizenOS we need to register all of the keys that we are going to use.
25
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,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
+ }
@@ -41,6 +41,11 @@ export type ChapterMarkerEvent = {
41
41
  actions: ActionChapter[];
42
42
  };
43
43
 
44
+ export type TitleSummaryEvent = {
45
+ title: string | number;
46
+ summary: string | number;
47
+ };
48
+
44
49
  type ChapterMarkersObserverProps = {
45
50
  player: Player;
46
51
  };
@@ -60,6 +65,11 @@ export type PlayNextState = PlayNextConfig & {
60
65
  export class OverlaysObserver {
61
66
  readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
62
67
  private playNextSubject: BehaviorSubject<PlayNextState>;
68
+ private titleSummarySubject: BehaviorSubject<TitleSummaryEvent>;
69
+ private feedUrl: string;
70
+ private reloadData: () => void;
71
+ private updateTitleAndDescription: (data: any) => void;
72
+ private feedDataInterval: any;
63
73
  private releasePlayerObserver?: () => void;
64
74
  readonly entry: ZappEntry;
65
75
  private chapterMarkerEvents: ChapterMarkerEvent[];
@@ -70,14 +80,55 @@ export class OverlaysObserver {
70
80
  constructor({ player }: ChapterMarkersObserverProps) {
71
81
  this.chapterSubject = new BehaviorSubject(null);
72
82
  this.playNextSubject = new BehaviorSubject(null);
83
+
84
+ this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
85
+ title: player.getEntry()?.title || "",
86
+ summary: player.getEntry()?.summary || "",
87
+ });
88
+
73
89
  this.entry = player.getEntry();
74
90
  this.player = player;
75
91
 
76
92
  this.chapterMarkerEvents = this.prepareChapterMarkers();
77
93
  this.releasePlayerObserver = this.subscribeToPlayerEvents();
94
+ this.feedUrl = "";
95
+ this.reloadData = () => {};
96
+ this.updateTitleAndDescription = () => {};
97
+ this.feedDataInterval = null;
78
98
  void this.preparePlayNext();
79
99
  }
80
100
 
101
+ private setupFeedDataInterval(interval: number) {
102
+ if (this.feedUrl && this.reloadData && this.updateTitleAndDescription) {
103
+ this.feedDataInterval = setInterval(() => {
104
+ this.reloadData();
105
+ }, interval * 1000);
106
+ }
107
+ }
108
+
109
+ public clearFeedDataInterval() {
110
+ if (this.feedDataInterval) {
111
+ clearInterval(this.feedDataInterval);
112
+ this.feedDataInterval = null;
113
+ }
114
+ }
115
+
116
+ public setFeedDataHandlers(
117
+ feedUrl: string,
118
+ reloadData: () => void,
119
+ interval: number,
120
+ updateTitleAndDescription: (data: any) => void
121
+ ) {
122
+ this.feedUrl = feedUrl;
123
+ this.reloadData = reloadData;
124
+ this.updateTitleAndDescription = updateTitleAndDescription;
125
+ this.setupFeedDataInterval(interval);
126
+ }
127
+
128
+ public getTitleSummaryObservable(): Observable<TitleSummaryEvent> {
129
+ return this.titleSummarySubject.asObservable().pipe(distinctUntilChanged());
130
+ }
131
+
81
132
  handleUserCancelPlayNext = () => {
82
133
  this.isCanceledByUser = true;
83
134
  this.playNextSubject.next(null);
@@ -281,7 +332,9 @@ export class OverlaysObserver {
281
332
  onPlayerClose = () => {
282
333
  this.chapterSubject.complete();
283
334
  this.playNextSubject.complete();
335
+ this.titleSummarySubject.complete();
284
336
  this.releasePlayerObserver?.();
337
+ this.clearFeedDataInterval();
285
338
  this.releasePlayerObserver = null;
286
339
  };
287
340
 
@@ -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",
@@ -20,6 +21,11 @@ export enum SharedPlayerCallBacksKeys {
20
21
  OnPlayerMute = "onPlayerMute",
21
22
  OnPlayerUnmute = "onPlayerUnmute",
22
23
 
24
+ onVideoFullscreenPlayerDidDismiss = "onVideoFullscreenPlayerDidDismiss",
25
+ onVideoFullscreenPlayerDidPresent = "onVideoFullscreenPlayerDidPresent",
26
+ onVideoFullscreenPlayerWillDismiss = "onVideoFullscreenPlayerWillDismiss",
27
+ onVideoFullscreenPlayerWillPresent = "onVideoFullscreenPlayerWillPresent",
28
+
23
29
  OnAdBegin = "onAdBegin",
24
30
  OnAdBreakBegin = "onAdBreakBegin",
25
31
  OnAdBreakEnd = "onAdBreakEnd",