Connection make global connector by passed config
import MqttConnection from 'flespi-io-js/dist/mqtt'
The arguments are:
config
is a global config for all connections you haveconnectorName
is a name of global variable of connector(only for initialization Vue plugin)token
is a token for connectionsserver
server for mqtt connectionsport (optional)
port for mqtt connectionsclientId (optional)
client id for mqtt connectionsmqttSettings
mqtt settings by MQTT.js API
let connector = new MqttConnection({
token: 'FlespiToken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
server: `ws://server.io`,
mqttSettings: {
reschedulePings: true,
keepalive: 3600,
resubscribe: false,
reconnectPeriod: 5000,
connectTimeout: 3600000
}
})
- Token
let token = connector.token
connector.token = 'FlespiToken XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
- mqttConfig
let socketConfig = connector.config
connector.config = {
server: `ws://server.io`,
mqttSettings: {
reschedulePings: true,
keepalive: 3600,
resubscribe: false,
reconnectPeriod: 5000,
connectTimeout: 3600000
}
}
- setRegion methods allows set flespi region for connection.
connector.setRegion(region)
/* region structure */
{
"cdn": "https://ru-cdn.flespi.io",
"default": false,
"gw": "ru-gw.flespi.io",
"mqtt": "ru-mqtt.flespi.io:8883",
"mqtt-ws": "ru-mqtt.flespi.io:443",
"region": "ru",
"rest": "https://ru.flespi.io"
}
It has all methods like socket
namespace of main class.