Connection lifecycle
onConnect fires on every successful WebSocket connection, including every reconnection when reconnect: true is enabled.
Hub-side subscriptions live only for the current connection, so register them inside onConnect when you use reconnecting clients.
Example
const client = new obyte.Client('wss://obyte.org/bb', {
reconnect: true,
});
client.onConnect(function() {
client.justsaying('light/new_aa_to_watch', {
aa: 'AA_ADDRESS_TO_WATCH',
});
client.subscribe(function(err, result) {
if (err) return console.error(err);
console.log('notification:', result);
});
});
client.onError(function(err) {
console.error('connection error:', err);
});
const heartbeat = setInterval(function() {
client.api.heartbeat();
}, 10 * 1000);Close permanently
When reconnect: true is enabled, a closed socket is treated as a dropped connection and the client reconnects. Disable reconnection before closing if you want to shut down permanently.
Returns
subscribe receives hub notifications.
Last updated