Skip to main content

JavaScript API

For web apps the SDK is compiled to WebAssembly and exposed through a JavaScript wrapper that mirrors the same v3 call surface as the native languages.

Every Switchboard object — the SDK singleton ("switchboard"), engines, nodes, extensions — is identified by an object URI string. The same handful of calls drives every object.

note

The JavaScript bindings follow the cross-language v3 design described below, but exact binding names (camelCase variants, async vs sync return shape) may differ slightly.

Initialize SDK​

Initializes the SDK with a config object. Resolves to the SDK's object URI.

await Switchboard.initialize(config);
await Switchboard.initialize({
appID: 'your-app-id',
appSecret: 'your-app-secret',
});

Deinitialize SDK​

Releases all SDK-owned resources.

await Switchboard.deinitialize();

Create Engine​

Creates an engine from a config object. Resolves to the engine's object ID.

const engineID = await Switchboard.createEngine(engineConfig);

Destroy Engine​

Destroys an engine and everything it owns.

await Switchboard.destroyEngine(engineID);

Call Action​

Invokes a named action on any Switchboard object.

await Switchboard.callAction(objectURI, actionName, params);
// Start the engine
await Switchboard.callAction(engineID, 'start');

// Load a file into a player node
await Switchboard.callAction('playerNode', 'load', {
audioFilePath: 'AudioFiles/speech-mono-48k.wav',
});

Set Value​

Writes a value to a key on a Switchboard object.

await Switchboard.setValue(objectURI, key, value);
await Switchboard.setValue('playerNode', 'isLoopingEnabled', true);
await Switchboard.setValue('gainNode', 'gain', 0.5);

Get Value​

Reads a value from a key on a Switchboard object.

const value = await Switchboard.getValue(objectURI, key);
const frames = await Switchboard.getValue('recorderNode', 'framesRecorded');

Add Event Listener​

Subscribes to a named event. Returns a listener ID.

const listenerID = await Switchboard.addEventListener(objectURI, eventName, callback);
const listenerID = await Switchboard.addEventListener(
'playerNode',
'playbackProgress',
(eventData) => {
// ...
}
);

Remove Event Listener​

Unsubscribes a previously registered listener.

await Switchboard.removeEventListener(objectURI, listenerID);