Compare commits

..

4 Commits

Author SHA1 Message Date
1baf1c318c 1.0.57 2019-08-12 17:23:11 +02:00
051aba3299 fix(core): update 2019-08-12 17:23:10 +02:00
7998d79b13 1.0.56 2019-08-12 15:12:32 +02:00
6838a8729a fix(core): update 2019-08-12 15:12:31 +02:00
9 changed files with 37 additions and 38 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.55",
"version": "1.0.57",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.55",
"version": "1.0.57",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",

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,23 +124,16 @@ 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(
this.universeCache,
unauthenticatedMessage
);
if (foundChannel) {
if (foundChannel && unauthenticatedMessage.authenticated) {
const authenticatedMessage = unauthenticatedMessage;
await this.universeCache.addMessage(authenticatedMessage);
}

View File

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

View File

@ -42,7 +42,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
/**
* wether the message is authenticated
*/
public authenticated: boolean = null;
public authenticated: boolean = false;
/**
* a destruction timer for this message