Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
bd4897f392 | |||
dbdc8a2811 | |||
908d00981b | |||
669ef262d7 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.95",
|
"version": "1.0.97",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.95",
|
"version": "1.0.97",
|
||||||
"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",
|
||||||
|
@ -47,7 +47,6 @@ myUniverse.start(8765); // start the server and provide the port on which to lis
|
|||||||
|
|
||||||
All your microservices represents clients in the universe that may talk to each other using the universe server.
|
All your microservices represents clients in the universe that may talk to each other using the universe server.
|
||||||
|
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
export class BroadcastSUbscription {}
|
export class BroadcastSubscription {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -25,6 +25,8 @@ export class ClientUniverse {
|
|||||||
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
|
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
|
||||||
public clientUniverseCache = new ClientUniverseCache();
|
public clientUniverseCache = new ClientUniverseCache();
|
||||||
|
|
||||||
|
public autoReconnectStatus: 'on' | 'off' = 'off';
|
||||||
|
|
||||||
constructor(optionsArg: IClientOptions) {
|
constructor(optionsArg: IClientOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
@ -74,10 +76,14 @@ export class ClientUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
|
if (this.options.autoReconnect) {
|
||||||
|
this.autoReconnectStatus = 'on';
|
||||||
|
}
|
||||||
await this.checkConnection();
|
await this.checkConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
|
this.autoReconnectStatus = 'off';
|
||||||
await this.disconnect('triggered');
|
await this.disconnect('triggered');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +91,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
|
||||||
*/
|
*/
|
||||||
public async checkConnection(): Promise<void> {
|
private async checkConnection(): Promise<void> {
|
||||||
if (!this.smartsocketClient) {
|
if (!this.smartsocketClient) {
|
||||||
const parsedURL = url.parse(this.options.serverAddress);
|
const parsedURL = url.parse(this.options.serverAddress);
|
||||||
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
||||||
@ -165,19 +171,25 @@ export class ClientUniverse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async disconnect(
|
private async disconnect(
|
||||||
reason: 'upstreamEvent' | 'triggered' = 'triggered',
|
reason: 'upstreamEvent' | 'triggered' = 'triggered',
|
||||||
tryReconnect = false
|
tryReconnect = false
|
||||||
) {
|
) {
|
||||||
if (reason === 'triggered') {
|
const instructDisconnect = async () => {
|
||||||
const smartsocketToDisconnect = this.smartsocketClient;
|
if (this.smartsocketClient) {
|
||||||
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
|
const smartsocketToDisconnect = this.smartsocketClient;
|
||||||
await smartsocketToDisconnect.disconnect();
|
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);
|
await plugins.smartdelay.delayForRandom(5000, 20000);
|
||||||
this.smartsocketClient = null;
|
await this.checkConnection();
|
||||||
this.checkConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
* @param messageArg
|
* @param messageArg
|
||||||
*/
|
*/
|
||||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
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 = {
|
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||||
id: plugins.smartunique.shortId(),
|
id: plugins.smartunique.shortId(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
|
Reference in New Issue
Block a user