refactor(websocket): improve code formatting, fix linting issues
parent
2e9c3f0573
commit
6bed0726fa
|
@ -1,10 +1,10 @@
|
||||||
import { WebSocketServer } from 'ws';
|
|
||||||
import cookie from 'cookie';
|
import cookie from 'cookie';
|
||||||
import jsonwebtoken from 'jsonwebtoken';
|
|
||||||
import httpsServer from 'https';
|
|
||||||
import httpServer from 'http';
|
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
|
import httpServer from 'http';
|
||||||
|
import httpsServer from 'https';
|
||||||
|
import jsonwebtoken from 'jsonwebtoken';
|
||||||
import log4js from 'log4js';
|
import log4js from 'log4js';
|
||||||
|
import { WebSocketServer } from 'ws';
|
||||||
|
|
||||||
import { AthenaActionLog, AthenaReturnedData } from '../../../models';
|
import { AthenaActionLog, AthenaReturnedData } from '../../../models';
|
||||||
import deviceController from '../../controllers/devices';
|
import deviceController from '../../controllers/devices';
|
||||||
|
@ -12,7 +12,9 @@ import helperFunctions from './helpers';
|
||||||
|
|
||||||
const logger = log4js.getLogger();
|
const logger = log4js.getLogger();
|
||||||
|
|
||||||
let helpers;
|
// TODO: I think we need to provide wss as a param here
|
||||||
|
const helpers = helperFunctions();
|
||||||
|
|
||||||
let wss;
|
let wss;
|
||||||
|
|
||||||
function __server() {
|
function __server() {
|
||||||
|
@ -110,7 +112,6 @@ async function manageConnection(ws, res) {
|
||||||
__server();
|
__server();
|
||||||
|
|
||||||
wss.retropilotFunc = {
|
wss.retropilotFunc = {
|
||||||
|
|
||||||
findFromDongle: (dongleId) => {
|
findFromDongle: (dongleId) => {
|
||||||
let websocket = null;
|
let websocket = null;
|
||||||
wss.clients.forEach((value) => {
|
wss.clients.forEach((value) => {
|
||||||
|
@ -162,16 +163,18 @@ wss.retropilotFunc = {
|
||||||
method, params, jsonrpc: '2.0', id,
|
method, params, jsonrpc: '2.0', id,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
actionLogger: async (accountId, deviceId, action, userIp, deviceIp, meta, dongleId) => {
|
||||||
actionLogger: async (account_id, device_id, action, user_ip, device_ip, meta, dongle_id) => {
|
|
||||||
await AthenaActionLog.create({
|
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;
|
export default helpers;
|
||||||
|
|
|
@ -12,7 +12,6 @@ const logger = log4js.getLogger();
|
||||||
|
|
||||||
let server;
|
let server;
|
||||||
let wss;
|
let wss;
|
||||||
let controls;
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
function __server() {
|
function __server() {
|
||||||
|
@ -63,7 +62,6 @@ async function authenticateUser(ws, req) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
ws.account = account;
|
ws.account = account;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -98,13 +96,7 @@ async function manageConnection(ws, req) {
|
||||||
// ws.send(JSON.stringify(await commandBuilder('reboot')))
|
// ws.send(JSON.stringify(await commandBuilder('reboot')))
|
||||||
}
|
}
|
||||||
|
|
||||||
const websocketServer = __server();
|
export const websocketServer = __server();
|
||||||
|
export const controls = controlsFunction(websocketServer);
|
||||||
controls = controlsFunction(websocketServer);
|
|
||||||
|
|
||||||
athenaRealtime.realtimeCallback(controls);
|
athenaRealtime.realtimeCallback(controls);
|
||||||
|
|
||||||
export default {
|
|
||||||
controls,
|
|
||||||
websocketServer,
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue