56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const channelBase_1 = require("./channels/channelBase");
|
|
class ChannelManager {
|
|
constructor() {
|
|
this.channels = [];
|
|
// create default channel...
|
|
var channel = new channelBase_1.default('default');
|
|
this.channels.push(channel);
|
|
}
|
|
createChannel(data) {
|
|
var channel = this.channelExists(data.channel);
|
|
if (channel) {
|
|
console.log('channel already exists');
|
|
}
|
|
else {
|
|
channel = this.getChannelType(data);
|
|
channel ? this.channels.push(channel) : null;
|
|
console.log('added channel to channel manager');
|
|
}
|
|
}
|
|
channelExists(channel_id) {
|
|
for (let channel of this.channels) {
|
|
if (channel.id == channel_id) {
|
|
return channel;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
addClientToChannel(client, channel_id) {
|
|
var channel = this.channelExists(channel_id);
|
|
if (channel) {
|
|
channel.addClient(client);
|
|
client.connectToChannel(channel);
|
|
}
|
|
else {
|
|
console.log(`channel with id ${channel_id} does not exist.`);
|
|
}
|
|
}
|
|
getChannelType(data) {
|
|
try {
|
|
var Channel = require(`./channels/${data.client_type}s/${data.client}channel`);
|
|
console.log(`attempting to create channel of type ${data.client}, channel id: ${data.channel}...`);
|
|
return new Channel(data.channel);
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
console.log(`creating base channel`);
|
|
return new channelBase_1.default(data.channel);
|
|
}
|
|
}
|
|
}
|
|
;
|
|
exports.default = ChannelManager;
|
|
// { :client => 'mhs', :client_type => 'site', :user_id => 125, :user_type => 'user', :channel => 'mhs_1239' }
|
|
//# sourceMappingURL=channelManager.js.map
|