2018-05-28 10:07:25 +00:00
|
|
|
import * as plugins from './smartuniverse.plugins';
|
2019-04-11 15:52:01 +00:00
|
|
|
import * as interfaces from './interfaces';
|
2018-05-28 10:07:25 +00:00
|
|
|
|
2019-04-11 15:52:01 +00:00
|
|
|
import { ClientUniverse } from './';
|
2018-05-28 10:07:25 +00:00
|
|
|
|
2019-04-11 15:52:01 +00:00
|
|
|
export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
2018-05-28 10:07:25 +00:00
|
|
|
// ======
|
|
|
|
// STATIC
|
|
|
|
// ======
|
2019-04-22 21:11:51 +00:00
|
|
|
/**
|
|
|
|
* creates a channel and adds it to the cache of clientUniverseArg
|
|
|
|
* @param clientUniverseArg
|
2019-04-22 22:28:57 +00:00
|
|
|
* @param channelNameArg
|
|
|
|
* @param passphraseArg
|
2019-04-22 21:11:51 +00:00
|
|
|
*/
|
2018-05-28 10:07:25 +00:00
|
|
|
public static async createClientUniverseChannel(
|
|
|
|
clientUniverseArg: ClientUniverse,
|
2019-04-22 21:11:51 +00:00
|
|
|
channelNameArg: string,
|
2019-04-22 07:58:36 +00:00
|
|
|
passphraseArg: string
|
2018-05-28 10:07:25 +00:00
|
|
|
): Promise<ClientUniverseChannel> {
|
2019-04-22 22:28:57 +00:00
|
|
|
const clientChannel = new ClientUniverseChannel(
|
|
|
|
clientUniverseArg,
|
|
|
|
channelNameArg,
|
|
|
|
passphraseArg
|
|
|
|
);
|
2019-04-22 21:11:51 +00:00
|
|
|
clientUniverseArg.channelCache.add(clientChannel);
|
2019-04-22 11:06:01 +00:00
|
|
|
await clientChannel.subscribe();
|
2018-05-28 10:07:25 +00:00
|
|
|
return clientChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========
|
|
|
|
// INSTANCE
|
|
|
|
// ========
|
|
|
|
|
2019-04-22 20:04:52 +00:00
|
|
|
// properties
|
|
|
|
public name: string;
|
2019-04-22 07:58:36 +00:00
|
|
|
public passphrase: string;
|
2019-04-22 22:28:57 +00:00
|
|
|
|
2019-04-22 20:04:52 +00:00
|
|
|
// refs
|
|
|
|
public clientUniverse: ClientUniverse;
|
2019-04-22 22:28:57 +00:00
|
|
|
|
|
|
|
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
2018-05-28 10:07:25 +00:00
|
|
|
this.clientUniverse = clientUniverseArg;
|
2019-04-22 20:04:52 +00:00
|
|
|
this.name = nameArg;
|
2019-04-22 11:06:01 +00:00
|
|
|
this.passphrase = passphraseArg;
|
2018-05-28 10:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-22 11:06:01 +00:00
|
|
|
* subscribes to a channel
|
2018-05-28 10:07:25 +00:00
|
|
|
* tells the universe about this instances interest into a channel
|
|
|
|
*/
|
2019-04-22 11:06:01 +00:00
|
|
|
public async subscribe() {
|
2019-04-24 21:27:57 +00:00
|
|
|
const serverCallActionName: interfaces.IServerCallActions = 'subscribe';
|
|
|
|
const serverCallActionPayload: interfaces.IServerCallSubscribeActionPayload = {
|
|
|
|
name: this.name,
|
|
|
|
passphrase: this.passphrase
|
|
|
|
};
|
|
|
|
this.clientUniverse.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
|
2018-05-28 10:07:25 +00:00
|
|
|
}
|
|
|
|
}
|