lint: tidy up websocket
parent
f484ceca72
commit
a3e8cd7853
|
@ -8,12 +8,15 @@ const log4js = require('log4js');
|
||||||
const models = require('../../models/index.model');
|
const models = require('../../models/index.model');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
const authenticationController = require('../../controllers/authentication');
|
const authenticationController = require('../../controllers/authentication');
|
||||||
const deviceController = require('../../controllers/devices');
|
const deviceController = require('../../controllers/devices');
|
||||||
|
|
||||||
const logger = log4js.getLogger('default');
|
const logger = log4js.getLogger('default');
|
||||||
|
|
||||||
|
let helpers;
|
||||||
let wss;
|
let wss;
|
||||||
|
|
||||||
function __server() {
|
function __server() {
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
|
@ -171,6 +174,6 @@ wss.retropilotFunc = {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpers = require('./helpers')(wss);
|
helpers = require('./helpers')(wss);
|
||||||
|
|
||||||
module.exports = helpers;
|
module.exports = helpers;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
const authenticationController = require('../../controllers/authentication');
|
const authenticationController = require('../../controllers/authentication');
|
||||||
const deviceController = require('../../controllers/devices');
|
const deviceController = require('../../controllers/devices');
|
||||||
const athenaRealtime = require('../athena/index');
|
const athenaRealtime = require('../athena/index');
|
||||||
|
|
|
@ -2,30 +2,45 @@ const deviceController = require('../../controllers/devices');
|
||||||
|
|
||||||
let wss;
|
let wss;
|
||||||
|
|
||||||
async function getDongleOwners(dongle_id) {
|
async function getDongleOwners(dongleId) {
|
||||||
const owners = await deviceController.getOwnersFromDongle(dongle_id);
|
const owners = await deviceController.getOwnersFromDongle(dongleId);
|
||||||
console.log('dongle owners', owners);
|
console.log('dongle owners', owners);
|
||||||
return owners;
|
return owners;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function broadcastToAccounts(owners, data) {
|
async function broadcastToAccounts(owners, data) {
|
||||||
wss.clients.forEach((ws) => {
|
wss.clients.forEach((ws) => {
|
||||||
owners.data.forEach((account_id) => {
|
owners.data.forEach((accountId) => {
|
||||||
if (account_id === ws.account.id) {
|
if (accountId === ws.account.id) {
|
||||||
ws.send(JSON.stringify(data));
|
ws.send(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dongleStatus(dongle_id, status) {
|
async function dongleStatus(dongleId, status) {
|
||||||
const owners = await getDongleOwners(dongle_id);
|
const owners = await getDongleOwners(dongleId);
|
||||||
await broadcastToAccounts(owners, { command: 'dongle_status', id: Date.now(), data: { dongle_id, online: status, time: Date.now() } });
|
await broadcastToAccounts(owners, {
|
||||||
|
command: 'dongle_status',
|
||||||
|
id: Date.now(),
|
||||||
|
data: {
|
||||||
|
dongle_id: dongleId,
|
||||||
|
online: status,
|
||||||
|
time: Date.now(),
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function passData(dongle_id, msg) {
|
async function passData(dongleId, msg) {
|
||||||
const owners = await getDongleOwners(dongle_id);
|
const owners = await getDongleOwners(dongleId);
|
||||||
await broadcastToAccounts(owners, { command: 'data_return', id: msg.id, data: { dongle_id, return: msg } });
|
await broadcastToAccounts(owners, {
|
||||||
|
command: 'data_return',
|
||||||
|
id: msg.id,
|
||||||
|
data: {
|
||||||
|
dongle_id: dongleId,
|
||||||
|
return: msg,
|
||||||
|
},
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ const config = require('../../config');
|
||||||
let controls = require('./controls');
|
let controls = require('./controls');
|
||||||
|
|
||||||
const authenticationController = require('../../controllers/authentication');
|
const authenticationController = require('../../controllers/authentication');
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
const deviceController = require('../../controllers/devices');
|
const deviceController = require('../../controllers/devices');
|
||||||
|
|
||||||
const logger = log4js.getLogger('default');
|
const logger = log4js.getLogger('default');
|
||||||
|
@ -34,6 +35,7 @@ function __server() {
|
||||||
return wss;
|
return wss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function buildResponse(ws, success, msg, data) {
|
function buildResponse(ws, success, msg, data) {
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
success, msg, data, timestamp: Date.now(),
|
success, msg, data, timestamp: Date.now(),
|
||||||
|
|
Loading…
Reference in New Issue