fix(core): update
This commit is contained in:
parent
83807d7c5c
commit
a5e849aa17
@ -11,7 +11,7 @@ let testClientChannel: smartuniverse.ClientUniverseChannel;
|
||||
const testChannelData = {
|
||||
channelName: 'awesomeTestChannel',
|
||||
channelPass: 'awesomeChannelPAss'
|
||||
}
|
||||
};
|
||||
|
||||
tap.test('first test', async () => {
|
||||
testUniverse = new smartuniverse.Universe({
|
||||
@ -43,9 +43,7 @@ tap.test('should get a observable correctly', async () => {
|
||||
tap.test('should send a message correctly', async () => {
|
||||
await testUniverseClient.sendMessage({
|
||||
messageText: 'hello',
|
||||
passphrase: 'wowza',
|
||||
targetChannelName: 'channel1',
|
||||
|
||||
targetChannelName: 'channel1'
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -31,11 +31,34 @@ export class ClientUniverse {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a channel to the channelcache
|
||||
* TODO: verify channel before adding it to the channel cache
|
||||
*/
|
||||
public async addChannel (channelNameArg: string, passphraseArg: string) {
|
||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
||||
this,
|
||||
channelNameArg,
|
||||
passphraseArg
|
||||
);
|
||||
this.channelCache.add(clientUniverseChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a channel from the channelcache
|
||||
* @param channelName
|
||||
* @param passphraseArg
|
||||
*/
|
||||
public async getChannel(channelName: string, passphraseArg?: string): Promise<ClientUniverseChannel> {
|
||||
await this.checkConnection();
|
||||
return clientUniverseChannel;
|
||||
}
|
||||
|
||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||
const requestBody: interfaces.IUniverseMessage = {
|
||||
id: plugins.smartunique.shortId(),
|
||||
timestamp: Date.now(),
|
||||
passphrase: (await this.getChannel(messageArg.targetChannelName)).,
|
||||
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
|
||||
...messageArg,
|
||||
|
||||
};
|
||||
@ -46,21 +69,15 @@ export class ClientUniverse {
|
||||
});
|
||||
}
|
||||
|
||||
public async getChannel(channelName: string, passphraseArg?: string): Promise<ClientUniverseChannel> {
|
||||
await this.checkConnection();
|
||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
||||
this,
|
||||
channelName
|
||||
);
|
||||
this.channelCache.add(clientUniverseChannel);
|
||||
return clientUniverseChannel;
|
||||
}
|
||||
|
||||
public close() {
|
||||
this.socketClient.disconnect();
|
||||
}
|
||||
|
||||
private async checkConnection() {
|
||||
/**
|
||||
* checks the connection towards a universe server
|
||||
* since password validation is done through other means, a connection should always be possible
|
||||
*/
|
||||
private async checkConnection(): Promise<void> {
|
||||
if (!this.socketClient && !this.observableIntake) {
|
||||
const parsedURL = url.parse(this.options.serverAddress);
|
||||
this.socketClient = new SmartsocketClient({
|
||||
|
@ -13,7 +13,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
passphraseArg: string
|
||||
): Promise<ClientUniverseChannel> {
|
||||
const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg);
|
||||
await clientChannel.transmitSubscription();
|
||||
await clientChannel.subscribe();
|
||||
return clientChannel;
|
||||
}
|
||||
|
||||
@ -26,13 +26,14 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
|
||||
constructor(clientUniverseArg: ClientUniverse, passphraseArg: string) {
|
||||
this.clientUniverse = clientUniverseArg;
|
||||
this.passphrase = passphraseArg
|
||||
this.passphrase = passphraseArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* subscribes to a channel
|
||||
* tells the universe about this instances interest into a channel
|
||||
*/
|
||||
public async transmitSubscription() {
|
||||
public async subscribe() {
|
||||
this.clientUniverse.socketClient;
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,9 @@ export class Universe {
|
||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
allowedRoles: [ClientRole],
|
||||
funcName: 'channelSubscription',
|
||||
funcDef: () => {} // TODO: implement an action upon connection of clients
|
||||
funcDef: () => {
|
||||
console.log('a client connected');
|
||||
} // TODO: implement an action upon connection of clients
|
||||
});
|
||||
|
||||
// add smartsocket to the running smartexpress app
|
||||
|
Loading…
x
Reference in New Issue
Block a user