added unit testing, and started implementing unit tests...phew
This commit is contained in:
@ -1,22 +1,25 @@
|
||||
import ClientBase from '../clients/clientBase';
|
||||
import MHSClient from '../clients/sites/mhsClient';
|
||||
|
||||
var logger = require('../logger');
|
||||
|
||||
class ChannelBase {
|
||||
id: string;
|
||||
clients: MHSClient[]|ClientBase[] = [];
|
||||
|
||||
constructor(id: string) {
|
||||
this.id = id;
|
||||
console.log('channel created');
|
||||
logger.accessLog.info('Channel Created', {channelId: id});
|
||||
}
|
||||
|
||||
addClient(client: MHSClient|ClientBase) {
|
||||
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'};
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,12 +37,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`};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2,17 +2,20 @@ import ClientBase from '../../clients/clientBase';
|
||||
import MHSClient from '../../clients/sites/mhsClient';
|
||||
import ChannelBase from '../channelBase';
|
||||
|
||||
var logger = require('../../logger');
|
||||
|
||||
class MHSChannel extends ChannelBase {
|
||||
broadcastMessage(from: ClientBase|MHSClient|null, message: string) {
|
||||
for (let client of this.clients) {
|
||||
if (client != from && client.data.user_type == 'teacher') {
|
||||
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 and/or not a teacher.');
|
||||
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