lint: tidy up websocket
parent
f484ceca72
commit
a3e8cd7853
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue