@applicaster/zapp-react-native-utils 12.0.0-alpha.5251355865 → 12.0.0-alpha.5347482137
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/analyticsUtils/AnalyticsEvents/index.ts +13 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
- 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/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 -56
- 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/keyCodes/keys.web.js +8 -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 +223 -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 +43 -3
- package/appUtils/playerManager/playerFactory.ts +12 -10
- package/appUtils/playerManager/playerNative.ts +14 -14
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- 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 +9 -20
- package/cellUtils/index.ts +10 -14
- package/dateUtils/index.ts +11 -0
- package/focusManager/index.ts +1 -1
- package/headersUtils/index.ts +1 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/keyboardState/index.ts +0 -0
- package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
- package/localizationUtils/index.ts +13 -19
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/index.ts +9 -18
- package/package.json +2 -2
- package/playerUtils/configurationGenerator.ts +3 -1
- 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 +10 -1
- package/reactHooks/cell-click/index.ts +12 -12
- 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/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +11 -8
- package/reactHooks/navigation/index.ts +60 -21
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +2 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +3 -3
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/reactUtils/index.ts +102 -0
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/screenState/index.ts +0 -8
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +24 -22
- 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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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
|
-
|
|
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,223 @@
|
|
|
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
|
+
setClosedCaptionHandler: (
|
|
15
|
+
callback: (isCCEnabled: boolean) => void
|
|
16
|
+
) => void;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { log_debug, log_error } = createLogger({
|
|
22
|
+
category: "General",
|
|
23
|
+
subsystem: "PlatformUtils",
|
|
24
|
+
parent: utilsLogger,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const getUserAgent = () =>
|
|
28
|
+
window?.navigator?.userAgent || global?.navigator?.userAgent;
|
|
29
|
+
|
|
30
|
+
/** VIZIO UTILS */
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if we are on the Vizio platform by using the userAgent string
|
|
34
|
+
*
|
|
35
|
+
* Use this method when you need to identify the platform on runtime
|
|
36
|
+
* before the VIZIO Companion Library has loaded
|
|
37
|
+
*/
|
|
38
|
+
export const isVizioPlatform = () => {
|
|
39
|
+
const userAgent = getUserAgent();
|
|
40
|
+
|
|
41
|
+
const isVizioAgent =
|
|
42
|
+
userAgent.includes(PLATFORMS.vizio) ||
|
|
43
|
+
userAgent.includes(PLATFORMS.smartcast) ||
|
|
44
|
+
userAgent.includes(PLATFORMS.conjure);
|
|
45
|
+
|
|
46
|
+
return isVizioAgent;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
|
51
|
+
* and the VIZIO Companion Library. This method does not use the userAgent string,
|
|
52
|
+
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
53
|
+
*/
|
|
54
|
+
export const hasVizioAPIs = () => {
|
|
55
|
+
const hasAPIs =
|
|
56
|
+
typeof window.VIZIO !== "undefined" &&
|
|
57
|
+
window?.applicaster?.vizioLibraryDidLoad;
|
|
58
|
+
|
|
59
|
+
return hasAPIs;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Manages device based closed captioning state
|
|
64
|
+
* Returns an observable that emits the current state and updates whenever it changes
|
|
65
|
+
*/
|
|
66
|
+
class ClosedCaptioningManager {
|
|
67
|
+
private ccState$ = new BehaviorSubject<boolean>(false);
|
|
68
|
+
private static ccManagerInstance: ClosedCaptioningManager;
|
|
69
|
+
|
|
70
|
+
private constructor() {
|
|
71
|
+
this.initialize();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static getInstance(): ClosedCaptioningManager {
|
|
75
|
+
if (!ClosedCaptioningManager.ccManagerInstance) {
|
|
76
|
+
ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return ClosedCaptioningManager.ccManagerInstance;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async initialize() {
|
|
83
|
+
const existingState = await sessionStorage.getItem(
|
|
84
|
+
PLATFORM_KEYS.deviceClosedCaptioningEnabled
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
log_debug("Initializing closed captioning manager", { existingState });
|
|
88
|
+
|
|
89
|
+
if (existingState !== null) {
|
|
90
|
+
this.ccState$.next(existingState === "true" || existingState === true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (hasVizioAPIs()) {
|
|
94
|
+
window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
|
|
95
|
+
log_debug("CC state changed", { isCCEnabled });
|
|
96
|
+
|
|
97
|
+
sessionStorage.setItem(
|
|
98
|
+
PLATFORM_KEYS.deviceClosedCaptioningEnabled,
|
|
99
|
+
isCCEnabled
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
this.ccState$.next(isCCEnabled);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getCurrentState(): boolean {
|
|
108
|
+
return this.ccState$.getValue();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getStateAsObservable() {
|
|
112
|
+
return this.ccState$.asObservable();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Subscribe to closed captioning state changes
|
|
118
|
+
* @returns Observable<boolean>
|
|
119
|
+
* @example
|
|
120
|
+
* const subscription = getClosedCaptionState().subscribe(
|
|
121
|
+
* isEnabled => setClosedCaptionState(isEnabled)
|
|
122
|
+
* );
|
|
123
|
+
* subscription.unsubscribe(), []);
|
|
124
|
+
*/
|
|
125
|
+
export const getClosedCaptionState = () => {
|
|
126
|
+
const ccManager = ClosedCaptioningManager.getInstance();
|
|
127
|
+
|
|
128
|
+
return ccManager.getStateAsObservable();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export class TextTrackManager {
|
|
132
|
+
private controller?: PlayerWebController;
|
|
133
|
+
private static instance: TextTrackManager;
|
|
134
|
+
|
|
135
|
+
private constructor() {}
|
|
136
|
+
|
|
137
|
+
static getInstance(): TextTrackManager {
|
|
138
|
+
if (!TextTrackManager.instance) {
|
|
139
|
+
TextTrackManager.instance = new TextTrackManager();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return TextTrackManager.instance;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
initialize(controller: PlayerWebController) {
|
|
146
|
+
if (!controller) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
"Controller is required for TextTrackManager initialization"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.controller = controller;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async setTextTrackBasedOnCaptions(closedCaptionsState: boolean) {
|
|
156
|
+
if (!this.controller) {
|
|
157
|
+
log_error("Controller is not initialized");
|
|
158
|
+
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (closedCaptionsState) {
|
|
163
|
+
const textTracks = this.controller.getTracksState().textTracks;
|
|
164
|
+
const preferredTextTrack = await this.getPreferredTextTrack(textTracks);
|
|
165
|
+
|
|
166
|
+
if (preferredTextTrack) {
|
|
167
|
+
this.controller.selectTrack(preferredTextTrack);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
this.controller.selectTrack(null);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async getPreferredTextTrack(
|
|
175
|
+
textTracks: QuickBrickPlayer.TextTrack[]
|
|
176
|
+
): Promise<QuickBrickPlayer.TextTrack | undefined> {
|
|
177
|
+
if (!this.controller) return;
|
|
178
|
+
|
|
179
|
+
const userPreferredTextLanguageLocalStorage = await localStorage.getItem(
|
|
180
|
+
"preferred_text_language",
|
|
181
|
+
"user_preferences"
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
let userPreferredTextLanguage;
|
|
185
|
+
|
|
186
|
+
if (userPreferredTextLanguageLocalStorage) {
|
|
187
|
+
userPreferredTextLanguage = textTracks.find(
|
|
188
|
+
(track) => track.language === userPreferredTextLanguageLocalStorage
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (userPreferredTextLanguage?.id) {
|
|
193
|
+
return userPreferredTextLanguage;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const enableAutoTextTrackSelection =
|
|
197
|
+
this.controller.getPluginConfiguration()
|
|
198
|
+
?.enable_auto_text_track_selection ||
|
|
199
|
+
this.controller.getTracksState().textTracks.length > 0;
|
|
200
|
+
|
|
201
|
+
if (enableAutoTextTrackSelection) {
|
|
202
|
+
const languageCode = await sessionStorage.getItem("languageCode");
|
|
203
|
+
|
|
204
|
+
if (languageCode) {
|
|
205
|
+
const chosenTextTrackBySystemLanguage = textTracks.find(
|
|
206
|
+
(track) => track.language === languageCode
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (chosenTextTrackBySystemLanguage?.id) {
|
|
210
|
+
return chosenTextTrackBySystemLanguage;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return textTracks?.[0];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
isTextTrackEnabled(): boolean {
|
|
219
|
+
if (!this.controller) return false;
|
|
220
|
+
|
|
221
|
+
return this.controller.getTracksState().textTrackId !== null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -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",
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
|
|
12
12
|
import { setUserLanguagePreference } from "./userLanguagePreference";
|
|
13
13
|
import { PlayerRole } from "./conts";
|
|
14
|
+
import { RNPlayerManager } from "./nativePlayerManager";
|
|
14
15
|
|
|
15
16
|
const { log_error, log_debug, log_warning } = createLogger({
|
|
16
17
|
category: "General",
|
|
@@ -164,6 +165,10 @@ export class PlayerManager {
|
|
|
164
165
|
this.addPlayer(id, playerController);
|
|
165
166
|
|
|
166
167
|
if (playerController.playerRole === PlayerRole.Primary) {
|
|
168
|
+
if (playerController.playerPluginId !== "QuickBrickPlayerPlugin") {
|
|
169
|
+
RNPlayerManager?.["QuickBrickPlayerPlugin"]?.stopBackgroundPlayback?.();
|
|
170
|
+
}
|
|
171
|
+
|
|
167
172
|
playerController.addListener({
|
|
168
173
|
id: this.getPlayerListenerId(id),
|
|
169
174
|
listener: {
|
|
@@ -361,9 +366,9 @@ export class PlayerManager {
|
|
|
361
366
|
// TODO: Remove
|
|
362
367
|
if (this.castingReceiver) {
|
|
363
368
|
this.castingReceiver.rewind(deltaTime);
|
|
369
|
+
} else {
|
|
370
|
+
this.getActivePlayer()?.rewind(deltaTime);
|
|
364
371
|
}
|
|
365
|
-
|
|
366
|
-
this.getActivePlayer()?.rewind(deltaTime);
|
|
367
372
|
}
|
|
368
373
|
|
|
369
374
|
public forward(deltaTime = null) {
|
|
@@ -371,9 +376,9 @@ export class PlayerManager {
|
|
|
371
376
|
|
|
372
377
|
if (this.castingReceiver) {
|
|
373
378
|
this.castingReceiver.forward(deltaTime);
|
|
379
|
+
} else {
|
|
380
|
+
this.getActivePlayer()?.forward(deltaTime);
|
|
374
381
|
}
|
|
375
|
-
|
|
376
|
-
this.getActivePlayer()?.forward(deltaTime);
|
|
377
382
|
}
|
|
378
383
|
|
|
379
384
|
public seeking(time) {
|
|
@@ -436,7 +441,7 @@ export class PlayerManager {
|
|
|
436
441
|
}
|
|
437
442
|
|
|
438
443
|
// Call method on player just in case
|
|
439
|
-
return this.getActivePlayer()?.
|
|
444
|
+
return this.getActivePlayer()?.selectTrack(track);
|
|
440
445
|
}
|
|
441
446
|
|
|
442
447
|
public isRegistered() {
|
|
@@ -461,6 +466,7 @@ export class PlayerManager {
|
|
|
461
466
|
if (this.castingReceiver) {
|
|
462
467
|
this.castingReceiver.closeNativePlayer();
|
|
463
468
|
} else {
|
|
469
|
+
this.getActivePlayer().closeNativePlayer();
|
|
464
470
|
this.invokeHandler("close");
|
|
465
471
|
}
|
|
466
472
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NativeModules } from "react-native";
|
|
2
|
+
import { isApplePlatform } from "../../reactUtils";
|
|
3
|
+
|
|
4
|
+
export const RNPlayerManager = {
|
|
5
|
+
QuickBrickPlayerPlugin: isApplePlatform()
|
|
6
|
+
? NativeModules.PlayerModule
|
|
7
|
+
: NativeModules.QuickBrickDefaultPlayerModule,
|
|
8
|
+
KalturaPlayerPlugin: isApplePlatform()
|
|
9
|
+
? NativeModules.KalturaPlayerModule
|
|
10
|
+
: NativeModules.QBKalturaPlayerModule,
|
|
11
|
+
"quick-brick-player-brightcove": NativeModules.BrightcovePlayerModule,
|
|
12
|
+
};
|