@takeoffmedia/react-native-penthera 0.3.7 → 0.4.0
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/android/src/main/java/com/takeoffmediareactnativepenthera/AssetQueueObserver.kt +12 -5
- package/android/src/main/java/com/takeoffmediareactnativepenthera/virtuoso/OfflineVideoEngine.kt +24 -14
- package/android/src/main/java/com/takeoffmediareactnativepenthera/virtuoso/notification/NotificationFactory.kt +6 -3
- package/ios/Catalog.swift +11 -1
- package/ios/Penthera.swift +92 -19
- package/ios/Penthera.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/Penthera.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/Penthera.xcodeproj/project.xcworkspace/xcuserdata/joseguerreroot.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Penthera.xcodeproj/xcuserdata/joseguerreroot.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +104 -0
- package/ios/Penthera.xcodeproj/xcuserdata/joseguerreroot.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/hooks/usePenthera/usePenthera.js +38 -17
- package/lib/commonjs/hooks/usePenthera/usePenthera.js.map +1 -1
- package/lib/commonjs/hooks/usePenthera/usePentheraInit.js +1 -0
- package/lib/commonjs/hooks/usePenthera/usePentheraInit.js.map +1 -1
- package/lib/module/hooks/usePenthera/usePenthera.js +38 -17
- package/lib/module/hooks/usePenthera/usePenthera.js.map +1 -1
- package/lib/module/hooks/usePenthera/usePentheraInit.js +1 -0
- package/lib/module/hooks/usePenthera/usePentheraInit.js.map +1 -1
- package/lib/typescript/hooks/usePenthera/usePenthera.d.ts.map +1 -1
- package/lib/typescript/hooks/usePenthera/usePenthera.types.d.ts +11 -1
- package/lib/typescript/hooks/usePenthera/usePenthera.types.d.ts.map +1 -1
- package/lib/typescript/hooks/usePenthera/usePentheraInit.d.ts.map +1 -1
- package/lib/typescript/interface/PentheraTypes.d.ts +3 -1
- package/lib/typescript/interface/PentheraTypes.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/usePenthera/usePenthera.tsx +152 -126
- package/src/hooks/usePenthera/usePenthera.types.ts +12 -1
- package/src/hooks/usePenthera/usePentheraInit.tsx +6 -7
- package/src/interface/PentheraTypes.ts +3 -1
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
PentheraState,
|
|
5
5
|
PentheraAction,
|
|
6
6
|
InterfaceDataPlay,
|
|
7
|
+
AssetError,
|
|
7
8
|
} from './usePenthera.types';
|
|
8
9
|
import {
|
|
9
10
|
deleteMany,
|
|
@@ -15,136 +16,161 @@ import {
|
|
|
15
16
|
} from '../../nativeModules';
|
|
16
17
|
import type { PentheraTypes } from '../../interface/PentheraTypes';
|
|
17
18
|
|
|
18
|
-
export const usePenthera = create<PentheraState & PentheraAction>(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
loadAssets: (assets: PentheraState['assets']) =>
|
|
27
|
-
set(() => ({
|
|
28
|
-
assets,
|
|
29
|
-
})),
|
|
30
|
-
addAsset: (asset) =>
|
|
31
|
-
set((state) => ({
|
|
32
|
-
assets: [...state.assets, asset],
|
|
33
|
-
})),
|
|
34
|
-
updateAssetsProgress: (progress) =>
|
|
35
|
-
set((state) => {
|
|
36
|
-
return {
|
|
37
|
-
assetsProgress: {
|
|
38
|
-
...state.assetsProgress,
|
|
39
|
-
...progress,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}),
|
|
43
|
-
updateAssetCompleted: (assetID: string) => {
|
|
44
|
-
set((state) => {
|
|
45
|
-
const assets = state.assets.map((item) => {
|
|
46
|
-
if (item.id === assetID) {
|
|
47
|
-
return { ...item, isCompleted: true };
|
|
48
|
-
}
|
|
49
|
-
return item;
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
19
|
+
export const usePenthera = create<PentheraState & PentheraAction>(
|
|
20
|
+
(set, get) => ({
|
|
21
|
+
assets: [],
|
|
22
|
+
assetsProgress: {},
|
|
23
|
+
assetError: [],
|
|
24
|
+
assetsPending: [],
|
|
25
|
+
loadAssets: (assets: PentheraState['assets']) =>
|
|
26
|
+
set(() => ({
|
|
52
27
|
assets,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
28
|
+
})),
|
|
29
|
+
addAsset: (asset) =>
|
|
30
|
+
set((state) => ({
|
|
31
|
+
assets: [...state.assets, asset],
|
|
32
|
+
})),
|
|
33
|
+
updateAssetsProgress: (progress) =>
|
|
34
|
+
set((state) => {
|
|
35
|
+
return {
|
|
36
|
+
assetsProgress: {
|
|
37
|
+
...state.assetsProgress,
|
|
38
|
+
...progress,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
updateAssetCompleted: (assetID: string) => {
|
|
43
|
+
set((state) => {
|
|
44
|
+
const assets = state.assets.map((item) => {
|
|
45
|
+
if (item.id === assetID) {
|
|
46
|
+
return { ...item, isCompleted: true };
|
|
47
|
+
}
|
|
48
|
+
return item;
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
assets,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
onGetAllAssets: async () => {
|
|
56
|
+
try {
|
|
57
|
+
const assets: PentheraTypes.ItemCatalog[] = await getDownloads('');
|
|
58
|
+
if (Array.isArray(assets)) {
|
|
59
|
+
const uniqueAssets = assets.filter(
|
|
60
|
+
(item, index, self) =>
|
|
61
|
+
self.findIndex((i) => i.id === item.id) === index
|
|
62
|
+
);
|
|
63
|
+
return set(() => ({
|
|
64
|
+
assets: uniqueAssets,
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.log('error in getDownloads', error);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
onDownload: async ({ item, url, drm }) => {
|
|
72
|
+
try {
|
|
73
|
+
await download(JSON.stringify({ item, url, drm }));
|
|
74
|
+
return set((state) => ({
|
|
75
|
+
assets: [...state.assets, { ...item, id: item.data.mediaId }],
|
|
76
|
+
assetsPending: state.assetsPending.filter(
|
|
77
|
+
(asset) => asset.id !== item.data.mediaId
|
|
78
|
+
),
|
|
66
79
|
}));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('error: downloadAsset', error);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
deleteMany: async (assetIds: string[]) => {
|
|
85
|
+
try {
|
|
86
|
+
const vpids = assetIds.map((assetId) =>
|
|
87
|
+
get().getVpidByMediaId(assetId)
|
|
88
|
+
);
|
|
89
|
+
const response = await deleteMany(vpids);
|
|
90
|
+
const vpidsDeleted = Object.keys(response).filter(
|
|
91
|
+
(item) => response[item]
|
|
92
|
+
);
|
|
93
|
+
const deleted = vpidsDeleted.map((assetId) =>
|
|
94
|
+
get().getMediaIdByVpid(assetId)
|
|
95
|
+
);
|
|
96
|
+
return set((state) => {
|
|
97
|
+
const updatedAssetsProgress = { ...state.assetsProgress };
|
|
98
|
+
deleted.forEach((assetId: string) => {
|
|
99
|
+
if (state) {
|
|
100
|
+
delete updatedAssetsProgress[assetId];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
assets: state.assets.filter(
|
|
105
|
+
(asset) => !deleted.includes(asset.id as string)
|
|
106
|
+
),
|
|
107
|
+
assetsProgress: updatedAssetsProgress,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Error: deleteMany', error);
|
|
67
112
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
113
|
+
},
|
|
114
|
+
onPauseDownload: async (assetId: string) => {
|
|
115
|
+
await pauseDownload(assetId);
|
|
116
|
+
},
|
|
117
|
+
onPlayVideo: async (assetId: string) => {
|
|
118
|
+
try {
|
|
119
|
+
const vpid = get().getVpidByMediaId(assetId);
|
|
120
|
+
const response: InterfaceDataPlay = await playAsset(vpid);
|
|
121
|
+
return response;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.log('error in onPlayVideo', error);
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
setError: (dataError: AssetError) => {
|
|
128
|
+
return set((state) => {
|
|
129
|
+
const assetIdExists = state.assetError.some(
|
|
130
|
+
(error) => error.assetId === dataError.assetId
|
|
131
|
+
);
|
|
132
|
+
if (!assetIdExists) {
|
|
133
|
+
return {
|
|
134
|
+
assetError: [...state.assetError, { ...dataError }],
|
|
135
|
+
assetsProgress: {},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return state;
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
removeError: (assetIdToRemove: string) => {
|
|
75
142
|
return set((state) => ({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
143
|
+
assetError: state.assetError.filter(
|
|
144
|
+
(error) => error.assetId !== assetIdToRemove
|
|
145
|
+
),
|
|
146
|
+
assetsProgress: {},
|
|
147
|
+
}));
|
|
148
|
+
},
|
|
149
|
+
setConfigParameters: async (data) => {
|
|
150
|
+
await configParameters(JSON.stringify(data));
|
|
151
|
+
},
|
|
152
|
+
clearAssetProgress: () => {
|
|
153
|
+
return set(() => ({
|
|
154
|
+
assetsProgress: {},
|
|
155
|
+
}));
|
|
156
|
+
},
|
|
157
|
+
setAssetPending: (asset: PentheraTypes.ItemCatalog) => {
|
|
158
|
+
set((state) => ({
|
|
159
|
+
assetsPending: [...state.assetsPending, asset],
|
|
160
|
+
}));
|
|
161
|
+
},
|
|
162
|
+
removeAssetPending: (assetId: string) => {
|
|
163
|
+
set((state) => ({
|
|
81
164
|
assetsPending: state.assetsPending.filter(
|
|
82
|
-
(asset) => asset.id !==
|
|
165
|
+
(asset) => asset.id !== assetId
|
|
83
166
|
),
|
|
84
167
|
}));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return set((state) => {
|
|
95
|
-
const updatedAssetsProgress = { ...state.assetsProgress };
|
|
96
|
-
deleted.forEach((assetId: string) => {
|
|
97
|
-
if (state) {
|
|
98
|
-
delete updatedAssetsProgress[assetId];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
assets: state.assets.filter(
|
|
103
|
-
(asset) => !deleted.includes(asset.id as string)
|
|
104
|
-
),
|
|
105
|
-
assetsProgress: updatedAssetsProgress,
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error('Error: deleteMany', error);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
onPauseDownload: async (assetId: string) => {
|
|
113
|
-
await pauseDownload(assetId);
|
|
114
|
-
},
|
|
115
|
-
onPlayVideo: async (assetId: string) => {
|
|
116
|
-
try {
|
|
117
|
-
const response: InterfaceDataPlay = await playAsset(assetId);
|
|
118
|
-
return response;
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.log('error in onPlayVideo', error);
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
setError: (dataParse) => {
|
|
125
|
-
return set(() => ({
|
|
126
|
-
assetError: dataParse,
|
|
127
|
-
assetsProgress: {},
|
|
128
|
-
}));
|
|
129
|
-
},
|
|
130
|
-
setConfigParameters: async (data) => {
|
|
131
|
-
await configParameters(JSON.stringify(data));
|
|
132
|
-
},
|
|
133
|
-
clearAssetProgress: () => {
|
|
134
|
-
return set(() => ({
|
|
135
|
-
assetsProgress: {},
|
|
136
|
-
}));
|
|
137
|
-
},
|
|
138
|
-
setAssetPending: (asset: PentheraTypes.ItemCatalog) => {
|
|
139
|
-
set((state) => ({
|
|
140
|
-
assetsPending: [...state.assetsPending, asset],
|
|
141
|
-
}));
|
|
142
|
-
},
|
|
143
|
-
removeAssetPending: (assetId: string) => {
|
|
144
|
-
set((state) => ({
|
|
145
|
-
assetsPending: state.assetsPending.filter(
|
|
146
|
-
(asset) => asset.id !== assetId
|
|
147
|
-
),
|
|
148
|
-
}));
|
|
149
|
-
},
|
|
150
|
-
}));
|
|
168
|
+
},
|
|
169
|
+
getVpidByMediaId: (mediaId: string) =>
|
|
170
|
+
get().assets.find((item) => item.data.mediaId === mediaId)?.data?.vpid ??
|
|
171
|
+
'',
|
|
172
|
+
getMediaIdByVpid: (vpid: string) =>
|
|
173
|
+
get().assets?.find((item) => item.data.vpid === vpid)?.data?.mediaId ??
|
|
174
|
+
'',
|
|
175
|
+
})
|
|
176
|
+
);
|
|
@@ -24,6 +24,13 @@ export type Subtitle = {
|
|
|
24
24
|
language: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
export interface InfoVideoPlayer {
|
|
28
|
+
advisoryClassification: string;
|
|
29
|
+
advisoryDescription: string;
|
|
30
|
+
description: string;
|
|
31
|
+
title: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
export interface InterfaceDataPlay {
|
|
28
35
|
url?: string;
|
|
29
36
|
license?: string;
|
|
@@ -33,12 +40,13 @@ export interface InterfaceDataPlay {
|
|
|
33
40
|
js?: string;
|
|
34
41
|
css?: string;
|
|
35
42
|
hasZoom?: boolean;
|
|
43
|
+
infoVideoPlayer?: InfoVideoPlayer;
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export type PentheraState = {
|
|
39
47
|
assets: PentheraTypes.ItemCatalog[] | [];
|
|
40
48
|
assetsProgress: AssetProgress | {};
|
|
41
|
-
assetError: AssetError;
|
|
49
|
+
assetError: AssetError[] | [];
|
|
42
50
|
assetsPending: PentheraTypes.ItemCatalog[] | [];
|
|
43
51
|
};
|
|
44
52
|
|
|
@@ -69,6 +77,9 @@ export type PentheraAction = {
|
|
|
69
77
|
updateAssetCompleted: (assetID: string) => void;
|
|
70
78
|
setAssetPending: (assets: PentheraTypes.ItemCatalog) => void;
|
|
71
79
|
removeAssetPending: (assetID: string) => void;
|
|
80
|
+
removeError: (id: string) => void;
|
|
81
|
+
getVpidByMediaId: (mediaId: string) => string;
|
|
82
|
+
getMediaIdByVpid: (vpid: string) => string;
|
|
72
83
|
};
|
|
73
84
|
|
|
74
85
|
export type Event = {
|
|
@@ -109,7 +109,6 @@ export function usePentheraInit({
|
|
|
109
109
|
]);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
113
112
|
export function usePentheraInitV2() {
|
|
114
113
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
115
114
|
const updateAssetsProgress = usePenthera(
|
|
@@ -164,17 +163,17 @@ export function usePentheraInitV2() {
|
|
|
164
163
|
}
|
|
165
164
|
};
|
|
166
165
|
const event = eventEmitter.addListener('penthera', sessionConnect);
|
|
167
|
-
|
|
166
|
+
|
|
168
167
|
onGetAllAssets();
|
|
169
168
|
|
|
170
169
|
return () => {
|
|
171
170
|
event.remove();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
};
|
|
172
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
+
}, [isInitialized]);
|
|
175
174
|
|
|
176
175
|
return {
|
|
177
176
|
isInitialized,
|
|
178
|
-
setIsInitialized
|
|
179
|
-
}
|
|
177
|
+
setIsInitialized,
|
|
178
|
+
};
|
|
180
179
|
}
|
|
@@ -11,7 +11,7 @@ export declare namespace PentheraTypes {
|
|
|
11
11
|
drm: boolean | string;
|
|
12
12
|
thumbnails?: Thumbnails;
|
|
13
13
|
subtitles?: Subtitles;
|
|
14
|
-
data
|
|
14
|
+
data: DataItem;
|
|
15
15
|
isCompleted?: boolean;
|
|
16
16
|
download_percentage?: number;
|
|
17
17
|
isPaused?: boolean;
|
|
@@ -53,6 +53,8 @@ export declare namespace PentheraTypes {
|
|
|
53
53
|
isExpired?: boolean;
|
|
54
54
|
effectiveExpiryDate?: string;
|
|
55
55
|
expiryDate?: string;
|
|
56
|
+
mediaId: string;
|
|
57
|
+
vpid: string;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
export interface Classification {
|