@applicaster/zapp-react-native-utils 15.0.0-alpha.5830601313 → 15.0.0-alpha.5918085834

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 (51) 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/const.ts +4 -0
  7. package/appUtils/accessibilityManager/hooks.ts +20 -13
  8. package/appUtils/accessibilityManager/index.ts +28 -1
  9. package/appUtils/accessibilityManager/utils.ts +36 -5
  10. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  11. package/appUtils/orientationHelper.ts +2 -4
  12. package/appUtils/platform/platformUtils.ts +117 -18
  13. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  14. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  15. package/appUtils/playerManager/player.ts +4 -0
  16. package/appUtils/playerManager/playerNative.ts +29 -16
  17. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  18. package/cellUtils/index.ts +32 -0
  19. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  20. package/manifestUtils/defaultManifestConfigurations/player.js +75 -1
  21. package/manifestUtils/keys.js +21 -0
  22. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  23. package/manifestUtils/tvAction/container/index.js +1 -1
  24. package/package.json +2 -2
  25. package/playerUtils/usePlayerTTS.ts +8 -3
  26. package/pluginUtils/index.ts +4 -0
  27. package/reactHooks/advertising/index.ts +2 -2
  28. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  29. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  30. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +3 -0
  31. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  32. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  33. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  34. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  35. package/reactHooks/navigation/index.ts +7 -6
  36. package/reactHooks/navigation/useRoute.ts +8 -6
  37. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  38. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  39. package/reactHooks/resolvers/useComponentResolver.ts +8 -2
  40. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +10 -2
  41. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  42. package/reactHooks/state/useRivers.ts +1 -1
  43. package/reactHooks/usePluginConfiguration.ts +2 -2
  44. package/testUtils/index.tsx +29 -20
  45. package/utils/__tests__/mapAccum.test.ts +73 -0
  46. package/utils/__tests__/selectors.test.ts +124 -0
  47. package/utils/index.ts +6 -0
  48. package/utils/mapAccum.ts +23 -0
  49. package/utils/selectors.ts +46 -0
  50. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +34 -11
  51. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
@@ -23,12 +23,9 @@ import {
23
23
  EntryResolver,
24
24
  resolveObjectValues,
25
25
  } from "../appUtils/contextKeysManager/contextResolver";
26
- import { useNavigation } from "../reactHooks";
26
+ import { useNavigation, useRivers } from "../reactHooks";
27
27
 
28
- import {
29
- useContentTypes,
30
- usePickFromState,
31
- } from "@applicaster/zapp-react-native-redux/hooks";
28
+ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
32
29
  import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
33
30
  import { APP_EVENTS } from "../appUtils/events";
34
31
  import {
@@ -278,7 +275,7 @@ export function withActionExecutor(Component) {
278
275
 
279
276
  return function ActionExecutorComponent(props: Props) {
280
277
  const navigator = useNavigation();
281
- const { rivers } = usePickFromState(["rivers"]);
278
+ const rivers = useRivers();
282
279
  const contentTypes = useContentTypes();
283
280
 
284
281
  const handlers = useMemo(() => {
@@ -27,7 +27,7 @@ function makeMultiSelect(feed: ZappFeed, key, decoratedFeed) {
27
27
  );
28
28
 
29
29
  const behavior = {
30
- ...feed.extensions?.["behavior"],
30
+ ...feed.extensions?.behavior,
31
31
  select_mode: "multi",
32
32
  current_selection: `@{${scope}/${key}}`,
33
33
  };
@@ -75,7 +75,7 @@ function makeSingleSelect(feed: ZappFeed, key, decoratedFeed) {
75
75
  );
76
76
 
77
77
  const behavior = {
78
- ...feed.extensions?.["behavior"],
78
+ ...feed.extensions?.behavior,
79
79
  select_mode: "single",
80
80
  current_selection: `@{${scope}/${key}}`,
81
81
  };
@@ -141,11 +141,11 @@ function makeSingleSelect(feed: ZappFeed, key, decoratedFeed) {
141
141
  }
142
142
 
143
143
  export const decorateFeed = (feed: ZappFeed) => {
144
- if (!(feed.extensions?.["role"] === "preference_editor")) {
144
+ if (!(feed.extensions?.role === "preference_editor")) {
145
145
  return feed;
146
146
  }
147
147
 
148
- const key = feed.extensions?.["preference_editor_options"]?.["key"];
148
+ const key = feed.extensions?.preference_editor_options?.key;
149
149
 
150
150
  if (!key) {
151
151
  log_error(
@@ -160,8 +160,8 @@ export const decorateFeed = (feed: ZappFeed) => {
160
160
  const decoratedFeed = R.clone(feed);
161
161
 
162
162
  const isSingleSelect =
163
- (feed.extensions?.["preference_editor_options"]?.select_mode ||
164
- feed.extensions?.["behavior"]?.select_mode) === "single";
163
+ (feed.extensions?.preference_editor_options?.select_mode ||
164
+ feed.extensions?.behavior?.select_mode) === "single";
165
165
 
166
166
  if (isSingleSelect) {
167
167
  return makeSingleSelect(feed, key, decoratedFeed);
package/adsUtils/index.ts CHANGED
@@ -33,10 +33,10 @@ function convertOffset(offset: any): string {
33
33
  }
34
34
 
35
35
  function createAdBreak(ad: AdMap): string {
36
- const offset = ad["offset"];
36
+ const offset = ad.offset;
37
37
  const id = offset.toString();
38
38
  const timestamp = convertOffset(offset);
39
- const url = ad["ad_url"].toString().trim();
39
+ const url = ad.ad_url.toString().trim();
40
40
 
41
41
  return `
42
42
  <vmap:AdBreak timeOffset="${timestamp}" breakType="linear" breakId="break-${id}">
@@ -388,7 +388,7 @@ export function AnalyticsProvider(props: ComponentWithChildrenProps) {
388
388
 
389
389
  ```ts
390
390
  export function useAnalytics(props: any): any {
391
- const { appData } = usePickFromState(["appData"]);
391
+ const appData = useAppData();
392
392
  const getAnalyticsFunctions = React.useContext(AnalyticsContext);
393
393
 
394
394
  const analyticsFunctions = React.useMemo(
@@ -230,7 +230,7 @@ export function HooksManager({
230
230
  function completeHook(hookPlugin, payload, callback) {
231
231
  logHookEvent(
232
232
  hooksManagerLogger.info,
233
- `completeHook: hook sequence completed successfully: ${hookPlugin["identifier"]}`,
233
+ `completeHook: hook sequence completed successfully: ${hookPlugin.identifier}`,
234
234
  {
235
235
  payload,
236
236
  hook: hookPlugin,
@@ -276,7 +276,7 @@ export function HooksManager({
276
276
  if (hookPlugin.isCancelled()) {
277
277
  logHookEvent(
278
278
  hooksManagerLogger.info,
279
- `hookCallback: hook was cancelled: ${hookPlugin["identifier"]}`,
279
+ `hookCallback: hook was cancelled: ${hookPlugin.identifier}`,
280
280
  {}
281
281
  );
282
282
 
@@ -305,7 +305,7 @@ export function HooksManager({
305
305
  if (!success) {
306
306
  logHookEvent(
307
307
  hooksManagerLogger.info,
308
- `hookCallback: hook was cancelled: ${hookPlugin["identifier"]}`,
308
+ `hookCallback: hook was cancelled: ${hookPlugin.identifier}`,
309
309
  {
310
310
  payload,
311
311
  hook: hookPlugin,
@@ -334,7 +334,7 @@ export function HooksManager({
334
334
  if (isHookInHomescreen && isHookFlowBlocker && cancelled) {
335
335
  logHookEvent(
336
336
  hooksManagerLogger.info,
337
- `hookCallback: send app to background, cancelled flow blocker hook ${hookPlugin["identifier"]} on home screen`,
337
+ `hookCallback: send app to background, cancelled flow blocker hook ${hookPlugin.identifier} on home screen`,
338
338
  {
339
339
  payload,
340
340
  hook: hookPlugin,
@@ -349,7 +349,7 @@ export function HooksManager({
349
349
  } else {
350
350
  logHookEvent(
351
351
  hooksManagerLogger.info,
352
- `hookCallback: hook successfully finished: ${hookPlugin["identifier"]}`,
352
+ `hookCallback: hook successfully finished: ${hookPlugin.identifier}`,
353
353
  {
354
354
  payload,
355
355
  hook: hookPlugin,
@@ -359,7 +359,7 @@ export function HooksManager({
359
359
  if (!callback) {
360
360
  logHookEvent(
361
361
  hooksManagerLogger.warn,
362
- `hookCallback: ${hookPlugin["identifier"]} is missing \`callback\`, using hookCallback(default one)`,
362
+ `hookCallback: ${hookPlugin.identifier} is missing \`callback\`, using hookCallback(default one)`,
363
363
  {
364
364
  hookPlugin,
365
365
  }
@@ -401,7 +401,7 @@ export function HooksManager({
401
401
 
402
402
  logHookEvent(
403
403
  hooksManagerLogger.info,
404
- `presentScreenHook: Presenting screen hook: ${hookPlugin["identifier"]}`,
404
+ `presentScreenHook: Presenting screen hook: ${hookPlugin.identifier}`,
405
405
  {
406
406
  hook: hookPlugin,
407
407
  payload,
@@ -421,7 +421,7 @@ export function HooksManager({
421
421
  hooksManager.executeHook = function (hookPlugin, payload, callback) {
422
422
  logHookEvent(
423
423
  hooksManagerLogger.info,
424
- `executeHook: ${hookPlugin["identifier"]}`,
424
+ `executeHook: ${hookPlugin.identifier}`,
425
425
  {
426
426
  hook: hookPlugin,
427
427
  payload,
@@ -433,7 +433,7 @@ export function HooksManager({
433
433
  } catch (error) {
434
434
  logHookEvent(
435
435
  hooksManagerLogger.error,
436
- `executeHook: error executing hook: ${hookPlugin["identifier"]} error: ${error.message}`,
436
+ `executeHook: error executing hook: ${hookPlugin.identifier} error: ${error.message}`,
437
437
  {
438
438
  hook: hookPlugin,
439
439
  payload,
@@ -460,7 +460,7 @@ export function HooksManager({
460
460
  try {
461
461
  logHookEvent(
462
462
  hooksManagerLogger.info,
463
- `runInBackground: Executing hook: ${hookPlugin["identifier"]}`,
463
+ `runInBackground: Executing hook: ${hookPlugin.identifier}`,
464
464
  {
465
465
  hook: hookPlugin,
466
466
  payload,
@@ -31,6 +31,10 @@ export const BUTTON_ACCESSIBILITY_KEYS = {
31
31
  hint: "accessibility_close_mini_hint",
32
32
  },
33
33
  },
34
+ back_to_live: {
35
+ label: "back_to_live_label",
36
+ hint: "",
37
+ },
34
38
  maximize: {
35
39
  label: "accessibility_maximize_label",
36
40
  hint: "accessibility_maximize_hint",
@@ -23,19 +23,6 @@ export const useAccessibilityManager = (
23
23
  }
24
24
  }, [pluginConfiguration, accessibilityManager]);
25
25
 
26
- useEffect(() => {
27
- const subscription = accessibilityManager.getStateAsObservable().subscribe({
28
- next: () => {
29
- // TODO: handle accessibility states
30
- // screenReaderEnabled: false
31
- // reduceMotionEnabled: false
32
- // boldTextEnabled: false
33
- },
34
- });
35
-
36
- return () => subscription.unsubscribe();
37
- }, [accessibilityManager]);
38
-
39
26
  return accessibilityManager;
40
27
  };
41
28
 
@@ -72,3 +59,23 @@ export const useAnnouncementActive = (
72
59
 
73
60
  return isActive;
74
61
  };
62
+
63
+ export const useAccessibilityState = (
64
+ pluginConfiguration: Record<string, any> = {}
65
+ ) => {
66
+ const accessibilityManager = useAccessibilityManager(pluginConfiguration);
67
+
68
+ const [state, setState] = useState<AccessibilityState>(
69
+ accessibilityManager.getState()
70
+ );
71
+
72
+ useEffect(() => {
73
+ const subscription = accessibilityManager
74
+ .getStateAsObservable()
75
+ .subscribe(setState);
76
+
77
+ return () => subscription.unsubscribe();
78
+ }, [accessibilityManager]);
79
+
80
+ return state;
81
+ };
@@ -36,7 +36,20 @@ export class AccessibilityManager {
36
36
  false
37
37
  );
38
38
 
39
- private constructor() {}
39
+ private constructor() {
40
+ this.ttsManager
41
+ .getScreenReaderEnabledAsObservable()
42
+ .subscribe((enabled) => {
43
+ const state = this.state$.getValue();
44
+
45
+ if (state.screenReaderEnabled !== enabled) {
46
+ this.state$.next({
47
+ ...state,
48
+ screenReaderEnabled: enabled,
49
+ });
50
+ }
51
+ });
52
+ }
40
53
 
41
54
  public static getInstance(): AccessibilityManager {
42
55
  if (!AccessibilityManager._instance) {
@@ -92,8 +105,15 @@ export class AccessibilityManager {
92
105
  /**
93
106
  * Adds a heading to the queue, headings will be read before the next text
94
107
  * Each heading will be read once and removed from the queue
108
+ * Does nothing if screen reader is not enabled
95
109
  */
96
110
  public addHeading(heading: string) {
111
+ const state = this.state$.getValue();
112
+
113
+ if (!state.screenReaderEnabled) {
114
+ return;
115
+ }
116
+
97
117
  if (!this.pendingFocusId) {
98
118
  this.pendingFocusId = Date.now().toString();
99
119
  }
@@ -108,6 +128,7 @@ export class AccessibilityManager {
108
128
  *
109
129
  * Implements a delay mechanism to reduce noise during rapid navigation.
110
130
  * Only the most recent announcement will be read after the delay period.
131
+ * Does nothing if screen reader is not enabled
111
132
  */
112
133
  public readText({
113
134
  text,
@@ -116,6 +137,12 @@ export class AccessibilityManager {
116
137
  text: string;
117
138
  keyOfLocalizedText?: string;
118
139
  }) {
140
+ const state = this.state$.getValue();
141
+
142
+ if (!state.screenReaderEnabled) {
143
+ return;
144
+ }
145
+
119
146
  let textToRead = text;
120
147
 
121
148
  if (keyOfLocalizedText) {
@@ -12,13 +12,44 @@ export function calculateReadingTime(
12
12
  minimumPause: number = 500,
13
13
  announcementDelay: number = 700
14
14
  ): number {
15
- const words = text
16
- .trim()
15
+ const trimmed = text.trim();
16
+
17
+ // Count words (split on whitespace and punctuation, keep alnum boundaries)
18
+ const words = trimmed
17
19
  .split(/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)|[^\w\s]+|\s+/)
18
20
  .filter(Boolean).length;
19
21
 
20
- return (
21
- Math.max(minimumPause, (words / wordsPerMinute) * 60 * 1000) +
22
- announcementDelay
22
+ // Count spaces - multiple consecutive spaces add extra pause time
23
+ const spaceMatches: string[] = trimmed.match(/\s+/g) || [];
24
+
25
+ const totalSpaces = spaceMatches.reduce(
26
+ (sum: number, match: string) => sum + match.length,
27
+ 0
23
28
  );
29
+
30
+ const extraSpaces = Math.max(0, totalSpaces - (words - 1)); // words-1 is normal spacing
31
+
32
+ // Heuristic: punctuation increases TTS duration beyond word-based WPM.
33
+ // Commas typically introduce short pauses, sentence terminators longer ones.
34
+ const commaCount = (trimmed.match(/,/g) || []).length;
35
+ const semicolonCount = (trimmed.match(/;/g) || []).length;
36
+ const colonCount = (trimmed.match(/:/g) || []).length;
37
+ const dashCount = (trimmed.match(/\u2013|\u2014|-/g) || []).length; // – — -
38
+ const sentenceEndCount = (trimmed.match(/[.!?](?!\d)/g) || []).length;
39
+
40
+ const commaPauseMs = 220; // short prosody pause for ","
41
+ const midPauseMs = 260; // for ";", ":", dashes
42
+ const sentenceEndPauseMs = 420; // for ".", "!", "?"
43
+ const extraSpacePauseMs = 50; // per extra space beyond normal spacing
44
+
45
+ const punctuationPause =
46
+ commaCount * commaPauseMs +
47
+ (semicolonCount + colonCount + dashCount) * midPauseMs +
48
+ sentenceEndCount * sentenceEndPauseMs +
49
+ extraSpaces * extraSpacePauseMs;
50
+
51
+ const baseByWordsMs = (words / wordsPerMinute) * 60 * 1000;
52
+ const estimatedMs = Math.max(minimumPause, baseByWordsMs + punctuationPause);
53
+
54
+ return estimatedMs + announcementDelay;
24
55
  }
@@ -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
  });