refactor(websocket): improve code formatting, fix linting issues

pull/4/head
Cameron Clough 2022-03-26 23:12:50 +00:00
parent 2e9c3f0573
commit 6bed0726fa
No known key found for this signature in database
GPG Key ID: BFB3B74B026ED43F
2 changed files with 18 additions and 23 deletions

View File

@ -1,10 +1,10 @@
import { WebSocketServer } from 'ws';
import cookie from 'cookie';
import jsonwebtoken from 'jsonwebtoken';
import httpsServer from 'https';
import httpServer from 'http';
import { readFileSync } from 'fs';
import httpServer from 'http';
import httpsServer from 'https';
import jsonwebtoken from 'jsonwebtoken';
import log4js from 'log4js';
import { WebSocketServer } from 'ws';
import { AthenaActionLog, AthenaReturnedData } from '../../../models';
import deviceController from '../../controllers/devices';
@ -12,7 +12,9 @@ import helperFunctions from './helpers';
const logger = log4js.getLogger();
let helpers;
// TODO: I think we need to provide wss as a param here
const helpers = helperFunctions();
let wss;
function __server() {
@ -110,7 +112,6 @@ async function manageConnection(ws, res) {
__server();
wss.retropilotFunc = {
findFromDongle: (dongleId) => {
let websocket = null;
wss.clients.forEach((value) => {
@ -162,16 +163,18 @@ wss.retropilotFunc = {
method, params, jsonrpc: '2.0', id,
}),
/* eslint-disable camelcase */
actionLogger: async (account_id, device_id, action, user_ip, device_ip, meta, dongle_id) => {
actionLogger: async (accountId, deviceId, action, userIp, deviceIp, meta, dongleId) => {
await AthenaActionLog.create({
account_id, device_id, action, user_ip, device_ip, meta, created_at: Date.now(), dongle_id,
account_id: accountId,
device_id: deviceId,
action,
user_ip: userIp,
device_ip: deviceIp,
meta,
created_at: Date.now(),
dongle_id: dongleId,
});
},
/* eslint-enable camelcase */
};
helpers = helperFunctions();
export default helpers;

View File

@ -12,7 +12,6 @@ const logger = log4js.getLogger();
let server;
let wss;
let controls;
// eslint-disable-next-line no-underscore-dangle
function __server() {
@ -63,7 +62,6 @@ async function authenticateUser(ws, req) {
return false;
}
// eslint-disable-next-line no-param-reassign
ws.account = account;
return true;
}
@ -98,13 +96,7 @@ async function manageConnection(ws, req) {
// ws.send(JSON.stringify(await commandBuilder('reboot')))
}
const websocketServer = __server();
controls = controlsFunction(websocketServer);
export const websocketServer = __server();
export const controls = controlsFunction(websocketServer);
athenaRealtime.realtimeCallback(controls);
export default {
controls,
websocketServer,
};