Compare commits

..

4 Commits

Author SHA1 Message Date
c4640a3bc7 1.0.98 2019-11-10 16:55:18 +01:00
b6392ec6ba fix(core): update 2019-11-10 16:55:17 +01:00
bd4897f392 1.0.97 2019-11-09 18:44:34 +01:00
dbdc8a2811 fix(core): update 2019-11-09 18:44:33 +01:00
6 changed files with 45 additions and 23 deletions

8
package-lock.json generated
View File

@ -1,13 +1,13 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.96",
"version": "1.0.98",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@apiglobal/typedrequest-interfaces": {
"version": "1.0.7",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.7.tgz",
"integrity": "sha512-yPl0UcLFMwSQL7bK52wVjkgvadC+x2YS3+7T15V1A1dXNxa96yd4WX1fqcKqwnBrvYexq/8FaxWGi98tZ0oNwg=="
"version": "1.0.9",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.9.tgz",
"integrity": "sha512-lfxg6rBHnplRJnc6SLvRE/QZoNmXTSKcKYneJy5Sf/J6O/PxsSbNxbnv1iCrc4RZ8k3yuAnyJ6YFmy6IuudKgQ=="
},
"@babel/code-frame": {
"version": "7.5.5",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.96",
"version": "1.0.98",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",
@ -25,7 +25,7 @@
"rxjs": "*"
},
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.7",
"@apiglobal/typedrequest-interfaces": "^1.0.9",
"@pushrocks/lik": "^3.0.11",
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartexpress": "^3.0.52",

View File

@ -2,7 +2,22 @@ import * as plugins from './smartuniverse.plugins';
/**
* broadcasts an event to multiple channels
* also handles subsription
*/
export class BroadcastEvent<T> {
fire() {}
export class BroadcastEvent<T extends plugins.typedrequestInterfaces.IBroadCastEvent<any>> {
public eventSubject = new plugins.smartrx.rxjs.Subject<T['payload']>();
constructor() {
};
public fire(eventArg: T['payload']) {
};
public subscribe(funcArg: (nextArg: T['payload']) => void): plugins.smartrx.rxjs.Subscription {
return this.eventSubject.subscribe(funcArg);
}
}

View File

@ -1,5 +0,0 @@
import * as plugins from './smartuniverse.plugins';
export class BroadcastSubscription {
}

View File

@ -25,6 +25,8 @@ export class ClientUniverse {
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
public clientUniverseCache = new ClientUniverseCache();
public autoReconnectStatus: 'on' | 'off' = 'off';
constructor(optionsArg: IClientOptions) {
this.options = optionsArg;
}
@ -74,10 +76,14 @@ export class ClientUniverse {
}
public async start() {
if (this.options.autoReconnect) {
this.autoReconnectStatus = 'on';
}
await this.checkConnection();
}
public async stop() {
this.autoReconnectStatus = 'off';
await this.disconnect('triggered');
}
@ -85,7 +91,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
*/
public async checkConnection(): Promise<void> {
private async checkConnection(): Promise<void> {
if (!this.smartsocketClient) {
const parsedURL = url.parse(this.options.serverAddress);
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
@ -165,19 +171,25 @@ export class ClientUniverse {
}
}
public async disconnect(
private async disconnect(
reason: 'upstreamEvent' | 'triggered' = 'triggered',
tryReconnect = false
) {
if (reason === 'triggered') {
const smartsocketToDisconnect = this.smartsocketClient;
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
await smartsocketToDisconnect.disconnect();
const instructDisconnect = async () => {
if (this.smartsocketClient) {
const smartsocketToDisconnect = this.smartsocketClient;
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
await smartsocketToDisconnect.disconnect();
}
};
if (reason === 'triggered' && this.smartsocketClient) {
await instructDisconnect();
}
if (this.options.autoReconnect && reason === 'upstreamEvent' && this.smartsocketClient) {
if (this.autoReconnectStatus === 'on' && reason === 'upstreamEvent') {
await instructDisconnect();
await plugins.smartdelay.delayForRandom(5000, 20000);
this.smartsocketClient = null;
this.checkConnection();
await this.checkConnection();
}
}
}

View File

@ -88,7 +88,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
* @param messageArg
*/
public async sendMessage(messageArg: interfaces.IMessageCreator) {
await this.clientUniverseRef.checkConnection();
await this.clientUniverseRef.start(); // its ok to call this multiple times
const universeMessageToSend: interfaces.IUniverseMessage = {
id: plugins.smartunique.shortId(),
timestamp: Date.now(),