added unit testing, and started implementing unit tests...phew
This commit is contained in:
16
dist/server/channels/channelBase.js
vendored
16
dist/server/channels/channelBase.js
vendored
@ -1,19 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var logger = require('../logger');
|
||||
class ChannelBase {
|
||||
constructor(id) {
|
||||
this.clients = [];
|
||||
this.id = id;
|
||||
console.log('channel created');
|
||||
logger.accessLog.info('Channel Created', { channelId: id });
|
||||
}
|
||||
addClient(client) {
|
||||
console.log(client.data);
|
||||
if (this.clientExists(client.id)) {
|
||||
console.log('client already exits in channel');
|
||||
logger.errorLog.info('Client already exits in channel', { channelId: this.id, clientId: client.id });
|
||||
return { 'status': 'notice', 'message': 'client aleady exists in channel' };
|
||||
}
|
||||
else {
|
||||
this.clients.push(client);
|
||||
console.log('added client to channel');
|
||||
logger.accessLog.info('Added client to channel', { channelId: this.id, clientId: client.id });
|
||||
return { 'status': 'success', 'message': 'client added' };
|
||||
}
|
||||
}
|
||||
clientExists(id) {
|
||||
@ -28,13 +30,13 @@ class ChannelBase {
|
||||
for (let client of this.clients) {
|
||||
if (client != from) {
|
||||
client.ws.send(message);
|
||||
console.log(`sent to ${client.id}: %s`, message);
|
||||
console.log(message);
|
||||
logger.accessLog.info(`sent to ${client.id}: `, { message: message });
|
||||
}
|
||||
else {
|
||||
console.log('client is same as sender');
|
||||
logger.accessLog.info(`client is same as sender: ${client.id} - `, { message: message });
|
||||
}
|
||||
}
|
||||
return { 'status': 'success', 'message': `message broadcast complete` };
|
||||
}
|
||||
}
|
||||
;
|
||||
|
Reference in New Issue
Block a user