Handlers

When communicating with the stream, a number of notifications are emitted.

Connect

Emitted on successful connection.

// Create an instance of Wia
// Replace 'd_sk_abcdef' with your device secret key
var wia = require('wia')('d_sk_abcdef');

// Listen for a successful connection to the MQTT API
wia.stream.on('connect', function() {
console.log("Connected to the stream!");
});

Reconnect

Emitted when a reconnect starts.

// Create an instance of Wia
// Replace 'd_sk_abcdef' with your device secret key
var wia = require('wia')('d_sk_abcdef');

// Listen for a reconnection
wia.stream.on('reconnect', function() {
console.log("Reconnect emitted.");
});

Disconnect

Emitted after a disconnection.

// Create an instance of Wia
// Replace 'd_sk_abcdef' with your device secret key
var wia = require('wia')('d_sk_abcdef');

// Listen for a disconnection
wia.stream.on('disconnect', function() {
console.log("Disconnect emitted.");
});

Offline

Emitted when the client goes offline.

// Create an instance of Wia
// Replace 'd_sk_abcdef' with your device secret key
var wia = require('wia')('d_sk_abcdef');

// Listen for an offline
wia.stream.on('offline', function() {
console.log("Offline emitted.");
});

Error

Emitted when a client cannot connect or a parsing error occurs.

// Create an instance of Wia
// Replace 'd_sk_abcdef' with your device secret key
var wia = require('wia')('d_sk_abcdef');

// Listen for a error
wia.stream.on('error', function(err) {
console.log("Error emitted.");
console.log(err);
});