@applicaster/zapp-react-native-utils 16.0.0-alpha.3534530222 → 16.0.0-alpha.4342281394
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.
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const mockAppStoreGet = jest.fn();
|
|
2
|
+
const mockFindPluginByIdentifier = jest.fn();
|
|
3
|
+
|
|
4
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
|
|
5
|
+
appStore: { get: (key: string) => mockAppStoreGet(key) },
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
jest.mock("@applicaster/zapp-react-native-utils/pluginUtils", () => ({
|
|
9
|
+
findPluginByIdentifier: (id: string, plugins: any) =>
|
|
10
|
+
mockFindPluginByIdentifier(id, plugins),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { PlayerRole } from "../conts";
|
|
14
|
+
import { playerFactory } from "../playerFactory";
|
|
15
|
+
|
|
16
|
+
const fakeComponent = () => null;
|
|
17
|
+
|
|
18
|
+
class FakeController {
|
|
19
|
+
receivedConfig: any;
|
|
20
|
+
constructor(config: any) {
|
|
21
|
+
this.receivedConfig = config;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const baseConfig = {
|
|
26
|
+
player: {},
|
|
27
|
+
playerId: "p1",
|
|
28
|
+
autoplay: false,
|
|
29
|
+
entry: { id: "entry-1" } as any,
|
|
30
|
+
muted: false,
|
|
31
|
+
playerPluginId: "test-plugin",
|
|
32
|
+
screenConfig: { foo: "bar" },
|
|
33
|
+
playerRole: PlayerRole.Cell,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const installPluginWithProtocol = (
|
|
37
|
+
protocolReturn: any | ((screenConfig: any, entry: any) => any)
|
|
38
|
+
) => {
|
|
39
|
+
const playerProtocol =
|
|
40
|
+
typeof protocolReturn === "function"
|
|
41
|
+
? protocolReturn
|
|
42
|
+
: () => protocolReturn;
|
|
43
|
+
|
|
44
|
+
mockAppStoreGet.mockImplementation((key: string) =>
|
|
45
|
+
key === "plugins" ? { "test-plugin": {} } : null
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
mockFindPluginByIdentifier.mockReturnValue({
|
|
49
|
+
module: { playerProtocol },
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe("playerFactory", () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
mockAppStoreGet.mockReset();
|
|
56
|
+
mockFindPluginByIdentifier.mockReset();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("resolves with controller and Component when playerProtocol returns synchronously", async () => {
|
|
60
|
+
installPluginWithProtocol({
|
|
61
|
+
Component: fakeComponent,
|
|
62
|
+
controllerClass: FakeController,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const item = await playerFactory(baseConfig);
|
|
66
|
+
|
|
67
|
+
expect(item).not.toBeNull();
|
|
68
|
+
expect(item?.Component).toBe(fakeComponent);
|
|
69
|
+
expect(item?.controller).toBeInstanceOf(FakeController);
|
|
70
|
+
|
|
71
|
+
expect((item?.controller as FakeController).receivedConfig).toBe(
|
|
72
|
+
baseConfig
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("resolves with controller and Component when playerProtocol returns a Promise (delayed import)", async () => {
|
|
77
|
+
installPluginWithProtocol(async () => ({
|
|
78
|
+
Component: fakeComponent,
|
|
79
|
+
controllerClass: FakeController,
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
const item = await playerFactory(baseConfig);
|
|
83
|
+
|
|
84
|
+
expect(item).not.toBeNull();
|
|
85
|
+
expect(item?.Component).toBe(fakeComponent);
|
|
86
|
+
expect(item?.controller).toBeInstanceOf(FakeController);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("passes screenConfig and entry through to playerProtocol", async () => {
|
|
90
|
+
const playerProtocol = jest.fn(() => ({
|
|
91
|
+
Component: fakeComponent,
|
|
92
|
+
controllerClass: FakeController,
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
mockAppStoreGet.mockImplementation((key: string) =>
|
|
96
|
+
key === "plugins" ? { "test-plugin": {} } : null
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
mockFindPluginByIdentifier.mockReturnValue({ module: { playerProtocol } });
|
|
100
|
+
|
|
101
|
+
await playerFactory(baseConfig);
|
|
102
|
+
|
|
103
|
+
expect(playerProtocol).toHaveBeenCalledWith(
|
|
104
|
+
baseConfig.screenConfig,
|
|
105
|
+
baseConfig.entry
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("resolves to null when playerPluginId is missing", async () => {
|
|
110
|
+
expect(
|
|
111
|
+
await playerFactory({ ...baseConfig, playerPluginId: "" } as any)
|
|
112
|
+
).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("resolves to null when appStore has no plugins", async () => {
|
|
116
|
+
mockAppStoreGet.mockReturnValue(null);
|
|
117
|
+
|
|
118
|
+
expect(await playerFactory(baseConfig)).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("resolves to null when the plugin has no playerProtocol", async () => {
|
|
122
|
+
mockAppStoreGet.mockImplementation((key: string) =>
|
|
123
|
+
key === "plugins" ? { "test-plugin": {} } : null
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
mockFindPluginByIdentifier.mockReturnValue({ module: {} });
|
|
127
|
+
|
|
128
|
+
expect(await playerFactory(baseConfig)).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("resolves to null when playerProtocol returns without a Component", async () => {
|
|
132
|
+
installPluginWithProtocol({ controllerClass: FakeController });
|
|
133
|
+
|
|
134
|
+
expect(await playerFactory(baseConfig)).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("resolves to null when playerProtocol returns without a controllerClass", async () => {
|
|
138
|
+
installPluginWithProtocol({ Component: fakeComponent });
|
|
139
|
+
|
|
140
|
+
expect(await playerFactory(baseConfig)).toBeNull();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("rejects when playerProtocol throws synchronously", async () => {
|
|
144
|
+
installPluginWithProtocol(() => {
|
|
145
|
+
throw new Error("boom");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await expect(playerFactory(baseConfig)).rejects.toThrow("boom");
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -13,57 +13,41 @@ type PlayerFactoryProps = {
|
|
|
13
13
|
playerId: string;
|
|
14
14
|
autoplay: boolean;
|
|
15
15
|
entry: ZappEntry;
|
|
16
|
+
muted: boolean;
|
|
16
17
|
playerPluginId: string;
|
|
17
18
|
screenConfig: Record<string, any>;
|
|
18
19
|
playerRole: PlayerRole;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
interface
|
|
22
|
+
interface PlayerControllerConstructor {
|
|
22
23
|
new (params: any): Player;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
type PlayerProtocol = {
|
|
27
|
+
Component: any;
|
|
28
|
+
controllerClass: PlayerControllerConstructor;
|
|
29
|
+
};
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
export const playerFactory = async (
|
|
32
|
+
config: PlayerFactoryProps
|
|
33
|
+
): Promise<PlayerFactoryItem | null> => {
|
|
34
|
+
if (!config?.playerPluginId) return null;
|
|
33
35
|
|
|
34
36
|
const plugins = appStore.get("plugins");
|
|
37
|
+
if (!plugins) return null;
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const playerPlugin = findPluginByIdentifier(IDENTIFIER, plugins);
|
|
39
|
+
const playerPlugin = findPluginByIdentifier(config.playerPluginId, plugins);
|
|
40
|
+
if (!playerPlugin?.module?.playerProtocol) return null;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const playerProtocol: PlayerConstructor = playerPlugin.module.playerProtocol(
|
|
47
|
-
config?.screenConfig,
|
|
48
|
-
config?.entry
|
|
49
|
-
);
|
|
42
|
+
const playerProtocol: PlayerProtocol | null =
|
|
43
|
+
await playerPlugin.module.playerProtocol(config.screenConfig, config.entry);
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!playerView) {
|
|
45
|
+
if (!playerProtocol?.Component || !playerProtocol.controllerClass) {
|
|
54
46
|
return null;
|
|
55
47
|
}
|
|
56
48
|
|
|
57
|
-
const Controller = (playerProtocol as any)?.controllerClass || null;
|
|
58
|
-
|
|
59
|
-
if (Controller === null) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const controller = new Controller(config);
|
|
64
|
-
|
|
65
49
|
return {
|
|
66
|
-
controller,
|
|
67
|
-
Component:
|
|
50
|
+
controller: new playerProtocol.controllerClass(config),
|
|
51
|
+
Component: playerProtocol.Component,
|
|
68
52
|
};
|
|
69
53
|
};
|
|
@@ -308,6 +308,39 @@ const generalContent = () => ({
|
|
|
308
308
|
key: "pull_to_refresh_enabled",
|
|
309
309
|
initial_value: false,
|
|
310
310
|
},
|
|
311
|
+
{
|
|
312
|
+
type: "switch",
|
|
313
|
+
label: "Allow to use this screen as a hook",
|
|
314
|
+
label_tooltip: "Make sure that screen uses 'finishHook' action or performs navigation action to exit the screen after performing the hook action, or user will be stuck on the screen", // eslint-disable-line max-len
|
|
315
|
+
key: "available_as_hook",
|
|
316
|
+
initial_value: false,
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
type: "data_source_selector",
|
|
320
|
+
label: "Skip hook endpoint",
|
|
321
|
+
key: "skip_hook_endpoint",
|
|
322
|
+
label_tooltip:
|
|
323
|
+
"Endpoint if set will check with server if hook should be skipped",
|
|
324
|
+
conditional_fields: [
|
|
325
|
+
{
|
|
326
|
+
key: "rules/available_as_hook",
|
|
327
|
+
condition_value: true,
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
key: "skip_hook_storage_key",
|
|
333
|
+
type: "text_input",
|
|
334
|
+
label: "Hook will be skipped if storage key is set",
|
|
335
|
+
initial_value: "",
|
|
336
|
+
tooltip_text: "key.namespace format",
|
|
337
|
+
conditional_fields: [
|
|
338
|
+
{
|
|
339
|
+
key: "rules/available_as_hook",
|
|
340
|
+
condition_value: true,
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
311
344
|
],
|
|
312
345
|
},
|
|
313
346
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.4342281394",
|
|
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-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.4342281394",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
package/playerUtils/index.ts
CHANGED
|
@@ -9,6 +9,16 @@ import { Dimensions } from "react-native";
|
|
|
9
9
|
|
|
10
10
|
export { getPlayerActionButtons } from "./getPlayerActionButtons";
|
|
11
11
|
|
|
12
|
+
export const HLS_MIME_TYPES = [
|
|
13
|
+
"application/x-mpegURL",
|
|
14
|
+
"application/vnd.apple.mpegurl",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const STREAMING_VIDEO_MIME_TYPES = [
|
|
18
|
+
...HLS_MIME_TYPES,
|
|
19
|
+
"application/dash+xml",
|
|
20
|
+
];
|
|
21
|
+
|
|
12
22
|
/**
|
|
13
23
|
* Gets duration value from player manager, and from extensions
|
|
14
24
|
* then checks whether the value from either is a not a valid number
|
|
@@ -80,6 +90,16 @@ export function isLive(entry: ZappEntry): boolean {
|
|
|
80
90
|
return isEntryLive(entry) || isLiveByManager();
|
|
81
91
|
}
|
|
82
92
|
|
|
93
|
+
export const isVideoItem = (item: Option<ZappEntry>) => {
|
|
94
|
+
const contentType = item?.content?.type;
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
isString(contentType) &&
|
|
98
|
+
(contentType.includes("video") ||
|
|
99
|
+
STREAMING_VIDEO_MIME_TYPES.includes(contentType))
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
83
103
|
export const isAudioItem = (item: Option<ZappEntry>) => {
|
|
84
104
|
if (
|
|
85
105
|
isString(item?.content?.type) &&
|