update to types
This commit is contained in:
46
src/channels/channelBase.ts
Normal file
46
src/channels/channelBase.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import ClientBase from '../clients/clientBase';
|
||||
import MHSClient from '../clients/sites/mhsClient';
|
||||
|
||||
class ChannelBase {
|
||||
id: string;
|
||||
clients: MHSClient[]|ClientBase[] = [];
|
||||
|
||||
constructor(id: string) {
|
||||
this.id = id;
|
||||
console.log('channel created');
|
||||
}
|
||||
|
||||
addClient(client: MHSClient|ClientBase) {
|
||||
console.log(client.data)
|
||||
if (this.clientExists(client.id)) {
|
||||
console.log('client already exits in channel');
|
||||
} else {
|
||||
this.clients.push(client);
|
||||
console.log('added client to channel');
|
||||
}
|
||||
}
|
||||
|
||||
clientExists(id: number) {
|
||||
for (let client of this.clients) {
|
||||
if (client.id == id) {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
broadcastMessage(from: ClientBase|MHSClient|null, message: string) {
|
||||
for (let client of this.clients) {
|
||||
if (client != from) {
|
||||
client.ws.send(message);
|
||||
console.log(`sent to ${client.id}: %s`, message);
|
||||
console.log(message);
|
||||
} else {
|
||||
console.log('client is same as sender');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default ChannelBase;
|
19
src/channels/sites/mhsChannel.ts
Normal file
19
src/channels/sites/mhsChannel.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import ClientBase from '../../clients/clientBase';
|
||||
import MHSClient from '../../clients/sites/mhsClient';
|
||||
import ChannelBase from '../channelBase';
|
||||
|
||||
class MHSChannel extends ChannelBase {
|
||||
broadcastMessage(from: ClientBase|MHSClient|null, message: string) {
|
||||
for (let client of this.clients) {
|
||||
if (client != from) {
|
||||
client.ws.send(message);
|
||||
console.log(`sent to ${client.id}: %s`, message);
|
||||
console.log(message);
|
||||
} else {
|
||||
console.log('client is same as sender');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default MHSChannel;
|
Reference in New Issue
Block a user