From e74dff14c8e3e67a91f09a074d7fd5ff302d936e Mon Sep 17 00:00:00 2001 From: Erwan d'Orgeville Date: Thu, 1 Oct 2020 16:42:27 -0400 Subject: [PATCH] Adds missing semicolons, removes unused imports --- src/transports/mqtt.test.ts | 12 ++++++------ src/transports/mqtt.ts | 24 ++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/transports/mqtt.test.ts b/src/transports/mqtt.test.ts index bfd211a5..9fc06590 100644 --- a/src/transports/mqtt.test.ts +++ b/src/transports/mqtt.test.ts @@ -24,7 +24,7 @@ describe('mqtt transport', () => { transport.addRouter(router); - mqttBroker.listen(1883) + mqttBroker.listen(1883); await transport.connect(); mqttClient = await AsyncMQTT.connectAsync(mqttOptions.broker) mqttClient.subscribe(mqttOptions.outTopic) @@ -36,17 +36,17 @@ describe('mqtt transport', () => { }) it("can connect to the broker", () => { - expect(transport.client?.connected).toBeTruthy() + expect(transport.client?.connected).toBeTruthy(); }) it("can answer to simple JSON-RPC", (done) => { const messageHandler = (topic: string, payload: Buffer) => { - const response = JSON.parse(payload.toString()) + const response = JSON.parse(payload.toString()); expect(response.result).toBe(4); - mqttClient.off('message', messageHandler) - done() + mqttClient.off('message', messageHandler); + done(); } - mqttClient.on('message', messageHandler) + mqttClient.on('message', messageHandler); mqttClient.publish(mqttOptions.inTopic, JSON.stringify({ id: "0", diff --git a/src/transports/mqtt.ts b/src/transports/mqtt.ts index 9cf1470d..c6d1712a 100644 --- a/src/transports/mqtt.ts +++ b/src/transports/mqtt.ts @@ -1,8 +1,4 @@ -import cors from "cors"; -import { json as jsonParser } from "body-parser"; -import connect, { HandleFunction } from "connect"; -// import http, { ServerOptions } from "http"; -import AsyncMQTT, { AsyncClient } from "async-mqtt" +import AsyncMQTT, { AsyncClient } from "async-mqtt"; import ServerTransport, { JSONRPCRequest } from "./server-transport"; export interface MQTTServerTransportOptions { @@ -13,25 +9,25 @@ export interface MQTTServerTransportOptions { export default class MQTTServerTransport extends ServerTransport { - private options: MQTTServerTransportOptions - public client: AsyncMQTT.AsyncClient | null + private options: MQTTServerTransportOptions; + public client: AsyncMQTT.AsyncClient | null; constructor(options: MQTTServerTransportOptions) { - super() - this.options = { ...options } - this.client = null + super(); + this.options = { ...options }; + this.client = null; } public async connect(): Promise { this.client = await AsyncMQTT.connectAsync(this.options.broker); - this.client.subscribe(this.options.inTopic) + this.client.subscribe(this.options.inTopic); this.client.on('message', (topic: string, payload: Buffer) => { - this.mqttRouterHandler(JSON.parse(payload.toString())) + this.mqttRouterHandler(JSON.parse(payload.toString())); }) } public end(): void { - this.client?.end() + this.client?.end(); } private async mqttRouterHandler(payload: any): Promise { @@ -41,6 +37,6 @@ export default class MQTTServerTransport extends ServerTransport { } else { result = await super.routerHandler(payload); } - this.client?.publish(this.options.outTopic, JSON.stringify(result)) + this.client?.publish(this.options.outTopic, JSON.stringify(result)); } }