diff --git a/src/channelManager.ts b/src/channelManager.ts index 745fac8..3ef9b32 100644 --- a/src/channelManager.ts +++ b/src/channelManager.ts @@ -5,7 +5,7 @@ import PublicClient from './clients/types/publicClient'; import PrivateClient from './clients/types/privateClient'; import CustomClient from './clients/types/customClient'; -var logger = require('./logger'); +const logger = require('./logger'); class ChannelManager { channels: any[] = []; @@ -48,10 +48,10 @@ class ChannelManager { if (channel) { channel.addClient(client); client.connectToChannel(channel); - return {'status': 'success'}; + return {status: 'success'}; } else { logger.accessLog.info(`channel with id ${channel_id} does not exist.`); - return {'status': 'notice', 'message': `channel with id ${channel_id} does not exist.`}; + return {status: 'notice', message: `channel with id ${channel_id} does not exist.`}; } } @@ -60,14 +60,14 @@ class ChannelManager { logger.accessLog.info(`attempting to create channel of type ${data.channel_type}, channel id: ${data.channel}...`); if (data.channel_type == 'public') { - return new PublicChannel(data.channel) + return new PublicChannel(data.channel); } else if (data.channel_type == 'private') { - return new PrivateChannel(data.channel) + return new PrivateChannel(data.channel); } else { - return new CustomChannel(data.channel, data.custom) + return new CustomChannel(data.channel, data.custom); } } catch (e) { - console.log(e) + console.log(e); logger.errorLog.info(e); logger.accessLog.info(`creating base channel: ${data.channel}`); return new PublicChannel(data.channel); @@ -92,7 +92,7 @@ class ChannelManager { changeChannel(client: PublicClient|PrivateClient|CustomClient, changeRequest: any) { if (client.channel != null) { - this.removeClientFromChannel(client.id, client.channel.id) + this.removeClientFromChannel(client.id, client.channel.id); } let channel = this.createChannel(changeRequest); @@ -103,9 +103,9 @@ class ChannelManager { } purgeEmptyChannels() { - for (let channel of this.channels) { + for (const channel of this.channels) { if (channel.clients.length == 0 && channel.id != 'default') { - let index = this.channels.indexOf(channel) + const index = this.channels.indexOf(channel); this.channels.splice(index, 1); logger.accessLog.info(`channel removed: ${channel.id}`); } diff --git a/src/channels/channelBase.ts b/src/channels/channelBase.ts index 453aa7a..b73c227 100644 --- a/src/channels/channelBase.ts +++ b/src/channels/channelBase.ts @@ -2,7 +2,7 @@ import PublicClient from '../clients/types/publicClient'; import PrivateClient from '../clients/types/privateClient'; import CustomClient from '../clients/types/customClient'; -var logger = require('../logger'); +const logger = require('../logger'); class ChannelBase { id: string; @@ -19,7 +19,7 @@ class ChannelBase { to.ws.send(JSON.stringify(message)); logger.accessLog.info(`sent to ${to.id}`, { data: { message: message }}); } else { - logger.accessLog.info(`client is unable to send: ${to.id}`, { data: { message: message }}); + logger.accessLog.info(`client is unable to send: ${to.id}`, { data: {message}}); } } @@ -27,7 +27,7 @@ class ChannelBase { } messageTransactionPossible(_from: PublicClient|PrivateClient|CustomClient, _to: PublicClient|PrivateClient|CustomClient) { - return true + return true; } addClient(client: PublicClient|PrivateClient|CustomClient) { @@ -42,8 +42,8 @@ class ChannelBase { } clientExists(id: number) { - for (let client of this.clients) { - if (client.id == id) { + for (const client of this.clients) { + if (client.id === id) { return client; } } @@ -53,7 +53,7 @@ class ChannelBase { removeClient(id: number) { for (let client of this.clients) { - if (client.id == id) { + if (client.id === id) { let index = this.clients.indexOf(client) this.clients.splice(index, 1); return true; diff --git a/src/channels/types/privateChannel.ts b/src/channels/types/privateChannel.ts index 7dc6b03..a3564bd 100644 --- a/src/channels/types/privateChannel.ts +++ b/src/channels/types/privateChannel.ts @@ -1,14 +1,12 @@ import PrivateClient from '../../clients/types/privateClient'; import ChannelBase from '../channelBase'; -var logger = require('../../logger'); - class PrivateChannel extends ChannelBase { clients: PrivateClient[] = []; messageTransactionPossible(from: PrivateClient, to: PrivateClient) { return ( - to != from && + to !== from && to.roles.includes('receiver') && from.roles.includes('broadcaster') ) diff --git a/src/channels/types/publicChannel.ts b/src/channels/types/publicChannel.ts index 07daaa1..0bde811 100644 --- a/src/channels/types/publicChannel.ts +++ b/src/channels/types/publicChannel.ts @@ -1,14 +1,12 @@ import PublicClient from '../../clients/types/publicClient'; import ChannelBase from '../channelBase'; -var logger = require('../../logger'); - class PublicChannel extends ChannelBase { clients: PublicClient[] = []; messageTransactionPossible(from: PublicClient, to: PublicClient) { return ( - to != from + to !== from ) } }; diff --git a/src/clients/clientBase.ts b/src/clients/clientBase.ts index cc35bbc..2cbe5bd 100644 --- a/src/clients/clientBase.ts +++ b/src/clients/clientBase.ts @@ -5,8 +5,8 @@ import PublicChannel from '../channels/types/publicChannel'; import PrivateChannel from '../channels/types/privateChannel'; import CustomChannel from '../channels/types/customChannel'; -var messageManager = require('../messageManager'); -var logger = require('../logger'); +const messageManager = require('../messageManager'); +const logger = require('../logger'); class ClientBase { ws: WebSocket; @@ -30,9 +30,9 @@ class ClientBase { if (this.channel) { logger.accessLog.info(`starting message transaction on channel ${this.channel.id}: `, {data: data}); data = messageManager.prepareMessage(data, this.channel, this); - this.messageTransaction(data) + this.messageTransaction(data); } - } + }; } getData() { @@ -72,7 +72,7 @@ class ClientBase { break; case 'direct': let to = this.clientManager.getClient(data.message.to) - to.directMessage(data) + to.directMessage(data); break; case 'changeChannel': this.ws.removeListener('message', this.messageListener); @@ -88,7 +88,7 @@ class ClientBase { directMessage(message: any) { this.ws.send(JSON.stringify(message)); - logger.accessLog.info(`sent direct message to ${this.id}`, { data: { message: message }}); + logger.accessLog.info(`sent direct message to ${this.id}`, { data: { message }}); } replaceWebSocket(ws: WebSocket) { diff --git a/src/clients/types/privateClient.ts b/src/clients/types/privateClient.ts index 616838f..469fea4 100644 --- a/src/clients/types/privateClient.ts +++ b/src/clients/types/privateClient.ts @@ -8,7 +8,7 @@ var logger = require('../../logger'); class PrivateClient extends ClientBase { constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) { super(data, ws, channelManager, clientManager); - this.roles = data.user_roles + this.roles = data.user_roles; logger.accessLog.info('Private Client Created', {data: data}); } }; diff --git a/src/clients/types/publicClient.ts b/src/clients/types/publicClient.ts index f66c3f4..bc2c38e 100644 --- a/src/clients/types/publicClient.ts +++ b/src/clients/types/publicClient.ts @@ -1,7 +1,5 @@ import ClientBase from '../clientBase'; -var logger = require('../../logger'); - class PublicClient extends ClientBase {}; export default PublicClient; diff --git a/src/config/app.ts b/src/config/app.ts index 9d50ae3..1fa186d 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -1,7 +1,7 @@ module.exports = { version : '1.2', - whitelist : (process.env.WHITELIST || "http://admin.localhost").split(','), - secret : process.env.SECRET || "test", + whitelist : (process.env.WHITELIST || 'http://admin.localhost').split(','), + secret : process.env.SECRET || 'test', devToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNsaWVudCI6InRlc3QiLCJjbGllbnRfdHlwZSI6InNpdGUiLCJ1c2VyX3R5cGUiOiJ1c2VyIiwidXNlcl9pZCI6MjAwLCJjaGFubmVsIjoidGVzdF9jaGFubmVsIn0sImF1ZCI6ImludGVybmFsIiwiaXNzIjoiWWFyZHN0aWNrIFNvZnR3YXJlIiwic3ViIjoiQnJhaWQgSldUIn0.5KNCov_EW1cycT4Ay0oSvk4Z4PHFedd3bWOyqkHHTBQ', port: process.env.PORT || 80, hostname: process.env.HOSTNAME || 'ysbraid.localhost', diff --git a/src/controllers/appController.ts b/src/controllers/appController.ts index a53cc72..7746e08 100644 --- a/src/controllers/appController.ts +++ b/src/controllers/appController.ts @@ -4,4 +4,4 @@ module.exports = { home : (req: any, res: any) => { res.send(`Welcome to Braid v${app.version}`) } -} +}; diff --git a/src/controllers/authController.ts b/src/controllers/authController.ts index 2f3c9ad..228d014 100644 --- a/src/controllers/authController.ts +++ b/src/controllers/authController.ts @@ -1,6 +1,6 @@ import * as jwt from 'jsonwebtoken'; -var app = require('../config/app') +const app = require('../config/app'); module.exports = { confirmToken : (req: any, res: any) => { diff --git a/src/helpers/clientHelpers.ts b/src/helpers/clientHelpers.ts index bab885a..c86d8a2 100644 --- a/src/helpers/clientHelpers.ts +++ b/src/helpers/clientHelpers.ts @@ -1,7 +1,7 @@ module.exports = { clientExists: function (id: number) { - for (let client of this.clients) { - if (client.id == id) { + for (const client of this.clients) { + if (client.id === id) { return client; } } diff --git a/src/server.ts b/src/server.ts index 5e56bc2..b68f66a 100755 --- a/src/server.ts +++ b/src/server.ts @@ -1,12 +1,11 @@ -//external imports +// external imports import * as WebSocket from 'ws'; import * as jwt from 'jsonwebtoken'; import * as url from 'url'; -//internal imports -var routes = require('./routes'); +// internal imports var app = require('./config/app'); -var logger = require('./logger'); +const logger = require('./logger'); import ClientManager from './clientManager'; import ChannelManager from './channelManager'; @@ -27,7 +26,7 @@ function connectionManager() { ws.send(`Unable to validate JWT, please try again or contact support...`); ws.close(); } else { - let data = result.data; + const data = result.data; logger.accessLog.info(`Client Connected: ${data.user_id}`); if (!channelManager.channelExists(data.channel)) { @@ -59,7 +58,7 @@ function connectionManager() { function validateJWT(request: any) { try { - let query = url.parse(request.url, true).query + let query = url.parse(request.url, true).query; let token = query.token || (app.environment == 'development' ? app.devToken : ''); return JSON.stringify(jwt.verify(token, app.secret, app.signOptions)); } catch (e) { @@ -78,4 +77,4 @@ module.exports = { clientManager: clientManager, channelManager: channelManager, connectionManager: connectionManager -} +}; diff --git a/src/services/validations.ts b/src/services/validations.ts index 3c09c7d..e709784 100644 --- a/src/services/validations.ts +++ b/src/services/validations.ts @@ -17,8 +17,8 @@ class Validations { } constructor(message: any) { - if (message.channel_type == 'custom') { - let conditions = message.conditions + if (message.channel_type === 'custom') { + let conditions = message.conditions; } } }