gotta let the vars live in the moment
This commit is contained in:
parent
52bcd2d570
commit
37859d42a3
@ -17,8 +17,8 @@ class ChannelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createChannel(data: any) {
|
createChannel(data: any) {
|
||||||
var channelExists: PublicChannel|PrivateChannel|CustomChannel|null = this.channelExists(data.channel);
|
let channelExists: PublicChannel|PrivateChannel|CustomChannel|null = this.channelExists(data.channel);
|
||||||
var channel: PublicChannel|PrivateChannel|CustomChannel;
|
let channel: PublicChannel|PrivateChannel|CustomChannel;
|
||||||
|
|
||||||
if (channelExists) {
|
if (channelExists) {
|
||||||
channel = channelExists;
|
channel = channelExists;
|
||||||
@ -43,7 +43,7 @@ class ChannelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addClientToChannel(client: PublicClient|PrivateClient|CustomClient, channel_id: string) {
|
addClientToChannel(client: PublicClient|PrivateClient|CustomClient, channel_id: string) {
|
||||||
var channel: PrivateChannel|PrivateChannel|CustomChannel|null = this.channelExists(channel_id);
|
let channel: PrivateChannel|PrivateChannel|CustomChannel|null = this.channelExists(channel_id);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
channel.addClient(client);
|
channel.addClient(client);
|
||||||
@ -95,9 +95,9 @@ class ChannelManager {
|
|||||||
this.removeClientFromChannel(client.id, client.channel.id)
|
this.removeClientFromChannel(client.id, client.channel.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var channel = this.createChannel(changeRequest);
|
let channel = this.createChannel(changeRequest);
|
||||||
this.addClientToChannel(client, channel.id);
|
this.addClientToChannel(client, channel.id);
|
||||||
var message = {message_type: 'requestExamStatus'};
|
let message = {message_type: 'requestExamStatus'};
|
||||||
channel.broadcastMessage(client, message);
|
channel.broadcastMessage(client, message);
|
||||||
this.purgeEmptyChannels();
|
this.purgeEmptyChannels();
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ class ChannelManager {
|
|||||||
purgeEmptyChannels() {
|
purgeEmptyChannels() {
|
||||||
for (let channel of this.channels) {
|
for (let channel of this.channels) {
|
||||||
if (channel.clients.length == 0 && channel.id != 'default') {
|
if (channel.clients.length == 0 && channel.id != 'default') {
|
||||||
var index = this.channels.indexOf(channel)
|
let 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}`);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,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) {
|
||||||
var 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;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ class ClientManager {
|
|||||||
|
|
||||||
addClient(data: any, channelManager: ChannelManager, ws: WebSocket) {
|
addClient(data: any, channelManager: ChannelManager, ws: WebSocket) {
|
||||||
if (data.client_type && !this.clientExists(data.user_id)) {
|
if (data.client_type && !this.clientExists(data.user_id)) {
|
||||||
var client = this.getClientType(data, channelManager, ws);
|
let client = this.getClientType(data, channelManager, ws);
|
||||||
this.clients.push(client);
|
this.clients.push(client);
|
||||||
logger.accessLog.info(`client added to client manager: ${data.user_id}`);
|
logger.accessLog.info(`client added to client manager: ${data.user_id}`);
|
||||||
return client;
|
return client;
|
||||||
@ -27,7 +27,7 @@ class ClientManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientsOfType(client_type: string) {
|
clientsOfType(client_type: string) {
|
||||||
var result: PublicClient[]|PrivateClient[]|CustomClient[] = [];
|
let result: PublicClient[]|PrivateClient[]|CustomClient[] = [];
|
||||||
|
|
||||||
for (let client of this.clients) {
|
for (let client of this.clients) {
|
||||||
if (client.type() == client_type) {
|
if (client.type() == client_type) {
|
||||||
@ -53,7 +53,7 @@ class ClientManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeClient(id: number) {
|
removeClient(id: number) {
|
||||||
var index: number = 0;
|
let index: number = 0;
|
||||||
|
|
||||||
for (let client of this.clients) {
|
for (let client of this.clients) {
|
||||||
if (client.id == id) {
|
if (client.id == id) {
|
||||||
|
@ -45,7 +45,7 @@ class ClientBase {
|
|||||||
connectToChannel(channel: PublicChannel|PrivateChannel|CustomChannel) {
|
connectToChannel(channel: PublicChannel|PrivateChannel|CustomChannel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
var messageListener = (data: any) => {
|
let messageListener = (data: any) => {
|
||||||
logger.accessLog.info(`starting message transaction on channel ${channel.id}: `, {data: data});
|
logger.accessLog.info(`starting message transaction on channel ${channel.id}: `, {data: data});
|
||||||
data = messageManager.prepareMessage(data, channel, this);
|
data = messageManager.prepareMessage(data, channel, this);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ var app = require('../config/app')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
confirmToken : (req: any, res: any) => {
|
confirmToken : (req: any, res: any) => {
|
||||||
var token = req.body.token
|
let token = req.body.token
|
||||||
res.json({
|
res.json({
|
||||||
response: JSON.stringify(jwt.verify(token, app.secret, app.signOptions))
|
response: JSON.stringify(jwt.verify(token, app.secret, app.signOptions))
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
//external imports
|
//external imports
|
||||||
import * as express from 'express';
|
|
||||||
import * as https from 'https';
|
|
||||||
import * as WebSocket from 'ws';
|
import * as WebSocket from 'ws';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as jwt from 'jsonwebtoken';
|
import * as jwt from 'jsonwebtoken';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
@ -10,45 +7,27 @@ import * as url from 'url';
|
|||||||
var routes = require('./routes');
|
var routes = require('./routes');
|
||||||
var app = require('./config/app');
|
var app = require('./config/app');
|
||||||
var logger = require('./logger');
|
var logger = require('./logger');
|
||||||
|
|
||||||
import ClientManager from './clientManager';
|
import ClientManager from './clientManager';
|
||||||
import ChannelManager from './channelManager';
|
import ChannelManager from './channelManager';
|
||||||
import PublicClient from './clients/types/publicClient';
|
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';
|
||||||
|
|
||||||
|
|
||||||
// if (app.environment == 'development') {
|
|
||||||
// var privateKey = fs.readFileSync(app.privateKey, 'utf8');
|
|
||||||
// var certificate = fs.readFileSync(app.certificate, 'utf8');
|
|
||||||
// var options = {key: privateKey, cert: certificate, hostname: app.hostname};
|
|
||||||
|
|
||||||
// const application = express();
|
|
||||||
// const server = https.createServer(options, application);
|
|
||||||
// var wss = new WebSocket.Server({ server: server, maxPayload:250000, host: app.hostname });
|
|
||||||
|
|
||||||
// application.use(express.json());
|
|
||||||
// application.use('', routes);
|
|
||||||
|
|
||||||
// server.listen(app.port, () => {
|
|
||||||
// console.log(`Braid v${app.version} is running!\n`);
|
|
||||||
// logger.accessLog.info(`Braid v${app.version} is running!\n`);
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
var wss = new WebSocket.Server({ maxPayload:250000, port: app.port });
|
var wss = new WebSocket.Server({ maxPayload:250000, port: app.port });
|
||||||
// }
|
|
||||||
|
|
||||||
let clientManager = new ClientManager();
|
let clientManager = new ClientManager();
|
||||||
let channelManager = new ChannelManager();
|
let channelManager = new ChannelManager();
|
||||||
|
|
||||||
function connectionManager() {
|
function connectionManager() {
|
||||||
wss.on('connection', (ws: WebSocket, request: any, args: string) => {
|
wss.on('connection', (ws: WebSocket, request: any, args: string) => {
|
||||||
var result = JSON.parse(validateJWT(request));
|
let result = JSON.parse(validateJWT(request));
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
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 {
|
||||||
var data = result.data;
|
let 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)) {
|
||||||
@ -80,8 +59,8 @@ function connectionManager() {
|
|||||||
|
|
||||||
function validateJWT(request: any) {
|
function validateJWT(request: any) {
|
||||||
try {
|
try {
|
||||||
var query = url.parse(request.url, true).query
|
let query = url.parse(request.url, true).query
|
||||||
var 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) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user