New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

labstack

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

labstack - npm Package Compare versions

Comparing version
0.31.8
to
0.32.0
+21
-6
lib/hub.js
const mqtt = require('mqtt')
class Hub {
constructor(accountID, apiKey, clientID) {
constructor(accountID, apiKey, options) {
this.accountID = accountID
this.apiKey = apiKey
this.handlers = {}
this.options = options || {}
}
_normalizeTopic(topic) {
return `${this.accountID}/${topic}`
}
_denormalizeTopic(topic) {
return topic.replace(this.accountID + '/', '');
}
connect(handler) {

@@ -21,3 +30,10 @@ this.client = mqtt.connect('mqtt://hub.labstack.com', {

this.client.on('message', (topic, message) => {
this.handlers[topic](message)
topic = this._denormalizeTopic(topic)
handler = this.handlers[topic]
if (this.options.messageHandler) {
this.options.messageHandler(topic, message)
}
if (handler) {
handler(topic, message)
}
})

@@ -29,8 +45,7 @@ // this.client.on('end', () => {

publish(topic, message) {
this.client.publish(`${this.accountID}/${topic}`, message)
this.client.publish(this._normalizeTopic(topic), message)
}
subscribe(topic, handler) {
topic = `${this.accountID}/${topic}`
this.client.subscribe(topic)
this.client.subscribe(this._normalizeTopic(topic))
this.handlers[topic] = handler

@@ -40,3 +55,3 @@ }

unsubscribe(self, topic) {
this.client.unsubscribe(`${this.accountID}/${topic}`)
this.client.unsubscribe(this._normalizeTopic(topic))
}

@@ -43,0 +58,0 @@

{
"name": "labstack",
"version": "0.31.8",
"version": "0.32.0",
"description": "Official Node.js client library for the LabStack platform",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,11 +5,15 @@ const express = require('express')

const hub = new Hub('ie8t5fgcb6s2vaxgg02y', 'VouXFKK2A1TkuMUVz3wV2zvmapIdRuFM')
const hub = new Hub('ie8t5fgcb6s2vaxgg02y', 'VouXFKK2A1TkuMUVz3wV2zvmapIdRuFM', {
messageHandler: function(topic, message) {
console.log(topic, message)
}
})
hub.connect(() => {
console.log('connect')
})
hub.publish('hello', '111')
// hub.publish('hello', '111')
// hub.subscribe('hello', (message) => {
// console.log(message)
// })
hub.subscribe('hello', (topic, message) => {
console.log(topic, message)
})

@@ -16,0 +20,0 @@ // const app = express()