fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-12 17:23:10 +02:00
parent 7998d79b13
commit 051aba3299
6 changed files with 33 additions and 34 deletions

View File

@ -50,9 +50,8 @@ tap.test('should get a observable correctly', async () => {
});
tap.test('should send a message correctly', async () => {
await testClientUniverse.sendMessage({
messageText: 'hello',
targetChannelName: testChannelData.channelName
await (await testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
messageText: 'hello'
});
});

View File

@ -2,9 +2,11 @@ export interface IMessageCreator {
messageText: string;
payload?: string | number | any;
payloadStringType?: 'Buffer' | 'string' | 'object';
targetChannelName: string;
}
/**
*
*/
export interface IUniverseMessage extends IMessageCreator {
id: string;
/**
@ -12,4 +14,5 @@ export interface IUniverseMessage extends IMessageCreator {
*/
timestamp: number;
passphrase: string;
targetChannelName: string;
}

View File

@ -42,7 +42,7 @@ export class ClientUniverse {
}
// lets create the channel
ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
await ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
}
/**
@ -68,21 +68,6 @@ export class ClientUniverse {
});
}
/**
* sends a message towards the server
* @param messageArg
*/
public async sendMessage(messageArg: interfaces.IMessageCreator) {
await this.checkConnection();
const universeMessageToSend: interfaces.IUniverseMessage = {
id: plugins.smartunique.shortId(),
timestamp: Date.now(),
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
...messageArg
};
await this.smartsocketClient.serverCall('processMessage', universeMessageToSend);
}
public close() {
this.smartsocketClient.disconnect();
}
@ -91,7 +76,7 @@ export class ClientUniverse {
* 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> {
public async checkConnection(): Promise<void> {
if (!this.smartsocketClient && !this.observableIntake) {
const parsedURL = url.parse(this.options.serverAddress);
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {

View File

@ -37,10 +37,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
public passphrase: string;
// refs
public clientUniverse: ClientUniverse;
public clientUniverseRef: ClientUniverse;
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
this.clientUniverse = clientUniverseArg;
this.clientUniverseRef = clientUniverseArg;
this.name = nameArg;
this.passphrase = passphraseArg;
}
@ -55,6 +55,24 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
name: this.name,
passphrase: this.passphrase
};
this.clientUniverse.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
await this.clientUniverseRef.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
}
/**
* sends a message towards the server
* @param messageArg
*/
public async sendMessage(messageArg: interfaces.IMessageCreator) {
await this.clientUniverseRef.checkConnection();
const universeMessageToSend: interfaces.IUniverseMessage = {
id: plugins.smartunique.shortId(),
timestamp: Date.now(),
passphrase: this.passphrase,
targetChannelName: this.name,
messageText: messageArg.messageText,
payload: messageArg.payload,
payloadStringType: messageArg.payloadStringType
};
await this.clientUniverseRef.smartsocketClient.serverCall('processMessage', universeMessageToSend);
}
}

View File

@ -124,16 +124,9 @@ export class Universe {
if (universeConnection) {
console.log('found UniverseConnection for socket');
} else {
console.log('universe client not yet present');
console.log('creating one now as send only');
const universeConnectionInstance = new UniverseConnection({
socketConnection: socketConnectionArg,
authenticationRequests: []
});
await UniverseConnection.addConnectionToCache(
this.universeCache,
universeConnectionInstance
);
return {
error: 'You need to authenticate for a channel'
};
}
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(dataArg);
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(

View File

@ -23,6 +23,7 @@ export class UniverseConnection {
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
universeConnection
);
universeCache.connectionMap.add(universeConnection);
}
/**