From 30a02ae48bb95dd846855203fc19dbbc4cebcdfc Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 22 Apr 2019 23:11:51 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 12 ++++++------ ts/smartuniverse.classes.clientuniverse.ts | 4 ++-- ts/smartuniverse.classes.clientuniversechannel.ts | 11 +++++++++-- ts/smartuniverse.classes.universechannel.ts | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/test/test.ts b/test/test.ts index 1305e90..ed2cb64 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,7 +5,7 @@ import * as smartuniverse from '../ts/index'; import { Observable } from 'rxjs'; let testUniverse: smartuniverse.Universe; -let testUniverseClient: smartuniverse.ClientUniverse; +let testClientUniverse: smartuniverse.ClientUniverse; let testClientChannel: smartuniverse.ClientUniverseChannel; const testChannelData = { @@ -25,10 +25,10 @@ tap.test('add a message to the SmartUniverse', async () => { // testing message handling tap.test('create smartuniverse client', async () => { - testUniverseClient = new smartuniverse.ClientUniverse({ + testClientUniverse = new smartuniverse.ClientUniverse({ serverAddress: 'http://localhost:8765' }); - expect(testUniverseClient).to.be.instanceof(smartuniverse.ClientUniverse); + expect(testClientUniverse).to.be.instanceof(smartuniverse.ClientUniverse); }); tap.test('should add a channel to the universe', async () => { @@ -36,12 +36,12 @@ tap.test('should add a channel to the universe', async () => { }); tap.test('should get a observable correctly', async () => { - testClientChannel = await testUniverseClient.getChannel(testChannelData.channelName, testChannelData.channelPass); + testClientChannel = await testClientUniverse.getChannel(testChannelData.channelName); expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel); }); tap.test('should send a message correctly', async () => { - await testUniverseClient.sendMessage({ + await testClientUniverse.sendMessage({ messageText: 'hello', targetChannelName: 'channel1' }); @@ -50,7 +50,7 @@ tap.test('should send a message correctly', async () => { tap.test('should receive a message correctly', async () => {}); tap.test('should disconnect the client correctly', async () => { - testUniverseClient.close(); + testClientUniverse.close(); }); tap.test('should end the server correctly', async tools => { diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index 2b72ad6..afc4ed7 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -42,12 +42,12 @@ export class ClientUniverse { throw new Error('channel exists'); } - const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel( + // lets create the channel + ClientUniverseChannel.createClientUniverseChannel( this, channelNameArg, passphraseArg ); - this.channelCache.add(clientUniverseChannel); } /** diff --git a/ts/smartuniverse.classes.clientuniversechannel.ts b/ts/smartuniverse.classes.clientuniversechannel.ts index 446c57b..3276c9b 100644 --- a/ts/smartuniverse.classes.clientuniversechannel.ts +++ b/ts/smartuniverse.classes.clientuniversechannel.ts @@ -7,12 +7,19 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { // ====== // STATIC // ====== + /** + * creates a channel and adds it to the cache of clientUniverseArg + * @param clientUniverseArg + * @param channelNameArg + * @param passphraseArg + */ public static async createClientUniverseChannel( clientUniverseArg: ClientUniverse, - channelName: string, + channelNameArg: string, passphraseArg: string ): Promise { - const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg); + const clientChannel = new ClientUniverseChannel(clientUniverseArg, channelNameArg, passphraseArg); + clientUniverseArg.channelCache.add(clientChannel); await clientChannel.subscribe(); return clientChannel; } diff --git a/ts/smartuniverse.classes.universechannel.ts b/ts/smartuniverse.classes.universechannel.ts index ca32997..0f9e87f 100644 --- a/ts/smartuniverse.classes.universechannel.ts +++ b/ts/smartuniverse.classes.universechannel.ts @@ -83,8 +83,8 @@ export class UniverseChannel { */ public authenticate(universeMessageArg: UniverseMessage): boolean { return ( - this.name === universeMessageArg.requestedChannelName && - this.passphrase === universeMessageArg.requestedChannelPassphrase + this.name === universeMessageArg.targetChannelName && + this.passphrase === universeMessageArg.passphrase ); }