properly delegate to sub classes for channels and clients

This commit is contained in:
Josh Burman
2019-03-11 16:55:44 -04:00
parent cdd6179992
commit 74aad4a957
11 changed files with 66 additions and 44 deletions

View File

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const clientBase_1 = require("./clients/clientBase");
class ClientManager {
constructor() {
this.clients = [];
@ -7,8 +8,7 @@ class ClientManager {
}
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);
var client = this.getClientType(data, ws);
this.clients.push(client);
console.log('client added to client manager');
return client;
@ -51,6 +51,18 @@ class ClientManager {
index++;
}
}
getClientType(data, ws) {
try {
var Client = require(`./clients/${data.client_type}s/${data.client}client`);
console.log(`attempting to create client of type ${data.client}, client id: ${data.user_id}...`);
return new Client(data, ws);
}
catch (e) {
console.log(e);
console.log(`creating base client`);
return new clientBase_1.default(data, ws);
}
}
}
;
exports.default = ClientManager;