Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
Adds log to capture when a client disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miller-0 committed Dec 11, 2021
1 parent 1282104 commit 262df1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lattice-connect",
"version": "0.2.1",
"version": "0.2.2",
"description": "A small HTTP server + MQTT broker designed to bridge the web with Lattices in the field",
"main": "dist/index.js",
"scripts": {
Expand Down
25 changes: 15 additions & 10 deletions src/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ const net = require('net');
const instance = aedes();
let connCount = 0;

instance.on('client', (_client) => {
logger.debug(`BROKER (conns=${connCount}): New client (${_client.id}) attempting connection.`);
instance.on('client', (client) => {
logger.debug(`BROKER (conns=${connCount}): New client (${client.id}) attempting connection.`);
});

instance.on('clientReady', (_client) => {
instance.on('clientReady', (client) => {
connCount += 1;
logger.info(`BROKER (conns=${connCount}): Client (${_client.id}) connected.`);
logger.info(`BROKER (conns=${connCount}): Client (${client.id}) connected.`);
});

instance.on('clientError', (_client, error) => {
logger.error(`BROKER (conns=${connCount}): Error from client ${_client.id}: ${error.message}`);
instance.on('clientDisconnect', (client) => {
connCount -= 1;
logger.info(`BROKER (conns=${connCount}): Client (${client.id}) disconnected.`);
});

instance.on('subscribe', (_subscriptions, _client) => {
logger.debug(`BROKER (conns=${connCount}): Client (${_client.id}) subscribed to topics: ${JSON.stringify(_subscriptions)}`);
instance.on('clientError', (client, error) => {
logger.error(`BROKER (conns=${connCount}): Error from client ${client.id}: ${error.message}`);
});

instance.on('publish', (_packet, _client) => {
logger.trace(`BROKER (conns=${connCount}): Client (${_client}) published message: ${JSON.stringify(_packet)}`);
instance.on('subscribe', (_subscriptions, client) => {
logger.debug(`BROKER (conns=${connCount}): Client (${client.id}) subscribed to topics: ${JSON.stringify(_subscriptions)}`);
});

instance.on('publish', (_packet, client) => {
logger.trace(`BROKER (conns=${connCount}): Client (${client}) published message: ${JSON.stringify(_packet)}`);
});

const broker = net.createServer(instance.handle);
Expand Down

0 comments on commit 262df1a

Please sign in to comment.