update to types

This commit is contained in:
Josh Burman
2019-03-11 14:35:33 -04:00
parent 8fa7f98493
commit cdd6179992
28 changed files with 518 additions and 39 deletions

View File

@ -1,20 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ClientManager {
constructor(data, ws) {
this.ws = ws;
this.client(data);
constructor() {
this.clients = [];
//...maybe one day
}
client(data) {
if (data.site) {
console.log('legit: ' + data.site);
addClient(data, ws) {
if (data.client_type && !this.clientExists(data.user_id)) {
var Client = require(`./clients/${data.client_type}s/${data.client}client`);
var client = new Client(data, ws);
this.clients.push(client);
console.log('client added to client manager');
return client;
}
else {
console.log('no client type designated, socket disconnect.');
this.ws.close();
console.log('no client type designated or client already exists, socket disconnected.');
ws.close();
return null;
}
}
clientsOfType(client_type) {
var result = [];
for (let client of this.clients) {
if (client.type() == client_type) {
result.push(client);
}
}
return result;
}
clientExists(id) {
for (let client of this.clients) {
if (client.id == id) {
return client;
}
}
return null;
}
getClient(id) {
return this.clientExists(id);
}
removeClient(id) {
var index = 0;
for (let client of this.clients) {
if (client.id == id) {
client.ws.close();
this.clients.splice(index, 1);
console.log('client disconnected');
return true;
}
index++;
}
}
}
;
module.exports = ClientManager;
// user_type: 'user', user_id: 125, site: 'mhs' }
exports.default = ClientManager;
// { :client => 'mhs', :client_type => 'site', :user_id => 125, :user_type => 'user' }
// var exampleSocket = new WebSocket("wss://ysbraid.localhost:8443?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNsaWVudCI6Im1ocyIsImNsaWVudF90eXBlIjoic2l0ZSIsInVzZXJfdHlwZSI6InVzZXIiLCJ1c2VyX2lkIjoxMjV9LCJleHAiOjE1NTI4MDExMDUsImF1ZCI6ImludGVybmFsIiwiaXNzIjoiWWFyZHN0aWNrIFNvZnR3YXJlIiwic3ViIjoiQnJhaWQgSldUIn0.fkfoqoWNjOeKfsXXJxh-9lBudhFsxhUt9fUIT1BXOLU");
//# sourceMappingURL=clientManager.js.map