Shared Variables
Enable real-time data sharing between SVG documents on the same player, across players, and with external systems.
JavaScript API
var sv = createSharedVariable('myVariable'); | Property/Method | Description |
|---|---|
sv.value | Current value (read-only) |
sv.set(value) | Set the variable value |
sv.addUpdateListener(fn) | Register update handler |
sv.removeUpdateListener(fn) | Unregister handler |
sv.testAndSet(expected, new) | Atomic compare-and-swap |
Listen & Display
$(function() {
var display = $.headlineTextArea({}).addTo('svg');
var sv = createSharedVariable('message');
sv.addUpdateListener(function() {
display.text(sv.value);
});
display.text(sv.value || "Waiting...");
});Persist to localStorage
$(function() {
var sv = createSharedVariable('persistentVar');
var stored = localStorage.getItem('persistentVar');
if (stored) sv.set(stored);
sv.addUpdateListener(function() {
localStorage.setItem('persistentVar', sv.value);
});
});Network API
External clients can access the SV server via network. Disabled by default — enable in Control Center → Network → Services.
Remote Update via RPC (AJAX)
$.ajax({
type: "POST", url: "http://HMP_ADDRESS/rpc",
contentType: 'application/json',
data: JSON.stringify({
method: "webstorage_set",
params: [[ { name: "myVar", value: "NewValue" } ]], id: 1
})
});Related Pages
- Interactive Content — cross-document control
- Web Storage — localStorage persistence
- Data Feeds & AJAX — RPC calls
- Player APIs — network API overview