@applicaster/zapp-react-native-utils 12.0.0-alpha.3977160850 → 12.0.0-alpha.4023252383

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 (101) 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/HooksManager/index.js +3 -1
  11. package/appUtils/accessibilityManager/const.ts +50 -0
  12. package/appUtils/accessibilityManager/hooks.ts +40 -0
  13. package/appUtils/accessibilityManager/index.ts +166 -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/keys.web.js +8 -0
  25. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  26. package/appUtils/platform/const.ts +25 -0
  27. package/appUtils/platform/index.ts +3 -0
  28. package/appUtils/platform/platformUtils.ts +217 -0
  29. package/appUtils/playerManager/conts.ts +6 -0
  30. package/appUtils/playerManager/index.ts +20 -32
  31. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  32. package/appUtils/playerManager/player.ts +44 -3
  33. package/appUtils/playerManager/playerFactory.ts +13 -11
  34. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
  35. package/appUtils/playerManager/playerNative.ts +15 -15
  36. package/appUtils/playerManager/usePlayerControllerSetup.tsx +8 -2
  37. package/appUtils/playerManager/usePlayerState.tsx +19 -34
  38. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  39. package/arrayUtils/index.ts +5 -0
  40. package/booleanUtils/index.ts +4 -4
  41. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  42. package/cellUtils/index.ts +48 -19
  43. package/dateUtils/index.ts +11 -0
  44. package/functionUtils/index.ts +38 -0
  45. package/headersUtils/index.ts +1 -0
  46. package/index.d.ts +15 -0
  47. package/inflatedUrlUtils/index.ts +4 -4
  48. package/keyboardState/index.ts +0 -0
  49. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  50. package/localizationUtils/index.ts +13 -22
  51. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  52. package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
  53. package/manifestUtils/index.js +5 -1
  54. package/manifestUtils/secondaryImage/index.js +18 -15
  55. package/navigationUtils/index.ts +56 -4
  56. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  57. package/numberUtils/__tests__/toNumber.test.ts +2 -2
  58. package/numberUtils/index.ts +9 -18
  59. package/package.json +2 -2
  60. package/playerUtils/configurationGenerator.ts +3 -1
  61. package/playerUtils/imaScriptDom.ts +59 -0
  62. package/pluginUtils/index.ts +9 -0
  63. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  64. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  65. package/reactHooks/cell-click/__tests__/index.test.js +10 -1
  66. package/reactHooks/cell-click/index.ts +12 -12
  67. package/reactHooks/debugging/__tests__/index.test.js +81 -11
  68. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  69. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  70. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  71. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  72. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  73. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  74. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
  75. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  76. package/reactHooks/layout/types/index.ts +2 -0
  77. package/reactHooks/layout/useDimensions/useDimensions.ts +15 -7
  78. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  79. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  80. package/reactHooks/navigation/__tests__/index.test.tsx +26 -8
  81. package/reactHooks/navigation/index.ts +64 -21
  82. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  83. package/reactHooks/resolvers/useCellResolver.ts +5 -1
  84. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  85. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  86. package/reactHooks/screen/index.ts +2 -0
  87. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  88. package/reactHooks/screen/useScreenContext.ts +4 -4
  89. package/reactHooks/screen/useScreenData.ts +1 -1
  90. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  91. package/reactHooks/useListenEventBusEvent.ts +1 -4
  92. package/reactHooks/videoModal/index.ts +0 -3
  93. package/reactUtils/index.ts +104 -0
  94. package/screenState/index.ts +0 -8
  95. package/stringUtils/index.ts +5 -0
  96. package/testUtils/getByTestId.ts +14 -0
  97. package/testUtils/index.tsx +38 -23
  98. package/types.ts +4 -0
  99. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  100. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  101. 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
+ };
@@ -0,0 +1,76 @@
1
+ import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
2
+ import { find, path } from "ramda";
3
+
4
+ import {
5
+ waitForActiveScreen,
6
+ waitForContent,
7
+ getContentNode,
8
+ getNavbarNode,
9
+ } from "./utils";
10
+
11
+ import { coreLogger } from "../../logger";
12
+
13
+ const logger = coreLogger.addSubsystem("focusManagerAux");
14
+
15
+ export async function setFocusOnMenu(currentRoute: string) {
16
+ const { setFocus, focusableTree } = focusManager;
17
+
18
+ try {
19
+ await waitForActiveScreen(currentRoute, focusableTree);
20
+
21
+ const navbar = getNavbarNode(focusableTree);
22
+
23
+ const selectedMenuItemId = find(
24
+ (child) => child.component.props.selected,
25
+ navbar.children
26
+ )?.id;
27
+
28
+ if (selectedMenuItemId) {
29
+ // set focus on selected menu item
30
+ setFocus(selectedMenuItemId);
31
+
32
+ return;
33
+ }
34
+
35
+ const firstMenuItemId = path(["children", 0, "id"], navbar);
36
+
37
+ if (firstMenuItemId) {
38
+ // set focus on first menu item
39
+ setFocus(firstMenuItemId);
40
+ }
41
+ } catch (error) {
42
+ logger.log({
43
+ message: "setFocusOnMenu – failed to put focus on top-menu",
44
+ data: {
45
+ currentRoute,
46
+ error,
47
+ },
48
+ });
49
+ }
50
+ }
51
+
52
+ export async function setFocusOnContent(currentRoute: string) {
53
+ // we need to put focus on content here
54
+ // For doing it we have to wait registration of first focusable node into focusableTree
55
+ // we wait until content node starts having children
56
+
57
+ const { setInitialFocus, focusableTree } = focusManager;
58
+
59
+ try {
60
+ await waitForActiveScreen(currentRoute, focusableTree);
61
+ await waitForContent(focusableTree);
62
+
63
+ const content = getContentNode(focusableTree);
64
+
65
+ const { success } = setInitialFocus(content);
66
+
67
+ if (!success) {
68
+ // we've failed to put initial focus on content, re-run "setFocusOnContent" again as a fallback
69
+ throw Error(
70
+ "we've failed to put initial focus on content, re-run 'setFocusOnContent' again as a fallback"
71
+ );
72
+ }
73
+ } catch (error) {
74
+ setFocusOnContent(currentRoute);
75
+ }
76
+ }
@@ -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",
@@ -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",