@applicaster/zapp-react-native-utils 12.0.0-rc.9 → 12.0.0-rc.90
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.
- package/actionsExecutor/ActionExecutorContext.tsx +16 -8
- package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +12 -0
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/analyticsUtils/index.tsx +12 -0
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/accessibilityManager/const.ts +50 -0
- package/appUtils/accessibilityManager/hooks.ts +31 -0
- package/appUtils/accessibilityManager/index.ts +150 -0
- package/appUtils/accessibilityManager/logger.ts +5 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
- package/appUtils/focusManager/__tests__/index.test.ts +2 -3
- package/appUtils/focusManager/index.ts +76 -57
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -35
- package/appUtils/focusManager/utils/index.ts +100 -0
- package/appUtils/focusManagerAux/index.ts +76 -0
- package/appUtils/focusManagerAux/utils/index.ts +100 -0
- package/appUtils/index.js +2 -0
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
- package/appUtils/keyCodes/keys.web.js +9 -0
- package/appUtils/keyCodes/keysByPlatform.js +11 -1
- package/appUtils/platform/const.ts +25 -0
- package/appUtils/platform/index.ts +3 -0
- package/appUtils/platform/platformUtils.ts +281 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +6 -0
- package/appUtils/playerManager/index.ts +11 -5
- package/appUtils/playerManager/nativePlayerManager.ts +12 -0
- package/appUtils/playerManager/player.ts +55 -7
- package/appUtils/playerManager/playerFactory.ts +15 -1
- package/appUtils/playerManager/playerNative.ts +40 -14
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- package/appUtils/playerManager/usePlayerState.tsx +13 -1
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
- package/arrayUtils/index.ts +5 -0
- package/booleanUtils/index.ts +4 -4
- package/cellUtils/__tests__/cellUtils.test.ts +48 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +40 -2
- package/dateUtils/index.ts +11 -0
- package/focusManager/index.ts +1 -1
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
- package/functionUtils/__tests__/functionUtils.test.js +244 -248
- package/headersUtils/index.ts +1 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/keyboardState/index.ts +0 -0
- package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
- package/localizationUtils/index.ts +13 -19
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +10 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/modalState/index.ts +57 -0
- package/navigationUtils/index.ts +56 -7
- package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/index.ts +9 -18
- package/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +11 -1
- package/pluginUtils/index.ts +20 -7
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
- package/reactHooks/cell-click/__tests__/index.test.js +16 -3
- package/reactHooks/cell-click/index.ts +14 -14
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
- package/reactHooks/feed/useFeedRefresh.tsx +9 -7
- package/reactHooks/feed/useInflatedUrl.ts +44 -15
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
- package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
- package/reactHooks/navigation/index.ts +239 -80
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +4 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +4 -4
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/useListenEventBusEvent.ts +1 -4
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/reactUtils/index.ts +105 -0
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +38 -23
- package/types.ts +4 -0
- package/appUtils/focusManager/FocusableEvents.ts +0 -8
- package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
- 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,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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
33
|
-
keyCode(KEYS.Enter).
|
|
34
|
-
)
|
|
35
|
-
});
|
|
18
|
+
it("returns an object for a given key event", () => {
|
|
19
|
+
expect(keyCode(KEYS.Enter)).toMatchSnapshot();
|
|
20
|
+
});
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
it("has matcher for multiple keys", () => {
|
|
29
|
+
expect(
|
|
30
|
+
keyCode(KEYS.Enter).matchesAny("Enter", "Back", "ArrowUp")
|
|
31
|
+
).toBeTruthy();
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
expect(
|
|
34
|
+
keyCode(KEYS.Enter).matchesAny("Back", "ArrowUp", "ArrowDown")
|
|
35
|
+
).toBeFalsy();
|
|
48
36
|
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
37
|
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
expect(keyCode(KEYS.ArrowDown).direction()).toEqual(
|
|
42
|
+
directionHelper(KEYS.ArrowDown)
|
|
43
|
+
);
|
|
44
|
+
});
|
|
61
45
|
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
describe("in Tizen Env", () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
jest.resetModules();
|
|
56
|
+
global.tizen = globalTizen;
|
|
57
|
+
});
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
describe("in WebOS Env", () => {
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
jest.resetModules();
|
|
95
|
+
});
|
|
103
96
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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,281 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
|
|
3
|
+
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
4
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
5
|
+
import { PlayerWebController } from "@applicaster/zapp-react-native-default-player/src/playerFactory/players/playerWebController";
|
|
6
|
+
|
|
7
|
+
import { PLATFORM_KEYS, PLATFORMS } from "./const";
|
|
8
|
+
import { createLogger, utilsLogger } from "../../logger";
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
VIZIO?: {
|
|
13
|
+
exitApplication: () => void;
|
|
14
|
+
Chromevox: {
|
|
15
|
+
play: (text: string) => void;
|
|
16
|
+
};
|
|
17
|
+
setClosedCaptionHandler: (
|
|
18
|
+
callback: (isCCEnabled: boolean) => void
|
|
19
|
+
) => void;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { log_debug, log_error } = createLogger({
|
|
25
|
+
category: "General",
|
|
26
|
+
subsystem: "PlatformUtils",
|
|
27
|
+
parent: utilsLogger,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const getUserAgent = () =>
|
|
31
|
+
window?.navigator?.userAgent || global?.navigator?.userAgent;
|
|
32
|
+
|
|
33
|
+
/** VIZIO UTILS */
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Checks if we are on the Vizio platform by using the userAgent string
|
|
37
|
+
*
|
|
38
|
+
* Use this method when you need to identify the platform on runtime
|
|
39
|
+
* before the VIZIO Companion Library has loaded
|
|
40
|
+
*/
|
|
41
|
+
export const isVizioPlatform = () => {
|
|
42
|
+
const userAgent = getUserAgent();
|
|
43
|
+
|
|
44
|
+
const isVizioAgent =
|
|
45
|
+
userAgent.includes(PLATFORMS.vizio) ||
|
|
46
|
+
userAgent.includes(PLATFORMS.smartcast) ||
|
|
47
|
+
userAgent.includes(PLATFORMS.conjure);
|
|
48
|
+
|
|
49
|
+
return isVizioAgent;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
|
54
|
+
* and the VIZIO Companion Library. This method does not use the userAgent string,
|
|
55
|
+
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
56
|
+
*/
|
|
57
|
+
export const hasVizioAPIs = () => {
|
|
58
|
+
const hasAPIs =
|
|
59
|
+
typeof window.VIZIO !== "undefined" &&
|
|
60
|
+
window?.applicaster?.vizioLibraryDidLoad;
|
|
61
|
+
|
|
62
|
+
return hasAPIs;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Manages device based closed captioning state
|
|
67
|
+
* Returns an observable that emits the current state and updates whenever it changes
|
|
68
|
+
*/
|
|
69
|
+
export class ClosedCaptioningManager {
|
|
70
|
+
private ccState$ = new BehaviorSubject<boolean>(false);
|
|
71
|
+
private static ccManagerInstance: ClosedCaptioningManager;
|
|
72
|
+
|
|
73
|
+
private constructor() {
|
|
74
|
+
this.initialize();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static getInstance(): ClosedCaptioningManager {
|
|
78
|
+
if (!ClosedCaptioningManager.ccManagerInstance) {
|
|
79
|
+
ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return ClosedCaptioningManager.ccManagerInstance;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async initialize() {
|
|
86
|
+
const existingState = await sessionStorage.getItem(
|
|
87
|
+
PLATFORM_KEYS.deviceClosedCaptioningEnabled
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
log_debug("Initializing closed captioning manager", { existingState });
|
|
91
|
+
|
|
92
|
+
if (existingState !== null) {
|
|
93
|
+
this.ccState$.next(existingState === "true" || existingState === true);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (hasVizioAPIs()) {
|
|
97
|
+
window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
|
|
98
|
+
log_debug("CC state changed", { isCCEnabled });
|
|
99
|
+
|
|
100
|
+
sessionStorage.setItem(
|
|
101
|
+
PLATFORM_KEYS.deviceClosedCaptioningEnabled,
|
|
102
|
+
isCCEnabled
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
this.ccState$.next(isCCEnabled);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getCurrentState(): boolean {
|
|
111
|
+
return this.ccState$.getValue();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getStateAsObservable() {
|
|
115
|
+
return this.ccState$.asObservable();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Subscribe to closed captioning state changes
|
|
121
|
+
* @returns Observable<boolean>
|
|
122
|
+
* @example
|
|
123
|
+
* const subscription = getClosedCaptionState().subscribe(
|
|
124
|
+
* isEnabled => setClosedCaptionState(isEnabled)
|
|
125
|
+
* );
|
|
126
|
+
* subscription.unsubscribe(), []);
|
|
127
|
+
*/
|
|
128
|
+
export const getClosedCaptionState = () => {
|
|
129
|
+
const ccManager = ClosedCaptioningManager.getInstance();
|
|
130
|
+
|
|
131
|
+
return ccManager.getStateAsObservable();
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export class TextTrackManager {
|
|
135
|
+
private controller?: PlayerWebController;
|
|
136
|
+
private static instance: TextTrackManager;
|
|
137
|
+
|
|
138
|
+
private constructor() {}
|
|
139
|
+
|
|
140
|
+
static getInstance(): TextTrackManager {
|
|
141
|
+
if (!TextTrackManager.instance) {
|
|
142
|
+
TextTrackManager.instance = new TextTrackManager();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return TextTrackManager.instance;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
initialize(controller: PlayerWebController) {
|
|
149
|
+
if (!controller) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
"Controller is required for TextTrackManager initialization"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this.controller = controller;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async setTextTrackBasedOnCaptions(closedCaptionsState: boolean) {
|
|
159
|
+
if (!this.controller) {
|
|
160
|
+
log_error("Controller is not initialized");
|
|
161
|
+
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (closedCaptionsState) {
|
|
166
|
+
const textTracks = this.controller.getTracksState().textTracks;
|
|
167
|
+
const preferredTextTrack = await this.getPreferredTextTrack(textTracks);
|
|
168
|
+
|
|
169
|
+
if (preferredTextTrack) {
|
|
170
|
+
this.controller.selectTrack(preferredTextTrack);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
this.controller.selectTrack(null);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async getPreferredTextTrack(
|
|
178
|
+
textTracks: QuickBrickPlayer.TextTrack[]
|
|
179
|
+
): Promise<QuickBrickPlayer.TextTrack | undefined> {
|
|
180
|
+
if (!this.controller) return;
|
|
181
|
+
|
|
182
|
+
const userPreferredTextLanguageLocalStorage = await localStorage.getItem(
|
|
183
|
+
"preferred_text_language",
|
|
184
|
+
"user_preferences"
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
let userPreferredTextLanguage;
|
|
188
|
+
|
|
189
|
+
if (userPreferredTextLanguageLocalStorage) {
|
|
190
|
+
userPreferredTextLanguage = textTracks.find(
|
|
191
|
+
(track) => track.language === userPreferredTextLanguageLocalStorage
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (userPreferredTextLanguage?.id) {
|
|
196
|
+
return userPreferredTextLanguage;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const enableAutoTextTrackSelection =
|
|
200
|
+
this.controller.getPluginConfiguration()
|
|
201
|
+
?.enable_auto_text_track_selection ||
|
|
202
|
+
this.controller.getTracksState().textTracks.length > 0;
|
|
203
|
+
|
|
204
|
+
if (enableAutoTextTrackSelection) {
|
|
205
|
+
const languageCode = await sessionStorage.getItem("languageCode");
|
|
206
|
+
|
|
207
|
+
if (languageCode) {
|
|
208
|
+
const chosenTextTrackBySystemLanguage = textTracks.find(
|
|
209
|
+
(track) => track.language === languageCode
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (chosenTextTrackBySystemLanguage?.id) {
|
|
213
|
+
return chosenTextTrackBySystemLanguage;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return textTracks?.[0];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
isTextTrackEnabled(): boolean {
|
|
222
|
+
if (!this.controller) return false;
|
|
223
|
+
|
|
224
|
+
return this.controller.getTracksState().textTrackId !== null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Manages device based closed captioning state
|
|
230
|
+
* Returns an observable that emits the current state and updates whenever it changes
|
|
231
|
+
*/
|
|
232
|
+
export class TTSManager {
|
|
233
|
+
private ttsState$ = new BehaviorSubject<boolean>(false);
|
|
234
|
+
private static ttsManagerInstance: TTSManager;
|
|
235
|
+
|
|
236
|
+
private constructor() {
|
|
237
|
+
this.initialize();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static getInstance(): TTSManager {
|
|
241
|
+
if (!TTSManager.ttsManagerInstance) {
|
|
242
|
+
TTSManager.ttsManagerInstance = new TTSManager();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return TTSManager.ttsManagerInstance;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async initialize() {
|
|
249
|
+
if (!isVizioPlatform()) return;
|
|
250
|
+
|
|
251
|
+
document.addEventListener(
|
|
252
|
+
"VIZIO_TTS_ENABLED",
|
|
253
|
+
() => {
|
|
254
|
+
this.ttsState$.next(true);
|
|
255
|
+
},
|
|
256
|
+
false
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
document.addEventListener(
|
|
260
|
+
"VIZIO_TTS_DISABLED",
|
|
261
|
+
() => {
|
|
262
|
+
this.ttsState$.next(false);
|
|
263
|
+
},
|
|
264
|
+
false
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
getCurrentState(): boolean {
|
|
269
|
+
return this.ttsState$.getValue();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
getStateAsObservable() {
|
|
273
|
+
return this.ttsState$.asObservable();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
readText(text: string) {
|
|
277
|
+
if (!window.VIZIO?.Chromevox) return;
|
|
278
|
+
|
|
279
|
+
window.VIZIO.Chromevox.play(text);
|
|
280
|
+
}
|
|
281
|
+
}
|