Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1baf1c318c | |||
051aba3299 | |||
7998d79b13 | |||
6838a8729a |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.55",
|
"version": "1.0.57",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.55",
|
"version": "1.0.57",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "messaging service for your micro services",
|
"description": "messaging service for your micro services",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -50,9 +50,8 @@ tap.test('should get a observable correctly', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message correctly', async () => {
|
tap.test('should send a message correctly', async () => {
|
||||||
await testClientUniverse.sendMessage({
|
await (await testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
|
||||||
messageText: 'hello',
|
messageText: 'hello'
|
||||||
targetChannelName: testChannelData.channelName
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@ export interface IMessageCreator {
|
|||||||
messageText: string;
|
messageText: string;
|
||||||
payload?: string | number | any;
|
payload?: string | number | any;
|
||||||
payloadStringType?: 'Buffer' | 'string' | 'object';
|
payloadStringType?: 'Buffer' | 'string' | 'object';
|
||||||
targetChannelName: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
export interface IUniverseMessage extends IMessageCreator {
|
export interface IUniverseMessage extends IMessageCreator {
|
||||||
id: string;
|
id: string;
|
||||||
/**
|
/**
|
||||||
@ -12,4 +14,5 @@ export interface IUniverseMessage extends IMessageCreator {
|
|||||||
*/
|
*/
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
passphrase: string;
|
passphrase: string;
|
||||||
|
targetChannelName: string;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ export class ClientUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lets create the channel
|
// 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() {
|
public close() {
|
||||||
this.smartsocketClient.disconnect();
|
this.smartsocketClient.disconnect();
|
||||||
}
|
}
|
||||||
@ -91,7 +76,7 @@ export class ClientUniverse {
|
|||||||
* checks the connection towards a universe server
|
* checks the connection towards a universe server
|
||||||
* since password validation is done through other means, a connection should always be possible
|
* 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) {
|
if (!this.smartsocketClient && !this.observableIntake) {
|
||||||
const parsedURL = url.parse(this.options.serverAddress);
|
const parsedURL = url.parse(this.options.serverAddress);
|
||||||
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
||||||
|
@ -37,10 +37,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
public passphrase: string;
|
public passphrase: string;
|
||||||
|
|
||||||
// refs
|
// refs
|
||||||
public clientUniverse: ClientUniverse;
|
public clientUniverseRef: ClientUniverse;
|
||||||
|
|
||||||
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
||||||
this.clientUniverse = clientUniverseArg;
|
this.clientUniverseRef = clientUniverseArg;
|
||||||
this.name = nameArg;
|
this.name = nameArg;
|
||||||
this.passphrase = passphraseArg;
|
this.passphrase = passphraseArg;
|
||||||
}
|
}
|
||||||
@ -55,6 +55,24 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
name: this.name,
|
name: this.name,
|
||||||
passphrase: this.passphrase
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,23 +124,16 @@ export class Universe {
|
|||||||
if (universeConnection) {
|
if (universeConnection) {
|
||||||
console.log('found UniverseConnection for socket');
|
console.log('found UniverseConnection for socket');
|
||||||
} else {
|
} else {
|
||||||
console.log('universe client not yet present');
|
return {
|
||||||
console.log('creating one now as send only');
|
error: 'You need to authenticate for a channel'
|
||||||
const universeConnectionInstance = new UniverseConnection({
|
};
|
||||||
socketConnection: socketConnectionArg,
|
|
||||||
authenticationRequests: []
|
|
||||||
});
|
|
||||||
await UniverseConnection.addConnectionToCache(
|
|
||||||
this.universeCache,
|
|
||||||
universeConnectionInstance
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(dataArg);
|
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(dataArg);
|
||||||
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
|
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
|
||||||
this.universeCache,
|
this.universeCache,
|
||||||
unauthenticatedMessage
|
unauthenticatedMessage
|
||||||
);
|
);
|
||||||
if (foundChannel) {
|
if (foundChannel && unauthenticatedMessage.authenticated) {
|
||||||
const authenticatedMessage = unauthenticatedMessage;
|
const authenticatedMessage = unauthenticatedMessage;
|
||||||
await this.universeCache.addMessage(authenticatedMessage);
|
await this.universeCache.addMessage(authenticatedMessage);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ export class UniverseConnection {
|
|||||||
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
||||||
universeConnection
|
universeConnection
|
||||||
);
|
);
|
||||||
|
universeCache.connectionMap.add(universeConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
|||||||
/**
|
/**
|
||||||
* wether the message is authenticated
|
* wether the message is authenticated
|
||||||
*/
|
*/
|
||||||
public authenticated: boolean = null;
|
public authenticated: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a destruction timer for this message
|
* a destruction timer for this message
|
||||||
|
Reference in New Issue
Block a user