@applicaster/zapp-react-native-utils 16.0.0-rc.130 → 16.0.0-rc.132
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.
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
isSamsungPlatform,
|
|
12
12
|
} from "@applicaster/zapp-react-dom-app/App/Loader/utils/platform";
|
|
13
13
|
|
|
14
|
-
import { PLATFORM_KEYS,
|
|
14
|
+
import { PLATFORM_KEYS, ZappPlatform } from "./const";
|
|
15
15
|
import { createLogger, utilsLogger } from "../../logger";
|
|
16
|
-
import { getPlatform } from "../../reactUtils";
|
|
16
|
+
import { getPlatform, isVizioPlatform } from "../../reactUtils";
|
|
17
17
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
18
18
|
import { calculateReadingTime } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/utils";
|
|
19
19
|
|
|
@@ -47,24 +47,8 @@ export const getUserAgent = () => window?.navigator?.userAgent;
|
|
|
47
47
|
|
|
48
48
|
/** VIZIO UTILS */
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
* Use this method when you need to identify the platform on runtime
|
|
54
|
-
* before the VIZIO Companion Library has loaded
|
|
55
|
-
*/
|
|
56
|
-
export const isVizioPlatform = () => {
|
|
57
|
-
const userAgent = getUserAgent();
|
|
58
|
-
|
|
59
|
-
if (!userAgent) return false;
|
|
60
|
-
|
|
61
|
-
const isVizioAgent =
|
|
62
|
-
userAgent.includes(PLATFORMS.vizio) ||
|
|
63
|
-
userAgent.includes(PLATFORMS.smartcast) ||
|
|
64
|
-
userAgent.includes(PLATFORMS.conjure);
|
|
65
|
-
|
|
66
|
-
return isVizioAgent;
|
|
67
|
-
};
|
|
50
|
+
// One implementation, so its build-time device target guard applies here too.
|
|
51
|
+
export { isVizioPlatform };
|
|
68
52
|
|
|
69
53
|
/**
|
|
70
54
|
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.132",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "16.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-rc.132",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isLgPlatform,
|
|
3
|
+
isSamsungPlatform,
|
|
4
|
+
isVizioPlatform,
|
|
5
|
+
} from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
6
|
+
|
|
7
|
+
const UA = {
|
|
8
|
+
lg: "Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 Chrome/87.0",
|
|
9
|
+
samsung: "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/537.36",
|
|
10
|
+
vizio: "Mozilla/5.0 (X11; Linux) Chrome/76.0 VIZIO SmartCast Conjure/MTK",
|
|
11
|
+
desktop: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/120.0",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const originalNavigator = window.navigator;
|
|
15
|
+
|
|
16
|
+
const setUserAgent = (userAgent) => {
|
|
17
|
+
Object.defineProperty(window, "navigator", {
|
|
18
|
+
value: { userAgent },
|
|
19
|
+
configurable: true,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe("web TV device checks and the build-time device target", () => {
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
delete process.env.QUICK_BRICK_DEVICE_TARGET;
|
|
26
|
+
|
|
27
|
+
Object.defineProperty(window, "navigator", {
|
|
28
|
+
value: originalNavigator,
|
|
29
|
+
configurable: true,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("detects every TV at runtime when no device target is set", () => {
|
|
34
|
+
setUserAgent(UA.lg);
|
|
35
|
+
expect(isLgPlatform()).toBe(true);
|
|
36
|
+
|
|
37
|
+
setUserAgent(UA.samsung);
|
|
38
|
+
expect(isSamsungPlatform()).toBe(true);
|
|
39
|
+
|
|
40
|
+
setUserAgent(UA.vizio);
|
|
41
|
+
expect(isVizioPlatform()).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("rejects other TVs on a Samsung build, whatever the user agent", () => {
|
|
45
|
+
process.env.QUICK_BRICK_DEVICE_TARGET = "samsung_tv";
|
|
46
|
+
|
|
47
|
+
setUserAgent(UA.lg);
|
|
48
|
+
expect(isLgPlatform()).toBe(false);
|
|
49
|
+
|
|
50
|
+
setUserAgent(UA.vizio);
|
|
51
|
+
expect(isVizioPlatform()).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("still checks its own TV at runtime, so a desktop browser is not the TV", () => {
|
|
55
|
+
process.env.QUICK_BRICK_DEVICE_TARGET = "samsung_tv";
|
|
56
|
+
|
|
57
|
+
setUserAgent(UA.samsung);
|
|
58
|
+
expect(isSamsungPlatform()).toBe(true);
|
|
59
|
+
|
|
60
|
+
setUserAgent(UA.desktop);
|
|
61
|
+
expect(isSamsungPlatform()).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("keeps a Vizio build's identity separate from LG", () => {
|
|
65
|
+
process.env.QUICK_BRICK_DEVICE_TARGET = "vizio";
|
|
66
|
+
|
|
67
|
+
setUserAgent(UA.lg);
|
|
68
|
+
expect(isLgPlatform()).toBe(false);
|
|
69
|
+
|
|
70
|
+
setUserAgent(UA.vizio);
|
|
71
|
+
expect(isVizioPlatform()).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
package/reactUtils/index.ts
CHANGED
|
@@ -129,7 +129,21 @@ export const hasWebOS = typeof window?.webOS !== "undefined";
|
|
|
129
129
|
|
|
130
130
|
export const getUserAgent = () => window?.navigator?.userAgent;
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Web TV device checks return false outright when the bundle was built for another
|
|
134
|
+
* TV: the web template inlines `process.env.QUICK_BRICK_DEVICE_TARGET` (Zapp
|
|
135
|
+
* `device_target`), so the guard and the code after it fold away at build time.
|
|
136
|
+
* A build for this TV still checks at runtime, because the same bundle also runs
|
|
137
|
+
* in a desktop browser.
|
|
138
|
+
*/
|
|
132
139
|
export const isLgPlatform = () => {
|
|
140
|
+
if (
|
|
141
|
+
process.env.QUICK_BRICK_DEVICE_TARGET &&
|
|
142
|
+
process.env.QUICK_BRICK_DEVICE_TARGET !== "lg_tv"
|
|
143
|
+
) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
133
147
|
const userAgent = getUserAgent();
|
|
134
148
|
|
|
135
149
|
if (!userAgent) {
|
|
@@ -141,6 +155,13 @@ export const isLgPlatform = () => {
|
|
|
141
155
|
};
|
|
142
156
|
|
|
143
157
|
export const isSamsungPlatform = () => {
|
|
158
|
+
if (
|
|
159
|
+
process.env.QUICK_BRICK_DEVICE_TARGET &&
|
|
160
|
+
process.env.QUICK_BRICK_DEVICE_TARGET !== "samsung_tv"
|
|
161
|
+
) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
144
165
|
const userAgent = getUserAgent();
|
|
145
166
|
|
|
146
167
|
if (!userAgent) {
|
|
@@ -161,6 +182,13 @@ export const isSamsungPlatform = () => {
|
|
|
161
182
|
* before the VIZIO Companion Library has loaded
|
|
162
183
|
*/
|
|
163
184
|
export const isVizioPlatform = () => {
|
|
185
|
+
if (
|
|
186
|
+
process.env.QUICK_BRICK_DEVICE_TARGET &&
|
|
187
|
+
process.env.QUICK_BRICK_DEVICE_TARGET !== "vizio"
|
|
188
|
+
) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
164
192
|
const userAgent = getUserAgent();
|
|
165
193
|
|
|
166
194
|
if (!userAgent) {
|