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 PrivateClient from './clients/types/privateClient';
|
||||||
import CustomClient from './clients/types/customClient';
|
import CustomClient from './clients/types/customClient';
|
||||||
|
|
||||||
var logger = require('./logger');
|
const logger = require('./logger');
|
||||||
|
|
||||||
class ChannelManager {
|
class ChannelManager {
|
||||||
channels: any[] = [];
|
channels: any[] = [];
|
||||||
@ -48,10 +48,10 @@ class ChannelManager {
|
|||||||
if (channel) {
|
if (channel) {
|
||||||
channel.addClient(client);
|
channel.addClient(client);
|
||||||
client.connectToChannel(channel);
|
client.connectToChannel(channel);
|
||||||
return {'status': 'success'};
|
return {status: 'success'};
|
||||||
} else {
|
} else {
|
||||||
logger.accessLog.info(`channel with id ${channel_id} does not exist.`);
|
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}...`);
|
logger.accessLog.info(`attempting to create channel of type ${data.channel_type}, channel id: ${data.channel}...`);
|
||||||
|
|
||||||
if (data.channel_type == 'public') {
|
if (data.channel_type == 'public') {
|
||||||
return new PublicChannel(data.channel)
|
return new PublicChannel(data.channel);
|
||||||
} else if (data.channel_type == 'private') {
|
} else if (data.channel_type == 'private') {
|
||||||
return new PrivateChannel(data.channel)
|
return new PrivateChannel(data.channel);
|
||||||
} else {
|
} else {
|
||||||
return new CustomChannel(data.channel, data.custom)
|
return new CustomChannel(data.channel, data.custom);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e);
|
||||||
logger.errorLog.info(e);
|
logger.errorLog.info(e);
|
||||||
logger.accessLog.info(`creating base channel: ${data.channel}`);
|
logger.accessLog.info(`creating base channel: ${data.channel}`);
|
||||||
return new PublicChannel(data.channel);
|
return new PublicChannel(data.channel);
|
||||||
@ -92,7 +92,7 @@ class ChannelManager {
|
|||||||
|
|
||||||
changeChannel(client: PublicClient|PrivateClient|CustomClient, changeRequest: any) {
|
changeChannel(client: PublicClient|PrivateClient|CustomClient, changeRequest: any) {
|
||||||
if (client.channel != null) {
|
if (client.channel != null) {
|
||||||
this.removeClientFromChannel(client.id, client.channel.id)
|
this.removeClientFromChannel(client.id, client.channel.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let channel = this.createChannel(changeRequest);
|
let channel = this.createChannel(changeRequest);
|
||||||
@ -103,9 +103,9 @@ class ChannelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
purgeEmptyChannels() {
|
purgeEmptyChannels() {
|
||||||
for (let channel of this.channels) {
|
for (const channel of this.channels) {
|
||||||
if (channel.clients.length == 0 && channel.id != 'default') {
|
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);
|
this.channels.splice(index, 1);
|
||||||
logger.accessLog.info(`channel removed: ${channel.id}`);
|
logger.accessLog.info(`channel removed: ${channel.id}`);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import PublicClient from '../clients/types/publicClient';
|
|||||||
import PrivateClient from '../clients/types/privateClient';
|
import PrivateClient from '../clients/types/privateClient';
|
||||||
import CustomClient from '../clients/types/customClient';
|
import CustomClient from '../clients/types/customClient';
|
||||||
|
|
||||||
var logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
|
||||||
class ChannelBase {
|
class ChannelBase {
|
||||||
id: string;
|
id: string;
|
||||||
@ -19,7 +19,7 @@ class ChannelBase {
|
|||||||
to.ws.send(JSON.stringify(message));
|
to.ws.send(JSON.stringify(message));
|
||||||
logger.accessLog.info(`sent to ${to.id}`, { data: { message: message }});
|
logger.accessLog.info(`sent to ${to.id}`, { data: { message: message }});
|
||||||
} else {
|
} 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) {
|
messageTransactionPossible(_from: PublicClient|PrivateClient|CustomClient, _to: PublicClient|PrivateClient|CustomClient) {
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addClient(client: PublicClient|PrivateClient|CustomClient) {
|
addClient(client: PublicClient|PrivateClient|CustomClient) {
|
||||||
@ -42,8 +42,8 @@ class ChannelBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientExists(id: number) {
|
clientExists(id: number) {
|
||||||
for (let client of this.clients) {
|
for (const client of this.clients) {
|
||||||
if (client.id == id) {
|
if (client.id === id) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class ChannelBase {
|
|||||||
|
|
||||||
removeClient(id: number) {
|
removeClient(id: number) {
|
||||||
for (let client of this.clients) {
|
for (let client of this.clients) {
|
||||||
if (client.id == id) {
|
if (client.id === id) {
|
||||||
let index = this.clients.indexOf(client)
|
let index = this.clients.indexOf(client)
|
||||||
this.clients.splice(index, 1);
|
this.clients.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import PrivateClient from '../../clients/types/privateClient';
|
import PrivateClient from '../../clients/types/privateClient';
|
||||||
import ChannelBase from '../channelBase';
|
import ChannelBase from '../channelBase';
|
||||||
|
|
||||||
var logger = require('../../logger');
|
|
||||||
|
|
||||||
class PrivateChannel extends ChannelBase {
|
class PrivateChannel extends ChannelBase {
|
||||||
clients: PrivateClient[] = [];
|
clients: PrivateClient[] = [];
|
||||||
|
|
||||||
messageTransactionPossible(from: PrivateClient, to: PrivateClient) {
|
messageTransactionPossible(from: PrivateClient, to: PrivateClient) {
|
||||||
return (
|
return (
|
||||||
to != from &&
|
to !== from &&
|
||||||
to.roles.includes('receiver') &&
|
to.roles.includes('receiver') &&
|
||||||
from.roles.includes('broadcaster')
|
from.roles.includes('broadcaster')
|
||||||
)
|
)
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import PublicClient from '../../clients/types/publicClient';
|
import PublicClient from '../../clients/types/publicClient';
|
||||||
import ChannelBase from '../channelBase';
|
import ChannelBase from '../channelBase';
|
||||||
|
|
||||||
var logger = require('../../logger');
|
|
||||||
|
|
||||||
class PublicChannel extends ChannelBase {
|
class PublicChannel extends ChannelBase {
|
||||||
clients: PublicClient[] = [];
|
clients: PublicClient[] = [];
|
||||||
|
|
||||||
messageTransactionPossible(from: PublicClient, to: PublicClient) {
|
messageTransactionPossible(from: PublicClient, to: PublicClient) {
|
||||||
return (
|
return (
|
||||||
to != from
|
to !== from
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,8 +5,8 @@ import PublicChannel from '../channels/types/publicChannel';
|
|||||||
import PrivateChannel from '../channels/types/privateChannel';
|
import PrivateChannel from '../channels/types/privateChannel';
|
||||||
import CustomChannel from '../channels/types/customChannel';
|
import CustomChannel from '../channels/types/customChannel';
|
||||||
|
|
||||||
var messageManager = require('../messageManager');
|
const messageManager = require('../messageManager');
|
||||||
var logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
|
||||||
class ClientBase {
|
class ClientBase {
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
@ -30,9 +30,9 @@ class ClientBase {
|
|||||||
if (this.channel) {
|
if (this.channel) {
|
||||||
logger.accessLog.info(`starting message transaction on channel ${this.channel.id}: `, {data: data});
|
logger.accessLog.info(`starting message transaction on channel ${this.channel.id}: `, {data: data});
|
||||||
data = messageManager.prepareMessage(data, this.channel, this);
|
data = messageManager.prepareMessage(data, this.channel, this);
|
||||||
this.messageTransaction(data)
|
this.messageTransaction(data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getData() {
|
getData() {
|
||||||
@ -72,7 +72,7 @@ class ClientBase {
|
|||||||
break;
|
break;
|
||||||
case 'direct':
|
case 'direct':
|
||||||
let to = this.clientManager.getClient(data.message.to)
|
let to = this.clientManager.getClient(data.message.to)
|
||||||
to.directMessage(data)
|
to.directMessage(data);
|
||||||
break;
|
break;
|
||||||
case 'changeChannel':
|
case 'changeChannel':
|
||||||
this.ws.removeListener('message', this.messageListener);
|
this.ws.removeListener('message', this.messageListener);
|
||||||
@ -88,7 +88,7 @@ class ClientBase {
|
|||||||
|
|
||||||
directMessage(message: any) {
|
directMessage(message: any) {
|
||||||
this.ws.send(JSON.stringify(message));
|
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) {
|
replaceWebSocket(ws: WebSocket) {
|
||||||
|
@ -8,7 +8,7 @@ var logger = require('../../logger');
|
|||||||
class PrivateClient extends ClientBase {
|
class PrivateClient extends ClientBase {
|
||||||
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
|
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
|
||||||
super(data, ws, channelManager, clientManager);
|
super(data, ws, channelManager, clientManager);
|
||||||
this.roles = data.user_roles
|
this.roles = data.user_roles;
|
||||||
logger.accessLog.info('Private Client Created', {data: data});
|
logger.accessLog.info('Private Client Created', {data: data});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import ClientBase from '../clientBase';
|
import ClientBase from '../clientBase';
|
||||||
|
|
||||||
var logger = require('../../logger');
|
|
||||||
|
|
||||||
class PublicClient extends ClientBase {};
|
class PublicClient extends ClientBase {};
|
||||||
|
|
||||||
export default PublicClient;
|
export default PublicClient;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
version : '1.2',
|
version : '1.2',
|
||||||
whitelist : (process.env.WHITELIST || "http://admin.localhost").split(','),
|
whitelist : (process.env.WHITELIST || 'http://admin.localhost').split(','),
|
||||||
secret : process.env.SECRET || "test",
|
secret : process.env.SECRET || 'test',
|
||||||
devToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNsaWVudCI6InRlc3QiLCJjbGllbnRfdHlwZSI6InNpdGUiLCJ1c2VyX3R5cGUiOiJ1c2VyIiwidXNlcl9pZCI6MjAwLCJjaGFubmVsIjoidGVzdF9jaGFubmVsIn0sImF1ZCI6ImludGVybmFsIiwiaXNzIjoiWWFyZHN0aWNrIFNvZnR3YXJlIiwic3ViIjoiQnJhaWQgSldUIn0.5KNCov_EW1cycT4Ay0oSvk4Z4PHFedd3bWOyqkHHTBQ',
|
devToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNsaWVudCI6InRlc3QiLCJjbGllbnRfdHlwZSI6InNpdGUiLCJ1c2VyX3R5cGUiOiJ1c2VyIiwidXNlcl9pZCI6MjAwLCJjaGFubmVsIjoidGVzdF9jaGFubmVsIn0sImF1ZCI6ImludGVybmFsIiwiaXNzIjoiWWFyZHN0aWNrIFNvZnR3YXJlIiwic3ViIjoiQnJhaWQgSldUIn0.5KNCov_EW1cycT4Ay0oSvk4Z4PHFedd3bWOyqkHHTBQ',
|
||||||
port: process.env.PORT || 80,
|
port: process.env.PORT || 80,
|
||||||
hostname: process.env.HOSTNAME || 'ysbraid.localhost',
|
hostname: process.env.HOSTNAME || 'ysbraid.localhost',
|
||||||
|
@ -4,4 +4,4 @@ module.exports = {
|
|||||||
home : (req: any, res: any) => {
|
home : (req: any, res: any) => {
|
||||||
res.send(`Welcome to Braid v${app.version}`)
|
res.send(`Welcome to Braid v${app.version}`)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as jwt from 'jsonwebtoken';
|
import * as jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
var app = require('../config/app')
|
const app = require('../config/app');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
confirmToken : (req: any, res: any) => {
|
confirmToken : (req: any, res: any) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
clientExists: function (id: number) {
|
clientExists: function (id: number) {
|
||||||
for (let client of this.clients) {
|
for (const client of this.clients) {
|
||||||
if (client.id == id) {
|
if (client.id === id) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ import * as jwt from 'jsonwebtoken';
|
|||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
// internal imports
|
// internal imports
|
||||||
var routes = require('./routes');
|
|
||||||
var app = require('./config/app');
|
var app = require('./config/app');
|
||||||
var logger = require('./logger');
|
const logger = require('./logger');
|
||||||
|
|
||||||
import ClientManager from './clientManager';
|
import ClientManager from './clientManager';
|
||||||
import ChannelManager from './channelManager';
|
import ChannelManager from './channelManager';
|
||||||
@ -27,7 +26,7 @@ function connectionManager() {
|
|||||||
ws.send(`Unable to validate JWT, please try again or contact support...`);
|
ws.send(`Unable to validate JWT, please try again or contact support...`);
|
||||||
ws.close();
|
ws.close();
|
||||||
} else {
|
} else {
|
||||||
let data = result.data;
|
const data = result.data;
|
||||||
logger.accessLog.info(`Client Connected: ${data.user_id}`);
|
logger.accessLog.info(`Client Connected: ${data.user_id}`);
|
||||||
|
|
||||||
if (!channelManager.channelExists(data.channel)) {
|
if (!channelManager.channelExists(data.channel)) {
|
||||||
@ -59,7 +58,7 @@ function connectionManager() {
|
|||||||
|
|
||||||
function validateJWT(request: any) {
|
function validateJWT(request: any) {
|
||||||
try {
|
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 : '');
|
let token = query.token || (app.environment == 'development' ? app.devToken : '');
|
||||||
return JSON.stringify(jwt.verify(token, app.secret, app.signOptions));
|
return JSON.stringify(jwt.verify(token, app.secret, app.signOptions));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -78,4 +77,4 @@ module.exports = {
|
|||||||
clientManager: clientManager,
|
clientManager: clientManager,
|
||||||
channelManager: channelManager,
|
channelManager: channelManager,
|
||||||
connectionManager: connectionManager
|
connectionManager: connectionManager
|
||||||
}
|
};
|
||||||
|
@ -17,8 +17,8 @@ class Validations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(message: any) {
|
constructor(message: any) {
|
||||||
if (message.channel_type == 'custom') {
|
if (message.channel_type === 'custom') {
|
||||||
let conditions = message.conditions
|
let conditions = message.conditions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user