URL of WebSocket endpoint or undefined to guess it.
search
part of request url or undefined to take from
window.location.search
.
Specify an analysis id or undefined to have one generated. The connection will try to connect to a previously created analysis with that id.
initialize connection
close connection
Emit a signal/action to the backend.
A signal name. Usually an action name.
Payload attached to the action.
Register a callback that listens for a signal.
The signal can be a simple string (the name for a signal/action), but it
can also be an Object of the form {data: 'current_value'}
which would
trigger on data
actions that are sending a JSON dictionary that contains
the key current_value
. In this case, the value that is
given to the callback function is the value assigned to current_value
.
d.on('data', value => { console.log(value); });
// If the backend sends an action called 'data' with a message
// {current_value: 3.0}, this function would log `{current_value: 3.0}`.
d.on({data: 'current_value'}, value => { console.log(value); });
// If the backend sends an action called 'data' with a
// message {current_value: 3.0}, this function would log `3.0`.
// This callback is not triggered when the message does not contain a
// `current_value` key.
Signal name to listen for.
A callback function that takes the attached data.
Listen for a signal once.
Similar to [on] but returns a Promise
instead of taking a callback.
This is mostly useful for unit tests.
Signal name to listen for.
Set a pre-emit hook.
A signal name.
Callback function.
Trigger all callbacks for this signal with this message.
Name of the signal to trigger.
Payload for the triggered signal.
Generated using TypeDoc
Connection to the backend.
The standard template is to create a connection first, then use it to wire all UI elements, to add custom callback functions and at last to run Connection.connect to create a WebSocket connection to the backend server (see example below).
The other two essential functions to know about are Connection.on and Connection.emit.
Logging across frontend and backend can be done by emitting
log
,warn
orerror
, e.g.emit('log', 'Hello World')
.var databench = new Databench.Connection(); Databench.ui.wire(databench); // put custom databench.on() methods here databench.connect();