2018-04-13 13:45:48 +00:00
|
|
|
import * as plugins from './smartuniverse.plugins';
|
|
|
|
|
2018-04-29 12:17:26 +00:00
|
|
|
import { Objectmap } from 'lik';
|
|
|
|
|
2018-04-13 13:45:48 +00:00
|
|
|
/**
|
2018-04-29 12:17:26 +00:00
|
|
|
* enables messages to stay within a certain scope.
|
2018-04-13 13:45:48 +00:00
|
|
|
*/
|
|
|
|
export class UniverseChannel {
|
2018-04-29 12:17:26 +00:00
|
|
|
/**
|
|
|
|
* stores the channels that are available within the universe
|
|
|
|
*/
|
|
|
|
public static channelStore = new Objectmap();
|
2018-05-23 21:50:45 +00:00
|
|
|
|
2018-05-07 16:50:07 +00:00
|
|
|
/**
|
2018-05-19 22:41:59 +00:00
|
|
|
* creates new channels
|
|
|
|
* @param channelArg the name of the topic
|
|
|
|
* @param passphraseArg the secret thats used for a certain topic.
|
2018-05-07 16:50:07 +00:00
|
|
|
*/
|
2018-05-19 22:41:59 +00:00
|
|
|
public static createChannel = (channelNameArg: string, passphraseArg: string) => {
|
|
|
|
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
|
|
|
|
return newChannel;
|
2018-05-23 21:50:45 +00:00
|
|
|
};
|
|
|
|
|
2018-05-19 22:41:59 +00:00
|
|
|
/**
|
|
|
|
* the name of the channel
|
|
|
|
*/
|
|
|
|
public name: string;
|
2018-04-29 12:17:26 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-19 22:41:59 +00:00
|
|
|
* the passphrase for the channel
|
2018-04-29 12:17:26 +00:00
|
|
|
*/
|
2018-05-19 22:41:59 +00:00
|
|
|
public passphrase: string;
|
2018-04-29 12:17:26 +00:00
|
|
|
|
2018-05-19 22:41:59 +00:00
|
|
|
constructor(channelNameArg: string, passphraseArg: string) {
|
|
|
|
this.name = channelNameArg;
|
|
|
|
this.passphrase = passphraseArg;
|
|
|
|
UniverseChannel.channelStore.add(this);
|
|
|
|
}
|
2018-04-13 13:45:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* authenticates a client on the server side
|
|
|
|
*/
|
2018-05-19 22:41:59 +00:00
|
|
|
public async authenticateClient(passphraseArg: string): boolean {
|
|
|
|
return passphraseArg === this.passphrase;
|
|
|
|
}
|
2018-04-13 13:45:48 +00:00
|
|
|
}
|