From a3e8cd7853398dca979d409a378dbfccdf99c814 Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Sat, 8 Jan 2022 23:28:15 +0000 Subject: [PATCH] lint: tidy up websocket --- websocket/athena/index.js | 5 ++++- websocket/web/commands.js | 1 + websocket/web/controls.js | 35 +++++++++++++++++++++++++---------- websocket/web/index.js | 2 ++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/websocket/athena/index.js b/websocket/athena/index.js index c83067b..24b0dae 100644 --- a/websocket/athena/index.js +++ b/websocket/athena/index.js @@ -8,12 +8,15 @@ const log4js = require('log4js'); const models = require('../../models/index.model'); const config = require('../../config'); +// eslint-disable-next-line no-unused-vars const authenticationController = require('../../controllers/authentication'); const deviceController = require('../../controllers/devices'); const logger = log4js.getLogger('default'); +let helpers; let wss; + function __server() { let server; @@ -171,6 +174,6 @@ wss.retropilotFunc = { }; -const helpers = require('./helpers')(wss); +helpers = require('./helpers')(wss); module.exports = helpers; diff --git a/websocket/web/commands.js b/websocket/web/commands.js index 337cf30..d1254e1 100644 --- a/websocket/web/commands.js +++ b/websocket/web/commands.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-unused-vars const authenticationController = require('../../controllers/authentication'); const deviceController = require('../../controllers/devices'); const athenaRealtime = require('../athena/index'); diff --git a/websocket/web/controls.js b/websocket/web/controls.js index 264069f..dce9c12 100644 --- a/websocket/web/controls.js +++ b/websocket/web/controls.js @@ -2,30 +2,45 @@ const deviceController = require('../../controllers/devices'); let wss; -async function getDongleOwners(dongle_id) { - const owners = await deviceController.getOwnersFromDongle(dongle_id); +async function getDongleOwners(dongleId) { + const owners = await deviceController.getOwnersFromDongle(dongleId); console.log('dongle owners', owners); return owners; } async function broadcastToAccounts(owners, data) { wss.clients.forEach((ws) => { - owners.data.forEach((account_id) => { - if (account_id === ws.account.id) { + owners.data.forEach((accountId) => { + if (accountId === ws.account.id) { ws.send(JSON.stringify(data)); } }); }); } -async function dongleStatus(dongle_id, status) { - const owners = await getDongleOwners(dongle_id); - await broadcastToAccounts(owners, { command: 'dongle_status', id: Date.now(), data: { dongle_id, online: status, time: Date.now() } }); +async function dongleStatus(dongleId, status) { + const owners = await getDongleOwners(dongleId); + await broadcastToAccounts(owners, { + command: 'dongle_status', + id: Date.now(), + data: { + dongle_id: dongleId, + online: status, + time: Date.now(), + }, + }); } -async function passData(dongle_id, msg) { - const owners = await getDongleOwners(dongle_id); - await broadcastToAccounts(owners, { command: 'data_return', id: msg.id, data: { dongle_id, return: msg } }); +async function passData(dongleId, msg) { + const owners = await getDongleOwners(dongleId); + await broadcastToAccounts(owners, { + command: 'data_return', + id: msg.id, + data: { + dongle_id: dongleId, + return: msg, + }, + }); return true; } diff --git a/websocket/web/index.js b/websocket/web/index.js index a6ae144..4aab656 100644 --- a/websocket/web/index.js +++ b/websocket/web/index.js @@ -6,6 +6,7 @@ const config = require('../../config'); let controls = require('./controls'); const authenticationController = require('../../controllers/authentication'); +// eslint-disable-next-line no-unused-vars const deviceController = require('../../controllers/devices'); const logger = log4js.getLogger('default'); @@ -34,6 +35,7 @@ function __server() { return wss; } +// eslint-disable-next-line no-unused-vars function buildResponse(ws, success, msg, data) { ws.send(JSON.stringify({ success, msg, data, timestamp: Date.now(),