lintageddon 1
This commit is contained in:
parent
efa28482de
commit
cd876ccfcb
@ -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}`);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
};
|
||||
|
@ -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) {
|
||||
|
@ -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});
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
import ClientBase from '../clientBase';
|
||||
|
||||
var logger = require('../../logger');
|
||||
|
||||
class PublicClient extends ClientBase {};
|
||||
|
||||
export default PublicClient;
|
||||
|
@ -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',
|
||||
|
@ -4,4 +4,4 @@ module.exports = {
|
||||
home : (req: any, res: any) => {
|
||||
res.send(`Welcome to Braid v${app.version}`)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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) => {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user