Skip to content

Commit 5826400

Browse files
committed
Device id is must
Signed-off-by: Vishal Rana <[email protected]>
1 parent e0e7007 commit 5826400

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/hub.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
const mqtt = require('mqtt')
22

33
class Hub {
4-
constructor(accountID, apiKey, options) {
4+
constructor(accountID, apiKey, deviceID, options) {
55
this.accountID = accountID
66
this.apiKey = apiKey
7+
this.deviceID = this._normalizeDeviceID(deviceID)
78
this.handlers = {}
89
this.options = options || {}
910
}
1011

12+
_normalizeDeviceID(id) {
13+
return `${this.accountID}:${id}`
14+
}
15+
1116
_normalizeTopic(topic) {
1217
return `${this.accountID}/${topic}`
1318
}
@@ -19,7 +24,8 @@ class Hub {
1924
connect(handler) {
2025
this.client = mqtt.connect('mqtt://hub.labstack.com', {
2126
username: this.accountID,
22-
password: this.apiKey
27+
password: this.apiKey,
28+
clientId: this.deviceID
2329
})
2430
this.client.on('connect', function () {
2531
if (handler) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "labstack",
3-
"version": "0.32.0",
3+
"version": "0.32.1",
44
"description": "Official Node.js client library for the LabStack platform",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)