@applicaster/zapp-react-native-utils 15.0.0-alpha.1692821627 → 15.0.0-alpha.1966607451

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 (65) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +3 -6
  2. package/actionsExecutor/feedDecorator.ts +6 -6
  3. package/adsUtils/index.ts +2 -2
  4. package/analyticsUtils/README.md +1 -1
  5. package/appUtils/HooksManager/index.ts +10 -10
  6. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  7. package/appUtils/accessibilityManager/const.ts +4 -0
  8. package/appUtils/accessibilityManager/hooks.ts +20 -13
  9. package/appUtils/accessibilityManager/index.ts +28 -1
  10. package/appUtils/accessibilityManager/utils.ts +59 -8
  11. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
  12. package/appUtils/focusManager/index.ios.ts +25 -2
  13. package/appUtils/focusManagerAux/utils/index.ts +19 -1
  14. package/appUtils/focusManagerAux/utils/utils.ios.ts +177 -0
  15. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  16. package/appUtils/orientationHelper.ts +2 -4
  17. package/appUtils/platform/platformUtils.ts +117 -18
  18. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  19. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  20. package/appUtils/playerManager/player.ts +4 -0
  21. package/appUtils/playerManager/playerNative.ts +29 -16
  22. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  23. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  24. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  25. package/arrayUtils/index.ts +5 -0
  26. package/cellUtils/index.ts +32 -0
  27. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  28. package/focusManager/aux/index.ts +1 -1
  29. package/manifestUtils/defaultManifestConfigurations/player.js +87 -18
  30. package/manifestUtils/keys.js +21 -0
  31. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  32. package/manifestUtils/tvAction/container/index.js +1 -1
  33. package/package.json +2 -2
  34. package/playerUtils/usePlayerTTS.ts +8 -3
  35. package/pluginUtils/index.ts +4 -0
  36. package/reactHooks/advertising/index.ts +2 -2
  37. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  38. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  39. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +3 -0
  40. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  41. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  42. package/reactHooks/feed/useInflatedUrl.ts +43 -17
  43. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  44. package/reactHooks/layout/index.ts +1 -1
  45. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  46. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  47. package/reactHooks/navigation/index.ts +7 -6
  48. package/reactHooks/navigation/useRoute.ts +8 -6
  49. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  50. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  51. package/reactHooks/resolvers/useComponentResolver.ts +8 -2
  52. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +10 -2
  53. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  54. package/reactHooks/state/useRivers.ts +1 -1
  55. package/reactHooks/usePluginConfiguration.ts +2 -2
  56. package/testUtils/index.tsx +29 -20
  57. package/utils/__tests__/mapAccum.test.ts +73 -0
  58. package/utils/__tests__/selectors.test.ts +124 -0
  59. package/utils/index.ts +15 -0
  60. package/utils/mapAccum.ts +23 -0
  61. package/utils/path.ts +6 -3
  62. package/utils/pathOr.ts +5 -1
  63. package/utils/selectors.ts +46 -0
  64. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  65. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
@@ -1,24 +1,75 @@
1
+ import { createLogger } from "../../logger";
2
+
3
+ const { log_error } = createLogger({
4
+ category: "AccessibilityManager",
5
+ subsystem: "AppUtils",
6
+ });
7
+
1
8
  /**
2
9
  * Calculates the reading time for a given text based on word count
3
- * @param text - The text to calculate the reading time for
4
- * @param wordsPerMinute - Words per minute reading speed (default: 160)
10
+ * @param text - The text to calculate the reading time for (string or number)
11
+ * @param wordsPerMinute - Words per minute reading speed (default: 140)
5
12
  * @param minimumPause - Minimum pause time in milliseconds (default: 500)
6
13
  * @param announcementDelay - Additional delay for announcement in milliseconds (default: 700)
7
14
  * @returns The reading time in milliseconds
8
15
  */
9
16
  export function calculateReadingTime(
10
- text: string,
17
+ text: string | number,
11
18
  wordsPerMinute: number = 140,
12
19
  minimumPause: number = 500,
13
20
  announcementDelay: number = 700
14
21
  ): number {
15
- const words = text
16
- .trim()
22
+ if (typeof text !== "string" && typeof text !== "number") {
23
+ log_error(
24
+ `Invalid text input for reading time calculation got: ${
25
+ typeof text === "symbol" ? String(text) : text
26
+ }`
27
+ );
28
+
29
+ return 0;
30
+ }
31
+
32
+ const trimmed = typeof text === "number" ? String(text) : text.trim();
33
+
34
+ if (!trimmed) {
35
+ return 0;
36
+ }
37
+
38
+ const words = trimmed
17
39
  .split(/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)|[^\w\s]+|\s+/)
18
40
  .filter(Boolean).length;
19
41
 
20
- return (
21
- Math.max(minimumPause, (words / wordsPerMinute) * 60 * 1000) +
22
- announcementDelay
42
+ // Count spaces - multiple consecutive spaces add extra pause time
43
+ const spaceMatches: string[] = trimmed.match(/\s+/g) || [];
44
+
45
+ const totalSpaces = spaceMatches.reduce(
46
+ (sum: number, match: string) => sum + match.length,
47
+ 0
23
48
  );
49
+
50
+ const extraSpaces = Math.max(0, totalSpaces - (words - 1)); // words-1 is normal spacing
51
+
52
+ // Heuristic: punctuation increases TTS duration beyond word-based WPM.
53
+ // Commas typically introduce short pauses, sentence terminators longer ones.
54
+ const commaCount = (trimmed.match(/,/g) || []).length;
55
+ const semicolonCount = (trimmed.match(/;/g) || []).length;
56
+ const colonCount = (trimmed.match(/:/g) || []).length;
57
+ const dashCount = (trimmed.match(/\u2013|\u2014|-/g) || []).length; // – — -
58
+ const sentenceEndCount = (trimmed.match(/[.!?](?!\d)/g) || []).length;
59
+
60
+ const commaPauseMs = 220; // short prosody pause for ","
61
+ const midPauseMs = 260; // for ";", ":", dashes
62
+ const sentenceEndPauseMs = 420; // for ".", "!", "?"
63
+ const extraSpacePauseMs = 50; // per extra space beyond normal spacing
64
+
65
+ const punctuationPause =
66
+ commaCount * commaPauseMs +
67
+ (semicolonCount + colonCount + dashCount) * midPauseMs +
68
+ sentenceEndCount * sentenceEndPauseMs +
69
+ extraSpaces * extraSpacePauseMs;
70
+
71
+ const baseByWordsMs = (words / wordsPerMinute) * 60 * 1000;
72
+ const estimatedMs = Math.max(minimumPause, baseByWordsMs + punctuationPause);
73
+
74
+ return estimatedMs + announcementDelay;
24
75
  }
@@ -69,6 +69,7 @@ exports[`focusManagerIOS should be defined 1`] = `
69
69
  "getGroupRootById": [Function],
70
70
  "getPreferredFocusChild": [Function],
71
71
  "invokeHandler": [Function],
72
+ "isChildOf": [Function],
72
73
  "isFocusOn": [Function],
73
74
  "isGroupItemFocused": [Function],
74
75
  "moveFocus": [Function],
@@ -1,12 +1,20 @@
1
1
  import { NativeModules } from "react-native";
2
2
  import * as R from "ramda";
3
3
 
4
- import { isCurrentFocusOn } from "../focusManagerAux/utils";
4
+ import {
5
+ isCurrentFocusOn,
6
+ isChildOf as isChildOfUtils,
7
+ } from "../focusManagerAux/utils";
5
8
  import { Tree } from "./treeDataStructure/Tree";
6
9
  import { findFocusableNode } from "./treeDataStructure/Utils";
7
10
  import { subscriber } from "../../functionUtils";
8
11
  import { findChild } from "./utils";
9
12
 
13
+ import {
14
+ emitRegistered,
15
+ emitUnregistered,
16
+ } from "../focusManagerAux/utils/utils.ios";
17
+
10
18
  const { FocusableManagerModule } = NativeModules;
11
19
 
12
20
  /**
@@ -180,10 +188,20 @@ export const focusManager = (function () {
180
188
  function register({ id, component }) {
181
189
  const { isGroup = false } = component;
182
190
 
183
- return isGroup ? registerGroup(id, component) : registerItem(id, component);
191
+ if (isGroup) {
192
+ registerGroup(id, component);
193
+ } else {
194
+ registerItem(id, component);
195
+ }
196
+
197
+ const groupId = component?.props?.groupId;
198
+
199
+ emitRegistered({ id, groupId, isGroup });
184
200
  }
185
201
 
186
202
  function unregister(id, { group = false } = {}) {
203
+ emitUnregistered(id);
204
+
187
205
  group ? unregisterGroup(id) : unregisterItem(id);
188
206
  }
189
207
 
@@ -400,6 +418,10 @@ export const focusManager = (function () {
400
418
  return id && isCurrentFocusOn(id, currentFocusNode);
401
419
  }
402
420
 
421
+ function isChildOf(childId, parentId): boolean {
422
+ return isChildOfUtils(focusableTree, childId, parentId);
423
+ }
424
+
403
425
  return {
404
426
  on,
405
427
  invokeHandler,
@@ -422,5 +444,6 @@ export const focusManager = (function () {
422
444
  isGroupItemFocused,
423
445
  getPreferredFocusChild,
424
446
  isFocusOn,
447
+ isChildOf,
425
448
  };
426
449
  })();
@@ -102,7 +102,7 @@ export const getNavbarNode = (focusableTree) => {
102
102
 
103
103
  export const waitForContent = (focusableTree) => {
104
104
  const contentHasAnyChildren = (): boolean => {
105
- const countOfChildren = pathOr(
105
+ const countOfChildren = pathOr<number>(
106
106
  0,
107
107
  ["children", "length"],
108
108
  getContentNode(focusableTree)
@@ -190,3 +190,21 @@ export const isCurrentFocusOn = (id, node) => {
190
190
 
191
191
  return isCurrentFocusOn(id, node.parent);
192
192
  };
193
+
194
+ export const isChildOf = (focusableTree, childId, parentId) => {
195
+ if (isNil(childId) || isNil(parentId)) {
196
+ return false;
197
+ }
198
+
199
+ const childNode = focusableTree.findInTree(childId);
200
+
201
+ if (isNil(childNode)) {
202
+ return false;
203
+ }
204
+
205
+ if (childNode.parent?.id === parentId) {
206
+ return true;
207
+ }
208
+
209
+ return isChildOf(focusableTree, childNode.parent?.id, parentId);
210
+ };
@@ -0,0 +1,177 @@
1
+ import { ReplaySubject, Subject } from "rxjs";
2
+ import { filter, switchMap, take, map } from "rxjs/operators";
3
+ import { BUTTON_PREFIX } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/DefaultComponents/tv/TvActionButtons/const";
4
+ import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager/index.ios";
5
+
6
+ type FocusableID = string;
7
+ type RegistrationEvent = {
8
+ id: FocusableID;
9
+ registered: boolean;
10
+ };
11
+
12
+ let focusableViewRegistrationSubject$ = new Subject<{
13
+ id: FocusableID;
14
+ groupId: FocusableID;
15
+ }>();
16
+
17
+ let focusableGroupRegistrationSubject$ = new ReplaySubject<{
18
+ id: FocusableID;
19
+ }>();
20
+
21
+ let focusableNativeViewRegistrationSubject$ = new Subject<{
22
+ id: FocusableID;
23
+ groupId: FocusableID;
24
+ }>();
25
+
26
+ let focusableNativeGroupRegistrationSubject$ = new ReplaySubject<{
27
+ id: FocusableID;
28
+ groupId: FocusableID;
29
+ }>();
30
+
31
+ const isFocusableButton = (id: Option<FocusableID>): boolean =>
32
+ id && id.includes?.(BUTTON_PREFIX);
33
+
34
+ const registeredSubject$ = new ReplaySubject<RegistrationEvent>(1);
35
+
36
+ export const focusableButtonsRegistration$ = (focusableGroupId: string) =>
37
+ registeredSubject$.pipe(
38
+ filter(
39
+ (value) =>
40
+ value.registered && focusManager.isChildOf(value.id, focusableGroupId)
41
+ )
42
+ );
43
+
44
+ export const resetFocusableRegistration = () => {
45
+ // complete the old subject so subscribers are notified and resources are freed
46
+ if (!focusableViewRegistrationSubject$.closed) {
47
+ focusableViewRegistrationSubject$.complete();
48
+ }
49
+
50
+ if (!focusableGroupRegistrationSubject$.closed) {
51
+ focusableGroupRegistrationSubject$.complete();
52
+ }
53
+
54
+ if (!focusableNativeViewRegistrationSubject$.closed) {
55
+ focusableNativeViewRegistrationSubject$.complete();
56
+ }
57
+
58
+ if (!focusableNativeGroupRegistrationSubject$.closed) {
59
+ focusableNativeGroupRegistrationSubject$.complete();
60
+ }
61
+
62
+ focusableViewRegistrationSubject$ = new Subject<{
63
+ id: FocusableID;
64
+ groupId: FocusableID;
65
+ }>();
66
+
67
+ focusableGroupRegistrationSubject$ = new ReplaySubject<{
68
+ id: FocusableID;
69
+ }>();
70
+
71
+ focusableNativeViewRegistrationSubject$ = new Subject<{
72
+ id: FocusableID;
73
+ groupId: FocusableID;
74
+ }>();
75
+
76
+ focusableNativeGroupRegistrationSubject$ = new ReplaySubject<{
77
+ id: FocusableID;
78
+ groupId: FocusableID;
79
+ }>();
80
+ };
81
+
82
+ const focusableNativeViewRegistration = ({ focusableView, focusableGroup }) => {
83
+ return focusableNativeViewRegistrationSubject$.pipe(
84
+ filter(
85
+ (focusableNativeView) => focusableNativeView.id === focusableView.id
86
+ ),
87
+ take(1),
88
+ switchMap((focusableNativeView) =>
89
+ // start waiting registration of its parent FocusableNativeGroup
90
+ focusableNativeGroupRegistrationSubject$.pipe(
91
+ filter(
92
+ (focusableNativeGroup) =>
93
+ focusableNativeGroup.id === focusableNativeView.groupId
94
+ ),
95
+ take(1),
96
+ map((focusableNativeGroup) => ({
97
+ focusableNativeGroup,
98
+ focusableNativeView,
99
+ focusableView,
100
+ focusableGroup,
101
+ }))
102
+ )
103
+ )
104
+ );
105
+ };
106
+
107
+ export const firstFocusableViewRegistrationFactory = () =>
108
+ focusableViewRegistrationSubject$.pipe(
109
+ take(1), // we care about only first FocusableView registration
110
+ switchMap((focusableView) =>
111
+ // start waiting registration of its parent FocusableGroup
112
+ focusableGroupRegistrationSubject$.pipe(
113
+ filter((focusableGroup) => focusableGroup.id === focusableView.groupId),
114
+ take(1),
115
+ map((focusableGroup) => ({
116
+ focusableView,
117
+ focusableGroup,
118
+ }))
119
+ )
120
+ ),
121
+ // start waiting registration for FocusableNativeView and its parent FocusableNativeGroup
122
+ switchMap(({ focusableView, focusableGroup }) =>
123
+ focusableNativeViewRegistration({
124
+ focusableView,
125
+ focusableGroup,
126
+ })
127
+ )
128
+ );
129
+
130
+ // registration on RN level(into RN focusManager)
131
+ export const emitRegistered = ({
132
+ id,
133
+ groupId,
134
+ isGroup,
135
+ }: {
136
+ id: Option<FocusableID>;
137
+ groupId: Option<FocusableID>;
138
+ isGroup: boolean;
139
+ }): void => {
140
+ if (isFocusableButton(id)) {
141
+ registeredSubject$.next({ id, registered: true });
142
+ }
143
+
144
+ if (isGroup && id) {
145
+ focusableGroupRegistrationSubject$.next({ id });
146
+ }
147
+
148
+ if (!isGroup && id && groupId) {
149
+ focusableViewRegistrationSubject$.next({ id, groupId });
150
+ }
151
+ };
152
+
153
+ // unregistration on RN level(into RN focusManager)
154
+ export const emitUnregistered = (id: Option<FocusableID>): void => {
155
+ if (isFocusableButton(id)) {
156
+ registeredSubject$.next({ id, registered: false });
157
+ }
158
+ };
159
+
160
+ // registration focusableNativeView and focusableNativeGroup
161
+ export const emitNativeRegistered = ({
162
+ id,
163
+ groupId,
164
+ isGroup,
165
+ }: {
166
+ id: Option<FocusableID>;
167
+ groupId: Option<FocusableID>;
168
+ isGroup: boolean;
169
+ }): void => {
170
+ if (!isGroup && id && groupId) {
171
+ focusableNativeViewRegistrationSubject$.next({ id, groupId });
172
+ }
173
+
174
+ if (isGroup && id && groupId) {
175
+ focusableNativeGroupRegistrationSubject$.next({ id, groupId });
176
+ }
177
+ };
@@ -10,10 +10,7 @@ import { Platform } from "react-native";
10
10
  * platformKeys[Platform.OS] should only include keys
11
11
  * that are unique to that platform, i.e. Exit: { keyCode: 10182 }
12
12
  */
13
- export const KEYS = Object.assign(
14
- platformKeys["web"],
15
- platformKeys[Platform.OS]
16
- );
13
+ export const KEYS = Object.assign(platformKeys.web, platformKeys[Platform.OS]);
17
14
 
18
15
  export const ARROW_KEYS = [
19
16
  KEYS.ArrowUp,
@@ -1,5 +1,5 @@
1
1
  import * as ReactNative from "react-native";
2
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
2
+ import { useAppData } from "@applicaster/zapp-react-native-redux/hooks";
3
3
 
4
4
  import { isTV, platformSelect } from "../reactUtils";
5
5
  import { useIsTablet } from "../reactHooks";
@@ -184,9 +184,7 @@ export const getScreenOrientation = ({
184
184
 
185
185
  export const useGetScreenOrientation = (screenData) => {
186
186
  const isTablet = useIsTablet();
187
-
188
- const { appData } = usePickFromState(["appData"]);
189
- const isTabletPortrait = appData?.isTabletPortrait;
187
+ const { isTabletPortrait } = useAppData();
190
188
 
191
189
  return getScreenOrientation({
192
190
  screenData,
@@ -79,7 +79,7 @@ export class ClosedCaptioningManager {
79
79
  private constructor() {
80
80
  this.initialize();
81
81
 
82
- window["vizioDebug"] = {
82
+ window.vizioDebug = {
83
83
  setCCEnabled: (isCCEnabled: boolean) => {
84
84
  this.ccState$.next(isCCEnabled);
85
85
  },
@@ -170,7 +170,9 @@ export const getClosedCaptionState = () => {
170
170
  */
171
171
  export class TTSManager {
172
172
  private ttsState$ = new BehaviorSubject<boolean>(false);
173
+ private screenReaderEnabled$ = new BehaviorSubject<boolean>(false);
173
174
  private static ttsManagerInstance: TTSManager;
175
+ private samsungListenerId: number | null = null;
174
176
 
175
177
  private constructor() {
176
178
  this.initialize();
@@ -185,23 +187,116 @@ export class TTSManager {
185
187
  }
186
188
 
187
189
  async initialize() {
188
- if (!isVizioPlatform()) return;
190
+ if (isVizioPlatform()) {
191
+ document.addEventListener(
192
+ "VIZIO_TTS_ENABLED",
193
+ () => {
194
+ log_debug("Vizio screen reader enabled");
195
+ this.screenReaderEnabled$.next(true);
196
+ },
197
+ false
198
+ );
189
199
 
190
- document.addEventListener(
191
- "VIZIO_TTS_ENABLED",
192
- () => {
193
- this.ttsState$.next(true);
194
- },
195
- false
196
- );
200
+ document.addEventListener(
201
+ "VIZIO_TTS_DISABLED",
202
+ () => {
203
+ log_debug("Vizio screen reader disabled");
204
+ this.screenReaderEnabled$.next(false);
205
+ },
206
+ false
207
+ );
208
+ }
197
209
 
198
- document.addEventListener(
199
- "VIZIO_TTS_DISABLED",
200
- () => {
201
- this.ttsState$.next(false);
202
- },
203
- false
204
- );
210
+ if (isLgPlatform() && window.webOS?.service) {
211
+ try {
212
+ // https://webostv.developer.lge.com/develop/references/settings-service
213
+ window.webOS.service.request("luna://com.webos.settingsservice", {
214
+ method: "getSystemSettings",
215
+ parameters: {
216
+ category: "option",
217
+ keys: ["audioGuidance"],
218
+ subscribe: true, // Request a subscription to changes
219
+ },
220
+ onSuccess: (response: any) => {
221
+ const isEnabled = response?.settings?.audioGuidance === "on";
222
+
223
+ log_debug("LG Audio Guidance status changed", {
224
+ isEnabled,
225
+ response,
226
+ });
227
+
228
+ this.screenReaderEnabled$.next(isEnabled);
229
+ },
230
+ onFailure: (error: any) => {
231
+ log_debug("webOS settings subscription failed", { error });
232
+ this.screenReaderEnabled$.next(false);
233
+ },
234
+ });
235
+ } catch (error) {
236
+ log_debug("webOS settings service request error", { error });
237
+ // Fallback to false if the service is not available
238
+ this.screenReaderEnabled$.next(false);
239
+ }
240
+ }
241
+
242
+ if (isSamsungPlatform() && typeof window.webapis !== "undefined") {
243
+ try {
244
+ if (
245
+ window.webapis?.tvinfo &&
246
+ typeof window.webapis.tvinfo.getMenuValue === "function" &&
247
+ typeof window.webapis.tvinfo.addCaptionChangeListener === "function"
248
+ ) {
249
+ // Get initial Voice Guide status
250
+ const initialStatus = window.webapis.tvinfo.getMenuValue(
251
+ window.webapis.tvinfo.TvInfoMenuKey.VOICE_GUIDE_KEY
252
+ );
253
+
254
+ const isEnabled =
255
+ initialStatus === window.webapis.tvinfo.TvInfoMenuValue.ON;
256
+
257
+ log_debug("Samsung Voice Guide initial status", {
258
+ isEnabled,
259
+ initialStatus,
260
+ });
261
+
262
+ this.screenReaderEnabled$.next(isEnabled);
263
+
264
+ // Listen for Voice Guide status changes
265
+ const onChange = () => {
266
+ const currentStatus = window.webapis.tvinfo.getMenuValue(
267
+ window.webapis.tvinfo.TvInfoMenuKey.VOICE_GUIDE_KEY
268
+ );
269
+
270
+ const enabled =
271
+ currentStatus === window.webapis.tvinfo.TvInfoMenuValue.ON;
272
+
273
+ log_debug("Samsung Voice Guide status changed", {
274
+ enabled,
275
+ currentStatus,
276
+ });
277
+
278
+ this.screenReaderEnabled$.next(enabled);
279
+ };
280
+
281
+ this.samsungListenerId =
282
+ window.webapis.tvinfo.addCaptionChangeListener(
283
+ window.webapis.tvinfo.TvInfoMenuKey.VOICE_GUIDE_KEY,
284
+ onChange
285
+ );
286
+
287
+ log_debug("Samsung Voice Guide listener registered", {
288
+ listenerId: this.samsungListenerId,
289
+ });
290
+ } else {
291
+ log_debug("Samsung TvInfo API not available");
292
+ this.screenReaderEnabled$.next(false);
293
+ }
294
+ } catch (error) {
295
+ log_debug("Samsung Voice Guide listener error", { error });
296
+ // Fallback to false if the service is not available
297
+ this.screenReaderEnabled$.next(false);
298
+ }
299
+ }
205
300
  }
206
301
 
207
302
  getCurrentState(): boolean {
@@ -212,6 +307,10 @@ export class TTSManager {
212
307
  return this.ttsState$.asObservable();
213
308
  }
214
309
 
310
+ getScreenReaderEnabledAsObservable() {
311
+ return this.screenReaderEnabled$.asObservable();
312
+ }
313
+
215
314
  readText(text: string) {
216
315
  this.ttsState$.next(true);
217
316
 
@@ -229,14 +328,14 @@ export class TTSManager {
229
328
  try {
230
329
  window.webOS.service.request("luna://com.webos.service.tts", {
231
330
  method: "speak",
232
- onFailure(error: any) {
331
+ onFailure: (error: any) => {
233
332
  log_debug("There was a failure setting up webOS TTS service", {
234
333
  error,
235
334
  });
236
335
 
237
336
  this.ttsState$.next(false);
238
337
  },
239
- onSuccess(response: any) {
338
+ onSuccess: (response: any) => {
240
339
  log_debug("webOS TTS service is configured successfully", {
241
340
  response,
242
341
  });