Skip to main content
Version: Next

Applet Resources

Often there are some JavaScripts and CSS styles necessary to be loaded for your Applet. It can be libraries like jQuery or even your whole application code. For these necessities offline API for saving, storing & loading files are ready.

MethodsDescriptionSupported since
addFile()Add single file to Applet before starting it.1.0.0
addFiles()Add files to Applet before starting it.1.0.0
addFilesSync()Add files to Applet before starting it in the set order to prevent race condition.1.0.0

File object

Every method above, accept single object or array of objects depending by type. Every object must have these keys.

KeyTypeRequiredDescription
uriString
Yes
URL of file
uidString
Yes
Unique ID in Applet for future manage
typeString
Yes
Type of file. Example: sos.offline.types.javascript, sos.offline.types.css, sos.offline.types.video
^^
flagsArray
Yes
Special flag for file
headersArray
No
Authorization headers
info
  • The file URL must point to a file. If your URI leads to a 303 redirect (e.g. from http to https), the API will not work.
  • There are some limitations for Emulator.

addFile()

Method addFile() will allow you to load single resource into applet. If you want to load more resource, use addFiles().

Javascript Example

const file = { // File that will be loaded into an applet
"uri": "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
"uid": "jquery-2.2.4.min.js",
"type": sos.offline.types.javascript,
"flags": [sos.offline.flags.append(document.body)]
}

await sos.offline.addFile(file); // And finally load file

addFiles()

Method addFiles() will allow you to load array of your resources into Applet. Files are load in random order.

Javascript Example

const files = [ // Array of files
{
"uri": "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
"uid": "jquery-2.2.4.min.js",
"type": sos.offline.types.javascript,
"flags": [sos.offline.flags.append(document.body)]
},
{
"uri": "https://signageostest.blob.core.windows.net/test/applet-examples/benchmark-styles.css?v=1.0.0",
"uid": "benchmark-styles.css-v1.0.0",
"type": sos.offline.types.css,
"headers": { "Authorization": "Basic Zm9vOmJhcg==" },
"flags": [sos.offline.flags.append(document.head)]
}
];

await sos.offline.addFiles(files);

addFilesSync()

Method addFilesSync() works same as method above, but all files are loaded in correct order. Otherwise, files are loaded in random order by file size.

Javascript example

const files = [
{
"uri": "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
"uid": "jquery-2.2.4.min.js",
"type": sos.offline.types.javascript,
"flags": [sos.offline.flags.append(document.body)]
},
{
"uri": "https://signageostest.blob.core.windows.net/test/applet-examples/benchmark-styles.css?v=1.0.0",
"uid": "benchmark-styles.css-v1.0.0",
"type": sos.offline.types.css,
"headers": { "Authorization": "Basic Zm9vOmJhcg==" },
"flags": [sos.offline.flags.append(document.head)]
}
];

sos.offline.addFilesSync(files).then(() => {
console.log('Now you can use jQuery and CSS file');
jQuery('#do').something();
});

Usage with Typescript

You can also use all these methods with signageOS TypeScript.

interface ISaveFile {
uid: string;
uri: string;
type: string;
headers?: { [key: string]: string };
flags?: IFlag[];
}

addFile(files: ISaveFile[]): Promise<void>;
addFiles(files: ISaveFile[]): Promise<void>;
addFilesSync(files: ISaveFile[]): Promise<void>;

Flags that can be optionally passed to the file object are available in flags property.

interface IFlag {
type: 'append';
element: IElement;
}

Errors

Although we are doing our best, following errors may occur when working with the Applet Resources.

CodeTypeMessage
40101AppletResourcesErrorFile needs to be object
40102AppletResourcesErrorFile UID needs to be defined
40103AppletResourcesErrorFile flags needs to be Array
40104AppletResourcesErrorFile flag needs to be object
40105AppletResourcesErrorAlready loading file: FILE_NAME
^^^^Your code has probably multiple occurrences of addFile/s methods.
40106AppletResourcesErrorAlready existing file: FILE_NAME
^^^^File is already loaded or exists in Applet
49901FileNotFoundErrorFile FILE_ID was not found
^^^^Applet can not get file. URL is invalid.