@signageos/front-applet 8.1.3 → 8.1.4
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/dist/bundle.js.map +1 -1
- package/docs/sos/browser.md +17 -17
- package/docs/sos/command.md +6 -6
- package/docs/sos/debug.md +7 -3
- package/docs/sos/deviceInfo.md +6 -2
- package/docs/sos/display.md +3 -3
- package/docs/sos/fileSystem.md +67 -67
- package/docs/sos/hardware/barcodeScanner.md +58 -15
- package/docs/sos/hardware/index.md +72 -15
- package/docs/sos/hardware/led.md +32 -3
- package/docs/sos/index.md +3 -3
- package/docs/sos/input.md +7 -7
- package/docs/sos/monitors.md +8 -0
- package/docs/sos/native/mdc.md +9 -9
- package/docs/sos/offline/cache.md +368 -28
- package/docs/sos/offline/index.md +127 -24
- package/docs/sos/osd.md +8 -1
- package/docs/sos/proofOfPlay.md +28 -0
- package/docs/sos/stream.md +78 -78
- package/docs/sos/sync.md +228 -21
- package/docs/sos/video.md +73 -73
- package/docs/sos_management/app.md +11 -11
- package/docs/sos_management/audio.md +3 -3
- package/docs/sos_management/firmware.md +11 -11
- package/docs/sos_management/index.md +9 -9
- package/docs/sos_management/network.md +10 -10
- package/docs/sos_management/package.md +6 -6
- package/docs/sos_management/power.md +27 -27
- package/docs/sos_management/screen.md +17 -17
- package/docs/sos_management/security.md +3 -3
- package/docs/sos_management/time.md +8 -8
- package/docs/sos_management/wifi.md +12 -12
- package/es6/FrontApplet/Debug/Debug.d.ts +1 -1
- package/es6/FrontApplet/Debug/Debug.js +1 -1
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.d.ts +6 -2
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.js +6 -2
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.js.map +1 -1
- package/es6/FrontApplet/Display/Display.d.ts +1 -1
- package/es6/FrontApplet/Display/Display.js +1 -1
- package/es6/FrontApplet/Hardware/BarcodeScanner/BarcodeScanner.d.ts +36 -8
- package/es6/FrontApplet/Hardware/BarcodeScanner/BarcodeScanner.js +34 -2
- package/es6/FrontApplet/Hardware/BarcodeScanner/BarcodeScanner.js.map +1 -1
- package/es6/FrontApplet/Hardware/BarcodeScanner/IBarcodeScanner.d.ts +5 -0
- package/es6/FrontApplet/Hardware/Hardware.d.ts +34 -5
- package/es6/FrontApplet/Hardware/Hardware.js +33 -5
- package/es6/FrontApplet/Hardware/Hardware.js.map +1 -1
- package/es6/FrontApplet/Hardware/ISerialPort.d.ts +17 -1
- package/es6/FrontApplet/Hardware/ISerialPortDataMessage.d.ts +3 -0
- package/es6/FrontApplet/Hardware/ISerialPortOptions.d.ts +6 -0
- package/es6/FrontApplet/Hardware/ISerialPortOptions.js +3 -0
- package/es6/FrontApplet/Hardware/ISerialPortOptions.js.map +1 -1
- package/es6/FrontApplet/Hardware/Led/Led.d.ts +19 -3
- package/es6/FrontApplet/Hardware/Led/Led.js +19 -3
- package/es6/FrontApplet/Hardware/Led/Led.js.map +1 -1
- package/es6/FrontApplet/Monitors/Monitors.d.ts +5 -0
- package/es6/FrontApplet/Monitors/Monitors.js +5 -0
- package/es6/FrontApplet/Monitors/Monitors.js.map +1 -1
- package/es6/FrontApplet/NativeCommands/MDC/INativeMdcCommands.d.ts +1 -0
- package/es6/FrontApplet/OSD/OSD.d.ts +5 -1
- package/es6/FrontApplet/OSD/OSD.js +5 -1
- package/es6/FrontApplet/OSD/OSD.js.map +1 -1
- package/es6/FrontApplet/Offline/Cache/Cache.d.ts +205 -28
- package/es6/FrontApplet/Offline/Cache/Cache.js +205 -28
- package/es6/FrontApplet/Offline/Cache/Cache.js.map +1 -1
- package/es6/FrontApplet/Offline/IAddFont.js.map +1 -1
- package/es6/FrontApplet/Offline/IFileType.js.map +1 -1
- package/es6/FrontApplet/Offline/ISaveFile.d.ts +3 -0
- package/es6/FrontApplet/Offline/ISaveFile.js.map +1 -1
- package/es6/FrontApplet/Offline/Offline.d.ts +58 -15
- package/es6/FrontApplet/Offline/Offline.js +56 -13
- package/es6/FrontApplet/Offline/Offline.js.map +1 -1
- package/es6/FrontApplet/ProofOfPlay/IRecordItemOptions.d.ts +3 -0
- package/es6/FrontApplet/ProofOfPlay/ProofOfPlay.d.ts +15 -1
- package/es6/FrontApplet/ProofOfPlay/ProofOfPlay.js +15 -1
- package/es6/FrontApplet/ProofOfPlay/ProofOfPlay.js.map +1 -1
- package/es6/FrontApplet/Sync/Sync.d.ts +101 -18
- package/es6/FrontApplet/Sync/Sync.js +84 -10
- package/es6/FrontApplet/Sync/Sync.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,15 +8,14 @@ const ErrorCodes_1 = __importDefault(require("../../Error/ErrorCodes"));
|
|
|
8
8
|
const AppletOfflineCacheError_1 = __importDefault(require("../../Error/AppletOfflineCacheError"));
|
|
9
9
|
const Validate_1 = __importDefault(require("../../Validate/Validate"));
|
|
10
10
|
/**
|
|
11
|
-
* The `sos.offline` API groups together methods used to download and save arbitrary files, which can be accessed even if the device is offline.
|
|
11
|
+
* The `sos.offline.cache` API groups together methods used to download and save arbitrary files, which can be accessed even if the device is offline.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* > Please refer to difference between `sos.offline.cache` and `sos.fileSystem` APIs in our [documentation](http://localhost:3000/sdk/sos/offline/).
|
|
14
14
|
*
|
|
15
|
+
* :::warning
|
|
15
16
|
* Emulator has certain limitations while handling offline files. [Read more here](https://docs.signageos.io/hc/en-us/articles/4405238997138)
|
|
16
|
-
*
|
|
17
17
|
* :::
|
|
18
18
|
*
|
|
19
|
-
* @tutorial https://developers.signageos.io/docs/applets/api-guides/offline-content#caching-audio-visual-content-or-arbitrary-data-sosofflinecache
|
|
20
19
|
*/
|
|
21
20
|
class Cache {
|
|
22
21
|
messagePrefix;
|
|
@@ -32,9 +31,20 @@ class Cache {
|
|
|
32
31
|
this.savedContents = {};
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
|
-
* The `listFiles()` method list all currently cached files.
|
|
34
|
+
* The `listFiles()` method list all currently cached files in internal storage, which was previously saved by `saveFile()` or `loadOrSaveFile()` methods.
|
|
36
35
|
*
|
|
36
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of unique identifiers (uids) of the saved files.
|
|
37
|
+
* @throws Error If any error occurs during listing files.
|
|
38
|
+
* @throws Error If the files cannot be listed.
|
|
37
39
|
* @since 2.0.0
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* await sos.offline.cache.saveFile('example-file.mp4', 'https://example.com/path/to/your/file.mp4');
|
|
43
|
+
* await sos.offline.cache.saveFile('another-file.jpg', 'https://example.com/path/to/your/image.jpg');
|
|
44
|
+
*
|
|
45
|
+
* // Later list the saved files
|
|
46
|
+
* const files = await sos.offline.cache.listFiles();
|
|
47
|
+
* console.log('Saved files:', files); // Output: Saved files: ['example-file.mp4', 'another-file.jpg']
|
|
38
48
|
*/
|
|
39
49
|
async listFiles() {
|
|
40
50
|
const response = await this.postMessage({
|
|
@@ -45,9 +55,18 @@ class Cache {
|
|
|
45
55
|
/**
|
|
46
56
|
* The `loadFile()` method loads cached file, which was previously saved by `saveFile()` or `loadOrSaveFile()` methods.
|
|
47
57
|
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
58
|
+
* @param uid Unique identifier of the file to be loaded.
|
|
59
|
+
* @returns {Promise<IFile>} A promise that resolves to the loaded file.
|
|
60
|
+
* @throws Error If the uid is not a valid string.
|
|
61
|
+
* @throws Error If the uid does not exist
|
|
50
62
|
* @since 1.0.3
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Save a file
|
|
66
|
+
* await sos.offline.cache.saveFile('example-file.mp4', 'https://example.com/path/to/your/file.mp4');
|
|
67
|
+
* // Later load the file
|
|
68
|
+
* const file = await sos.offline.cache.loadFile('example-file.mp4');
|
|
69
|
+
* console.log('Loaded file:', file); // Output: Loaded file: { uid: 'example-file.mp4', uri: 'file://path/to/your/file.mp4' }
|
|
51
70
|
*/
|
|
52
71
|
async loadFile(uid) {
|
|
53
72
|
(0, Validate_1.default)({ uid }).required().string();
|
|
@@ -59,17 +78,35 @@ class Cache {
|
|
|
59
78
|
return response.loadedFile;
|
|
60
79
|
}
|
|
61
80
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* :::warning
|
|
65
|
-
*
|
|
66
|
-
* `uid` should have the same file extension (e.g.: mp4, svg, jpg) as the original file.
|
|
81
|
+
* Method `saveFile()` is used to save files from remote a destination into the device internal memory.
|
|
67
82
|
*
|
|
83
|
+
* :::info
|
|
84
|
+
* - Local device file path differs from device to device. It can point to `file://` or `http://localhost` etc.
|
|
68
85
|
* :::
|
|
69
86
|
*
|
|
70
|
-
*
|
|
87
|
+
* :::warning
|
|
88
|
+
* - headers has to be a JSON object. If you are passing the value, make sure you use JSON.parse().
|
|
89
|
+
* - `uid` should have the same file extension (e.g.: mp4, svg, jpg) as the original file.
|
|
90
|
+
* :::
|
|
71
91
|
*
|
|
92
|
+
* @param uid Unique identifier of the file to be saved.
|
|
93
|
+
* @param uri URI of the file to be downloaded.
|
|
94
|
+
* @param headers Key, value pairs of HTTP headers to send along with the request. Used when the target file is protected by a password or if any other specific headers are needed to access it.
|
|
95
|
+
* @throws Error If the network request fails.
|
|
96
|
+
* @throws Error If the uid is not a valid string.
|
|
97
|
+
* @throws Error If the uri is not a valid URI.
|
|
98
|
+
* @throws Error File with the same uid is already cached.
|
|
99
|
+
* @throws Error If the headers are not a valid object with string values.
|
|
72
100
|
* @since 1.0.3
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* await sos.offline.cache.saveFile('example-file.mp4', 'https://example.com/path/to/your/file.mp4')
|
|
104
|
+
* .then(() => {
|
|
105
|
+
* console.log('File saved successfully');
|
|
106
|
+
* })
|
|
107
|
+
* .catch((error) => {
|
|
108
|
+
* console.error('Error saving file:', error);
|
|
109
|
+
* });
|
|
73
110
|
*/
|
|
74
111
|
async saveFile(uid, uri, headers) {
|
|
75
112
|
this.checkUidValidity(uid);
|
|
@@ -89,9 +126,39 @@ class Cache {
|
|
|
89
126
|
this.savedFiles[uid] = response.savedFile;
|
|
90
127
|
}
|
|
91
128
|
/**
|
|
92
|
-
*
|
|
129
|
+
* Method `loadOrSaveFile()` is used for individual file retrieval & save in case when file is not saved in local storage yet. To get file from internal memory & save it when not yet exists we prepared `loadOrSaveFile()` method.
|
|
130
|
+
*
|
|
131
|
+
* :::info
|
|
132
|
+
* - The file URI has to return the file. If your URI leads to a 303 redirect (e.g. from http to https), the API will not work.
|
|
133
|
+
* - Emulator has certain limitations while handling offline files. [Read more here](https://docs.signageos.io/hc/en-us/articles/4405238997138).
|
|
134
|
+
* - Local device file path differs from device to device. It can point to `file://` or `http://localhost` etc.
|
|
135
|
+
* :::
|
|
136
|
+
*
|
|
137
|
+
* :::warning
|
|
138
|
+
* `uid` should have the same file extension (e.g.: mp4, svg, jpg) as the original file
|
|
139
|
+
* :::
|
|
93
140
|
*
|
|
141
|
+
* @param uid Unique identifier of the file to be loaded or saved.
|
|
142
|
+
* @param uri URI of the file to be downloaded if not cached.
|
|
143
|
+
* @param headers Key, value pairs of HTTP headers to send along with the request. Used when the target file is protected by a password or if any other specific headers are needed to access it.
|
|
144
|
+
* @returns {Promise<IFile>} A promise that resolves to the loaded or saved file.
|
|
145
|
+
* @throws Error If the uid is not a valid string.
|
|
146
|
+
* @throws Error If the uri is not a valid URI.
|
|
147
|
+
* @throws Error If the headers are not a valid object with string values.
|
|
148
|
+
* @throws Error If the file cannot be loaded or saved.
|
|
149
|
+
* @throws AppletOfflineCacheError If the headers are not valid.
|
|
94
150
|
* @since 1.0.9
|
|
151
|
+
* @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/offline-files | Example Applet with Offline Files}
|
|
152
|
+
* @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/video-loop-offline | Example Applet with Video Loop Offline}
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* await sos.offline.cache.loadOrSaveFile('example-file.mp4', 'https://example.com/path/to/your/file.mp4')
|
|
156
|
+
* .then((file) => {
|
|
157
|
+
* console.log('File loaded or saved:', file);
|
|
158
|
+
* })
|
|
159
|
+
* .catch((error) => {
|
|
160
|
+
* console.error('Error loading or saving file:', error);
|
|
161
|
+
* });
|
|
95
162
|
*/
|
|
96
163
|
async loadOrSaveFile(uid, uri, headers) {
|
|
97
164
|
(0, Validate_1.default)({ uid }).required().string();
|
|
@@ -110,11 +177,19 @@ class Cache {
|
|
|
110
177
|
}
|
|
111
178
|
}
|
|
112
179
|
/**
|
|
113
|
-
* The `deleteFile()` method removes the file specified by `uid
|
|
180
|
+
* The `deleteFile()` method removes the file specified by `uid` from cache storage.
|
|
114
181
|
*
|
|
182
|
+
* @param uid Unique identifier of the file to be deleted.
|
|
183
|
+
* @returns {Promise<void>} A promise that resolves when the file is deleted.
|
|
184
|
+
* @throws Error If the uid is not a valid string.
|
|
185
|
+
* @throws Error If the uid is not found in the cache.
|
|
115
186
|
* @since 2.0.0
|
|
116
187
|
*
|
|
117
|
-
* @
|
|
188
|
+
* @example
|
|
189
|
+
* // Save a file
|
|
190
|
+
* await sos.offline.cache.saveFile('example-file.mp4', 'https://example.com/path/to/your/file.mp4');
|
|
191
|
+
* // Later delete the file
|
|
192
|
+
* await sos.offline.cache.deleteFile('example-file.mp4');
|
|
118
193
|
*/
|
|
119
194
|
async deleteFile(uid) {
|
|
120
195
|
this.checkUidValidity(uid);
|
|
@@ -127,8 +202,17 @@ class Cache {
|
|
|
127
202
|
/**
|
|
128
203
|
* The `listContent()` method lists all values saved by `saveContent()` method.
|
|
129
204
|
*
|
|
205
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of saved content.
|
|
130
206
|
* @since 2.0.0
|
|
131
|
-
*
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* // Save some content and list all saved contents
|
|
210
|
+
* await sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash');
|
|
211
|
+
* await sos.offline.cache.saveContent('UserToken', 'abc123xyz');
|
|
212
|
+
*
|
|
213
|
+
* // Later list the saved contents
|
|
214
|
+
* const contents = await sos.offline.cache.listContents();
|
|
215
|
+
* console.log('Saved contents:', contents); // Output: Saved contents: ['ApplicationSecret', 'UserToken']
|
|
132
216
|
*/
|
|
133
217
|
async listContents() {
|
|
134
218
|
const response = await this.postMessage({
|
|
@@ -139,8 +223,22 @@ class Cache {
|
|
|
139
223
|
/**
|
|
140
224
|
* The `loadContent()` method gets the value specified by `uid`, which was previously saved by `saveContent()`.
|
|
141
225
|
*
|
|
226
|
+
* @param uid Unique identifier of the content to be loaded.
|
|
227
|
+
* @returns {Promise<string>} A promise that resolves to the loaded content.
|
|
228
|
+
* @throws Error If the uid does not exist.
|
|
229
|
+
* @throws Error If the uid is not a valid string.
|
|
230
|
+
* @throws Error If the content is not a valid string.
|
|
231
|
+
* @throws Error If any other error occurs during loading.
|
|
142
232
|
* @since 1.0.3
|
|
143
|
-
* @tutorial https://developers.signageos.io/docs/
|
|
233
|
+
* @tutorial https://developers.signageos.io/docs/sos-guides/key-value-storage
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* // Previously saved content with uid 'ApplicationSecret'
|
|
237
|
+
* await sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash');
|
|
238
|
+
*
|
|
239
|
+
* // Load the content
|
|
240
|
+
* const content = await sos.offline.cache.loadContent('ApplicationSecret');
|
|
241
|
+
* console.log('Loaded content:', content); // Output: Loaded content: 123SuperSecretHash
|
|
144
242
|
*/
|
|
145
243
|
async loadContent(uid) {
|
|
146
244
|
const response = await this.postMessage({
|
|
@@ -151,10 +249,31 @@ class Cache {
|
|
|
151
249
|
return response.loadedContent;
|
|
152
250
|
}
|
|
153
251
|
/**
|
|
154
|
-
* The `saveContent()` method saves a string value to the cache
|
|
252
|
+
* The `saveContent()` method saves a string value to the cache with specified `uid`.
|
|
155
253
|
*
|
|
254
|
+
* Use when you need to save some data into local memory. This API provides you with approach similar to the HTML5's Local Storage, but implemented internally via native device API and completely device-agnostic.
|
|
255
|
+
*
|
|
256
|
+
* @param uid Unique identifier of the content to be saved.
|
|
257
|
+
* @param content The string content to be saved.
|
|
258
|
+
* @returns {Promise<void>} A promise that resolves when the content is saved.
|
|
259
|
+
* @throws Error If the uid is not a valid string.
|
|
260
|
+
* @throws Error If the content is not a valid string.
|
|
261
|
+
* @throws Error If the uid already exists.
|
|
262
|
+
* @throws Error If any other error occurs during saving.
|
|
156
263
|
* @since 1.0.3
|
|
157
|
-
* @tutorial https://developers.signageos.io/docs/
|
|
264
|
+
* @tutorial https://developers.signageos.io/docs/sos-guides/key-value-storage
|
|
265
|
+
*
|
|
266
|
+
* @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/offline-content | Example of Applet using saveContent()}
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash')
|
|
270
|
+
* .then(() => {
|
|
271
|
+
* //Content was successfully saved, retrieve it.
|
|
272
|
+
* return sos.offline.cache.loadContent('ApplicationSecret');
|
|
273
|
+
* })
|
|
274
|
+
* .then((content) => {
|
|
275
|
+
* console.log('Loaded', content); // print 123SuperSecretHash
|
|
276
|
+
* })
|
|
158
277
|
*/
|
|
159
278
|
async saveContent(uid, content) {
|
|
160
279
|
this.checkUidValidity(uid);
|
|
@@ -167,10 +286,33 @@ class Cache {
|
|
|
167
286
|
this.savedContents[uid] = response.savedContent;
|
|
168
287
|
}
|
|
169
288
|
/**
|
|
170
|
-
* The `deleteContent() method removes the value specified by `uid` key.
|
|
289
|
+
* The `deleteContent()` method removes the value specified by `uid` key from the cache storage.
|
|
171
290
|
*
|
|
291
|
+
* @param uid Unique identifier of the content to be deleted.
|
|
292
|
+
* @returns {Promise<void>} A promise that resolves when the content is deleted.
|
|
293
|
+
* @throws Error If the uid does not exist.
|
|
294
|
+
* @throws Error If the uid is not a valid string.
|
|
295
|
+
* @throws Error If any other error occurs during deletion.
|
|
172
296
|
* @since 2.0.0
|
|
173
|
-
* @tutorial https://developers.signageos.io/docs/
|
|
297
|
+
* @tutorial https://developers.signageos.io/docs/sos-guides/key-value-storage
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* //Store
|
|
301
|
+
* sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash')
|
|
302
|
+
* .then(() => {
|
|
303
|
+
* //Content was successfully saved, retrieve it.
|
|
304
|
+
* return sos.offline.cache.loadContent('ApplicationSecret');
|
|
305
|
+
* })
|
|
306
|
+
* .then((content) => {
|
|
307
|
+
* console.log('Loaded', content); // print 123SuperSecretHash
|
|
308
|
+
*
|
|
309
|
+
* // Let's delete the content now
|
|
310
|
+
* return sos.offline.cache.deleteContent('ApplicationSecret')
|
|
311
|
+
* })
|
|
312
|
+
* .then(() => {
|
|
313
|
+
* console.log("Deleted");
|
|
314
|
+
* })
|
|
315
|
+
* .catch((error) => { console.error(error); });
|
|
174
316
|
*/
|
|
175
317
|
async deleteContent(uid) {
|
|
176
318
|
this.checkUidValidity(uid);
|
|
@@ -183,9 +325,20 @@ class Cache {
|
|
|
183
325
|
/**
|
|
184
326
|
* The `validateChecksumFile()` method validates whether the file, specified by `uid`, has the correct checksum.
|
|
185
327
|
*
|
|
186
|
-
* @
|
|
187
|
-
*
|
|
328
|
+
* @param uid Unique file identifier of a previously downloaded file.
|
|
329
|
+
* @param hash The expected checksum of the file.
|
|
330
|
+
* @param hashType The hashing algorithm to use. Supported algorithms are 'md5' and `crc32`.
|
|
331
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if the checksum is valid, otherwise `false`.
|
|
332
|
+
* @throws Error If the uid does not exist or the hashing algorithm is not supported.
|
|
333
|
+
* @throws Error If the hash is not a valid string.
|
|
334
|
+
* @throws Error If the hashType is not a valid string.
|
|
188
335
|
* @since 2.0.0
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* // Validate the checksum of a file
|
|
339
|
+
* const expectedHash = 'd41d8cd98f00b204e9800998ecf8427e'; // Example MD5 hash
|
|
340
|
+
* // Previously saved file with uid 'example-file.mp4'
|
|
341
|
+
* const isValid = await sos.offline.cache.validateChecksumFile('example-file.mp4', expectedHash, 'md5');
|
|
189
342
|
*/
|
|
190
343
|
async validateChecksumFile(uid, hash, hashType) {
|
|
191
344
|
this.checkUidValidity(uid);
|
|
@@ -202,9 +355,18 @@ class Cache {
|
|
|
202
355
|
/**
|
|
203
356
|
* The `getChecksumFile()` computes a checksum of the file specified by `uid`.
|
|
204
357
|
*
|
|
205
|
-
* @
|
|
206
|
-
*
|
|
358
|
+
* @param uid Unique file identifier of a previously downloaded file.
|
|
359
|
+
* @param hashType The hashing algorithm to use. Supported algorithms are `md5` and `crc32`.
|
|
360
|
+
* @returns {Promise<string>} A promise that resolves to the computed checksum of the file.
|
|
361
|
+
* @throws Error If the uid does not exist.
|
|
362
|
+
* @throws Error If the hashing algorithm is not supported.
|
|
207
363
|
* @since 2.0.0
|
|
364
|
+
*
|
|
365
|
+
* @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/md5-checksum | Example Applet with MD5 Checksum}
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* const checksum = await sos.offline.cache.getChecksumFile('example-file.mp4', 'md5');
|
|
369
|
+
* console.log('MD5 Checksum:', checksum); // Output: MD5 Checksum: d41d8cd98f00b204e9800998ecf8427e
|
|
208
370
|
*/
|
|
209
371
|
async getChecksumFile(uid, hashType) {
|
|
210
372
|
this.checkUidValidity(uid);
|
|
@@ -219,9 +381,24 @@ class Cache {
|
|
|
219
381
|
/**
|
|
220
382
|
* The `decompressFile()` decompresses the file specified by `uid` into a new file specified by `destinationUid`.
|
|
221
383
|
*
|
|
222
|
-
* @
|
|
223
|
-
*
|
|
384
|
+
* @param uid Unique file identifier of a previously downloaded ZIP file.
|
|
385
|
+
* @param destinationUid Unique directory identifier (prefix of file) to extract ZIP file.
|
|
386
|
+
* @param method The decompression method to use. Currently, only 'zip' is supported.
|
|
387
|
+
* @returns {Promise<void>} A promise that resolves when the file is decompressed.
|
|
388
|
+
* @throws Error If the uid does not exist.
|
|
389
|
+
* @throws Error If the destinationUid is not a valid string.
|
|
390
|
+
* @throws Error If the method is not supported.
|
|
224
391
|
* @since 2.1.0
|
|
392
|
+
*
|
|
393
|
+
* @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/offline-zip-decompress | Example Applet with Offline ZIP Decompression}
|
|
394
|
+
* @example
|
|
395
|
+
* // Save the ZIP file
|
|
396
|
+
* await sos.offline.cache.saveFile('example-zip-file.zip', 'https://example.com/path/to/your/file.zip');
|
|
397
|
+
*
|
|
398
|
+
* // Decompress the ZIP file into a directory
|
|
399
|
+
* await sos.offline.cache.decompressFile('example-zip-file.zip', 'extracted-files/', 'zip');
|
|
400
|
+
* .then(() => { console.log('ZIP file extracted'); })
|
|
401
|
+
* .catch((error) => { console.error(error); });
|
|
225
402
|
*/
|
|
226
403
|
async decompressFile(uid, destinationUid, method) {
|
|
227
404
|
this.checkUidValidity(uid);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/FrontApplet/Offline/Cache/Cache.ts"],"names":[],"mappings":";;;;;AAYA,sFAA8D;AAC9D,wEAAgD;AAChD,kGAA0E;AAC1E,uEAA+C;AAI/C
|
|
1
|
+
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/FrontApplet/Offline/Cache/Cache.ts"],"names":[],"mappings":";;;;;AAYA,sFAA8D;AAC9D,wEAAgD;AAChD,kGAA0E;AAC1E,uEAA+C;AAI/C;;;;;;;;;GASG;AACH,MAAqB,KAAK;IAQhB;IACA;IARF,MAAM,CAAC,cAAc,GAAW,OAAO,CAAC;IAEvC,UAAU,CAAc;IACxB,aAAa,CAAiB;IAEtC,gBAAgB;IAChB,YACS,aAAqB,EACrB,WASP;QAVO,kBAAa,GAAb,aAAa,CAAQ;QACrB,gBAAW,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AAC,KAAK,QAAQ,EAAE,CAAC;gBACjE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACb,CAAC;;AAlcF,wBAmcC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IAddFont.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/IAddFont.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"IAddFont.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/IAddFont.ts"],"names":[],"mappings":";;;AAgCa,QAAA,aAAa,GAAG;IAC5B,KAAK,EAAE,QAAQ;IACf,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;CACd,CAAC;AAEW,QAAA,oBAAoB,GAAG;IACnC,UAAU,EAAE,QAAQ;IACpB,WAAW,EAAE,SAAS;IACtB,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,SAAS;CACvB,CAAC;AAEW,QAAA,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,4BAAoB,EAAE;IAC5D,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,qBAAa;CACtB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFileType.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/IFileType.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"IFileType.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/IFileType.ts"],"names":[],"mappings":";;;AAMa,QAAA,UAAU,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import IFileType from './IFileType';
|
|
2
2
|
import IFlag from './Flags/IFlag';
|
|
3
3
|
import ErrorCodes from '../Error/ErrorCodes';
|
|
4
|
+
/**
|
|
5
|
+
* Interface represents a file that can be saved to cache and loaded into applet resources.
|
|
6
|
+
*/
|
|
4
7
|
interface ISaveFile {
|
|
5
8
|
uid: string;
|
|
6
9
|
uri: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ISaveFile.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/ISaveFile.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoD;AACpD,yCAA8C;AAC9C,qEAA6C;AAC7C,qFAA6D;
|
|
1
|
+
{"version":3,"file":"ISaveFile.js","sourceRoot":"","sources":["../../../src/FrontApplet/Offline/ISaveFile.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoD;AACpD,yCAA8C;AAC9C,qEAA6C;AAC7C,qFAA6D;AAmBhD,QAAA,UAAU,GAAG;IACzB,GAAG,EAAE;QACJ,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE;YACN,IAAI,EAAE,oBAAU,CAAC,sBAAsB;YACvC,OAAO,EAAE,4BAAkB,CAAC,oBAAU,CAAC,sBAAsB,CAAC;SAC9D;KACD;IACD,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE;QACL,MAAM,EAAE,sBAAU;QAClB,KAAK,EAAE;YACN,IAAI,EAAE,oBAAU,CAAC,2BAA2B;YAC5C,OAAO,EAAE,4BAAkB,CAAC,oBAAU,CAAC,2BAA2B,CAAC;SACnE;KACD;IACD,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE;QACN,QAAQ,EAAE;YACT,MAAM,EAAE,cAAM;YACd,KAAK,EAAE,EAAE,IAAI,EAAE,oBAAU,CAAC,uBAAuB,EAAE,OAAO,EAAE,4BAAkB,CAAC,oBAAU,CAAC,uBAAuB,CAAC,EAAE;SACpH;KACD;CACD,CAAC"}
|
|
@@ -10,15 +10,23 @@ type FlagControllers = {
|
|
|
10
10
|
append: AppendFlagController;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Web-based applications often require additional assets to function, but downloading them every time is undesirable. The JS Applet SDK offers a wide range of APIs for storing different kinds of assets.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* Generally, there are four types of assets:
|
|
16
|
+
* - CSS & JavaScript files
|
|
17
|
+
* - Fonts
|
|
18
|
+
* - Audio-visual content (image, video, and audio files)
|
|
19
|
+
* - Arbitrary data (e.g., JSON files, plain text, binary data)
|
|
16
20
|
*
|
|
17
|
-
*
|
|
21
|
+
* And the SDK also provides two different APIs:
|
|
22
|
+
* - `sos.offline` & `sos.offline.cache`: A file system abstraction for caching files that are removed when the applet configuration is changed or the applet is reloaded. This method is usually preferred if the files can be re-downloaded.
|
|
23
|
+
* - `sos.fileSystem`: Direct access to the file system. All files are stored permanently and are not removed when the applet configuration changes.
|
|
18
24
|
*
|
|
19
|
-
*
|
|
25
|
+
* Using the `sos.offline` and `sos.offline.cache` APIs allows you to ship an applet without content, including only basic bootstrapping code, and load the content dynamically. The content will then be available even when the device is offline.
|
|
20
26
|
*
|
|
21
|
-
*
|
|
27
|
+
* :::warning
|
|
28
|
+
* Emulator has certain limitations while handling offline files. [Read more here](https://docs.signageos.io/hc/en-us/articles/4405238997138)
|
|
29
|
+
* :::
|
|
22
30
|
*/
|
|
23
31
|
export default class Offline {
|
|
24
32
|
private messagePrefix;
|
|
@@ -29,16 +37,23 @@ export default class Offline {
|
|
|
29
37
|
readonly types: ITypes;
|
|
30
38
|
readonly loadFile: ILoadFile;
|
|
31
39
|
readonly flags: IFlags<FlagControllers>;
|
|
32
|
-
private flagControllers;
|
|
40
|
+
private readonly flagControllers;
|
|
33
41
|
private FlagControllers;
|
|
34
42
|
private LoadFileControllers;
|
|
35
43
|
/** @internal */
|
|
36
44
|
constructor(messagePrefix: string, window: Window, postMessage: IPostMessage<any>);
|
|
37
45
|
/**
|
|
38
|
-
* The `addFiles()` method downloads the specified files and stores them locally.
|
|
46
|
+
* The `addFiles()` method downloads the specified files and stores them locally.
|
|
47
|
+
* The order in which the files are downloaded and stored is **not** guaranteed.
|
|
39
48
|
*
|
|
49
|
+
* CSS and JavaScript files are specific because they must be loaded with an HTML tag. The `sos.offline` API methods download, save, and append the resource to the web page. When adding a file, choose a unique identifier (`uid`) that should not change for the resource. The file will be overwritten if another file is added with the same `uid`.
|
|
50
|
+
*
|
|
51
|
+
* @param files Array of files to be downloaded and stored locally.
|
|
52
|
+
* @returns {Promise<Awaited<void>>} Resolves when all files are added.
|
|
53
|
+
* @throws {Error} If the `files` parameter is not an array of objects.
|
|
40
54
|
* @since 1.0.0
|
|
41
55
|
*
|
|
56
|
+
* @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/offline-resources | Example of Applet that save files and load them in one file}
|
|
42
57
|
* @example
|
|
43
58
|
* await sos.offline.addFile([{
|
|
44
59
|
* uri: 'https://unpkg.com/normalize.css@8.0.1/normalize.css',
|
|
@@ -52,27 +67,52 @@ export default class Offline {
|
|
|
52
67
|
* flags: [sos.offline.flags.append(document.body)],
|
|
53
68
|
* }]);
|
|
54
69
|
*/
|
|
55
|
-
addFiles(files: ISaveFile[]): Promise<void[]>;
|
|
70
|
+
addFiles(files: ISaveFile[]): Promise<Awaited<void>[]>;
|
|
56
71
|
/**
|
|
57
|
-
*
|
|
72
|
+
* Method `addFile()` will allow you to load single resource into applet. If you want to load more resource, use `addFiles()`.
|
|
73
|
+
*
|
|
74
|
+
* The order in which the files are downloaded and stored **is** guaranteed.
|
|
58
75
|
*
|
|
76
|
+
* @param files Array of files to be downloaded and stored locally.
|
|
77
|
+
* @returns {Promise<void>} Resolves when all files are added and the files are appended to the document when flags are used.
|
|
78
|
+
* @throws {Error} If the `files` parameter is not an array of objects
|
|
59
79
|
* @since 1.0.0
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const file = { // File that will be loaded into an applet
|
|
83
|
+
* "uri": "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
|
|
84
|
+
* "uid": "jquery-2.2.4.min.js",
|
|
85
|
+
* "type": sos.offline.types.javascript,
|
|
86
|
+
* "flags": [sos.offline.flags.append(document.body)]
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* await sos.offline.addFile(file); // And finally load file
|
|
60
90
|
*/
|
|
61
91
|
addFilesSync(files: ISaveFile[]): Promise<void>;
|
|
62
92
|
/**
|
|
63
93
|
* The `addFile()` method downloads the specified file and stores it locally.
|
|
64
94
|
*
|
|
95
|
+
* CSS and JavaScript files are specific because they must be loaded with an HTML tag. The `sos.offline` API methods download, save, and append the resource to the web page. When adding a file, choose a unique identifier (`uid`) that should not change for the resource. The file will be overwritten if another file is added with the same `uid`.
|
|
96
|
+
*
|
|
97
|
+
* :::info
|
|
98
|
+
* The file URL must point to a file. If your URI leads to a redirect (e.g. from http to https), the API will not work.
|
|
99
|
+
* :::
|
|
100
|
+
*
|
|
101
|
+
* @param file URI of the file to be downloaded.
|
|
102
|
+
* @param file.uid Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 characters.
|
|
103
|
+
* @param file.type Type of the file, e.g. 'javascript', 'css', etc.
|
|
104
|
+
* @param file.headers HTTP headers to be sent with the request for the file.
|
|
105
|
+
* @param file.flags Additional flags for appending stored files to the DOM or other operations
|
|
106
|
+
* @returns {Promise<void>} Resolves when the file is added and the file is appended to the document when flags are used.
|
|
107
|
+
* @throws {Error} If the `file` parameter is not an object.
|
|
108
|
+
* @throws {Error} If the `file` parameter does not contain a valid parameters.
|
|
65
109
|
* @since 1.0.0
|
|
66
110
|
*
|
|
67
111
|
* @example
|
|
68
112
|
* await sos.offline.addFile({
|
|
69
|
-
* // Source URL
|
|
70
113
|
* uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js',
|
|
71
|
-
* // Unique identifier of the resource
|
|
72
114
|
* uid: 'jquery-3.7.1.slim.min.js',
|
|
73
|
-
* // Indicate that the downloaded file is a JavaScript file
|
|
74
115
|
* type: sos.offline.types.javascript,
|
|
75
|
-
* // After the file is downloaded, it will be appended to document.body
|
|
76
116
|
* flags: [sos.offline.flags.append(document.body)],
|
|
77
117
|
* });
|
|
78
118
|
*/
|
|
@@ -88,10 +128,13 @@ export default class Offline {
|
|
|
88
128
|
* @param font.fontStretch Allows you to make text wider or narrower.
|
|
89
129
|
* @param font.fontStyle Specifies the font style for a text. (Either `normal`, `italic`, `oblique`, `initial` or `inherit`)
|
|
90
130
|
* @param font.fontWeight Sets how thick or thin characters in text should be displayed
|
|
91
|
-
* @param font.unicodeRange Defines the range of
|
|
131
|
+
* @param font.unicodeRange Defines the range of Unicode characters the font supports, default value is "U+0-10FFFF"
|
|
92
132
|
* @param font.formats Dictionary of supported formats with its files
|
|
93
|
-
*
|
|
133
|
+
* @throws {Error} If the `font` parameter is not an object.
|
|
134
|
+
* @returns {Promise<void>} Resolves when the font is added and the style element is appended to the document.
|
|
94
135
|
* @since 2.0.0
|
|
136
|
+
*
|
|
137
|
+
* @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/fonts | Example of Applet that loads custom font}
|
|
95
138
|
*/
|
|
96
139
|
addFont(font: IAddFont): Promise<void>;
|
|
97
140
|
private handleFileFlag;
|