Files
smartuniverse/ts/smartuniverse.classes.universechannel.ts

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-04-13 15:45:48 +02:00
import * as plugins from './smartuniverse.plugins';
2018-04-29 14:17:26 +02:00
import { Objectmap } from 'lik';
2018-04-13 15:45:48 +02:00
/**
2018-04-29 14:17:26 +02:00
* enables messages to stay within a certain scope.
2018-04-13 15:45:48 +02:00
*/
export class UniverseChannel {
2018-04-29 14:17:26 +02:00
/**
* stores the channels that are available within the universe
*/
2018-05-24 00:14:57 +02:00
public static channelStore = new Objectmap<UniverseChannel>();
/**
* allows messages to be processed in a blacklist mode for further analysis
*/
public static blackListChannel = new UniverseChannel('blacklist', 'nada');
2018-05-23 23:50:45 +02:00
2018-05-07 18:50:07 +02:00
/**
2018-05-20 00:41:59 +02:00
* creates new channels
* @param channelArg the name of the topic
* @param passphraseArg the secret thats used for a certain topic.
2018-05-07 18:50:07 +02:00
*/
2018-05-24 00:14:57 +02:00
public static createChannel (channelNameArg: string, passphraseArg: string) {
2018-05-20 00:41:59 +02:00
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
return newChannel;
2018-05-23 23:50:45 +02:00
};
2018-05-24 00:14:57 +02:00
public static authorizeForChannel (channelNameArg: string, passphraseArg: string) {
const foundChannel = this.channelStore.find(universeChannel => {
const result = universeChannel.authenticate(channelNameArg, passphraseArg);
return result;
});
if(foundChannel) {
return foundChannel;
} else {
return this.blackListChannel;
}
};
2018-05-20 00:41:59 +02:00
/**
* the name of the channel
*/
public name: string;
2018-04-29 14:17:26 +02:00
/**
2018-05-20 00:41:59 +02:00
* the passphrase for the channel
2018-04-29 14:17:26 +02:00
*/
2018-05-20 00:41:59 +02:00
public passphrase: string;
2018-04-29 14:17:26 +02:00
2018-05-20 00:41:59 +02:00
constructor(channelNameArg: string, passphraseArg: string) {
this.name = channelNameArg;
this.passphrase = passphraseArg;
UniverseChannel.channelStore.add(this);
}
2018-04-13 15:45:48 +02:00
/**
* authenticates a client on the server side
*/
2018-05-24 00:14:57 +02:00
public authenticate(channelNameArg: string, passphraseArg: string): boolean {
return (this.name === channelNameArg && this.passphrase === passphraseArg);
2018-05-20 00:41:59 +02:00
}
2018-04-13 15:45:48 +02:00
}