Movatterモバイル変換


[0]ホーム

URL:


Jump to content
SpinetiX Wiki
Search

Web Storage API

From SpinetiX Wiki

Introduction

Theweb storage specification, standardized by theWorld Wide Web Consortium (W3C), has been used to implement a permanent & semi-permanent storage of structured key-value pair data on theDSOS players.

The following APIs are available:

Additionally, local storage items can also be manipulated through RPC API and Shared Variables.

JavaScript API

The JavaScript API provides two mechanisms for storing key-value pair data on theplayers, respectively onElementi, using these twoJavaScript global objects:

  • localStorage for permanent data storage, including upon player restart orpublish of new content.
  • sessionStorage for semi-permanent storage, as the data is reinitialized following a player restart or a contentpublish.
NoteNotes:
  • The items saved into Web Storage can also be accessed as JavaScript properties (e.g.,localStorage.key). The value of an item (i.e. object property) can be read at any time, independently on the time it has been set.
  • Only strings can be stored in the web storage - attempting to store a different data type will result in an automatic conversion into a string. Conversion into JSON (JavaScript Object Notation), however, allows for effective storage of JavaScript objects.
  • When invoking the methods above, except for the getter, astorage event is fired.
  • The maximum size for each of the two web storage objects is 4 MB - see above how the data can be cleared.

localStorage

ThelocalStorage object enables permanent storage of data, being resilient to player reboots. It provides access to a list of key/value pairs (sometimes called items), that can be set and / or read with the following methods:

// setterlocalStorage.setItem(key,value);// getterlocalStorage.getItem(key);// remove itemlocalStorage.removeItem(key);// remove all items from the local storagelocalStorage.clear();
NoteNote:
The data stored into the web storage of the players can also be cleared fromControl CenterOperations → Reset page.

sessionStorage

ThesessionStorage object is identical to thelocalStorage object, except that the data is reinitialized whenever the content restarts, following a player reboot or a contentpublishing. It provides access to a list of key-value pairs (sometimes called items), that can be set and/or read with the following methods:

// settersessionStorage.setItem(key,value);// gettersessionStorage.getItem(key);// remove itemsessionStorage.removeItem(key);// remove all items from the session storagesessionStorage.clear();

REST API

Note 
Applies to allDSOS players, except forHMP300 andDiVA. It requiresSYSTEMS Feature Set.

The Web Storage REST API allows manipulating thelocalStorage data of the player from external clients through HTTP(S) calls. REST stands for "Representational State Transfer", which is a software architectural style that defines a set of constraints to be used for creating web services. It was added infirmware 4.3.0.

The following operations are supported:

  • List the existing keys
  • Get the value of a key
  • Set the value of one or more keys
  • Delete a key

Configuration

APIs Security settings

The REST API is deactivated by default – follow these steps to activated it:

  1. OpenControl CenterAdvanced Applications → API Security page.
  2. Activate "Enable security token access to the Webstorage API" option.
  3. If the script calling this API is not running on theplayer content server and the requests are being blocked due toCORS, then activate the "Enable CORS requests" option as well.
  4. If needed, replace the generated security token and API key with your own.
  5. Click the "Apply" button.

Authentication

To access the API end-points, the security token, generated and stored on the player, must be provided with each call, through a "Bearer Authorization" header or an "access_token" query string parameter. Alternatively, the authentication can be done using the credentials of users defined inuser manager with content authoring or admin rights. BothTLS-SRP andHTTP Basic authentication methods are supported.

NoteNotes:
  • Using HTTP is not secure, any eavesdropper can steal the bearer token or user password – using HTTPS, either with self-signed certificate or with TLS-SRP is a secure alternative.
  • To protect the player against CSRF when using CORS (i.e., the script is located on another host) thespx-api-key={rpcApiKey} query string parameter must be appended to the end-point, where{rpcApiKey} is the API Key configured on that player, either fromControl CenterAdvanced Applications → APIs Security section, or by using the<rpc-api-key>configuration tag.

Endpoint

The endpointwebstorage allows the following operations:

GEThttp(s)://player_address/webstorage

Get the list of web storage variables on the player.

GEThttp(s)://player_address/webstorage/{key} or /webstorage?name={key}

Get the value of the variable named {key}.

POSThttp(s)://player_address/webstorage

Update one of more variables using the content of a form.

POSThttp(s)://player_address/webstorage/{key} or /webstorage?name={key}

Update the variable named {key} with the content of the POST.

POSThttp(s)://player_address/webstorage/{key}?expect={value}

Update the variable named {key} with the content of the POST, only is the previous value of the variable is equal to {value}.

DELETEhttp(s)://player_address/webstorage/{key}

Delete the variable named {key}.

PURGEhttp(s)://player_address/webstorage/

Delete all the variables.Added infirmware 4.6.1.
NoteNote:
The full documentation, including examples, can be found here:https://api.docs.spinetix.com/ .

Tool

Note 
This tool is served from a secured connection, so the browser will block a request to aplayer address using HTTP (default behavior when the protocol is not provided) due to mixed active content protection – the solution is to disable the browser protection on this page or enter an HTTPS player address (you need to prior install theplayer self-signed certificate).

Alternatively, this tool can bedownloaded from our server for local usage.

Other APIs

RPC API

TheRPC API offers severalwebstorage_***RPC commands to interact with the data stored in thelocalStorage. It is especially useful for cases when thecommunication needs to be initialized by the player itself (typical usage is when the player is behind a firewall or a NAT) when using thenative REST API would be problematic.

Shared Variables

Shared Variables are automatically saved into thelocalStorage object sincefirmware 3.1.0, thusupdating a Shared Variable triggers a modification within the localStorage object as well.

See also

Retrieved from "https://support.spinetix.com/w/index.php?title=Web_Storage_API&oldid=20523"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp