fix(core): update
This commit is contained in:
parent
241182ed2e
commit
30a02ae48b
12
test/test.ts
12
test/test.ts
@ -5,7 +5,7 @@ import * as smartuniverse from '../ts/index';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
let testUniverse: smartuniverse.Universe;
|
let testUniverse: smartuniverse.Universe;
|
||||||
let testUniverseClient: smartuniverse.ClientUniverse;
|
let testClientUniverse: smartuniverse.ClientUniverse;
|
||||||
let testClientChannel: smartuniverse.ClientUniverseChannel;
|
let testClientChannel: smartuniverse.ClientUniverseChannel;
|
||||||
|
|
||||||
const testChannelData = {
|
const testChannelData = {
|
||||||
@ -25,10 +25,10 @@ tap.test('add a message to the SmartUniverse', async () => {
|
|||||||
|
|
||||||
// testing message handling
|
// testing message handling
|
||||||
tap.test('create smartuniverse client', async () => {
|
tap.test('create smartuniverse client', async () => {
|
||||||
testUniverseClient = new smartuniverse.ClientUniverse({
|
testClientUniverse = new smartuniverse.ClientUniverse({
|
||||||
serverAddress: 'http://localhost:8765'
|
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 () => {
|
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 () => {
|
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);
|
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message correctly', async () => {
|
tap.test('should send a message correctly', async () => {
|
||||||
await testUniverseClient.sendMessage({
|
await testClientUniverse.sendMessage({
|
||||||
messageText: 'hello',
|
messageText: 'hello',
|
||||||
targetChannelName: 'channel1'
|
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 receive a message correctly', async () => {});
|
||||||
|
|
||||||
tap.test('should disconnect the client correctly', async () => {
|
tap.test('should disconnect the client correctly', async () => {
|
||||||
testUniverseClient.close();
|
testClientUniverse.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should end the server correctly', async tools => {
|
tap.test('should end the server correctly', async tools => {
|
||||||
|
@ -42,12 +42,12 @@ export class ClientUniverse {
|
|||||||
throw new Error('channel exists');
|
throw new Error('channel exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
// lets create the channel
|
||||||
|
ClientUniverseChannel.createClientUniverseChannel(
|
||||||
this,
|
this,
|
||||||
channelNameArg,
|
channelNameArg,
|
||||||
passphraseArg
|
passphraseArg
|
||||||
);
|
);
|
||||||
this.channelCache.add(clientUniverseChannel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,12 +7,19 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
// ======
|
// ======
|
||||||
// STATIC
|
// STATIC
|
||||||
// ======
|
// ======
|
||||||
|
/**
|
||||||
|
* creates a channel and adds it to the cache of clientUniverseArg
|
||||||
|
* @param clientUniverseArg
|
||||||
|
* @param channelNameArg
|
||||||
|
* @param passphraseArg
|
||||||
|
*/
|
||||||
public static async createClientUniverseChannel(
|
public static async createClientUniverseChannel(
|
||||||
clientUniverseArg: ClientUniverse,
|
clientUniverseArg: ClientUniverse,
|
||||||
channelName: string,
|
channelNameArg: string,
|
||||||
passphraseArg: string
|
passphraseArg: string
|
||||||
): Promise<ClientUniverseChannel> {
|
): Promise<ClientUniverseChannel> {
|
||||||
const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg);
|
const clientChannel = new ClientUniverseChannel(clientUniverseArg, channelNameArg, passphraseArg);
|
||||||
|
clientUniverseArg.channelCache.add(clientChannel);
|
||||||
await clientChannel.subscribe();
|
await clientChannel.subscribe();
|
||||||
return clientChannel;
|
return clientChannel;
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ export class UniverseChannel {
|
|||||||
*/
|
*/
|
||||||
public authenticate(universeMessageArg: UniverseMessage): boolean {
|
public authenticate(universeMessageArg: UniverseMessage): boolean {
|
||||||
return (
|
return (
|
||||||
this.name === universeMessageArg.requestedChannelName &&
|
this.name === universeMessageArg.targetChannelName &&
|
||||||
this.passphrase === universeMessageArg.requestedChannelPassphrase
|
this.passphrase === universeMessageArg.passphrase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user