Compare commits

..

6 Commits

Author SHA1 Message Date
7f73664970 1.2.22 2022-01-20 18:38:18 +01:00
71452a293f fix(core): update 2022-01-20 18:38:17 +01:00
c5e60d804a 1.2.21 2022-01-20 18:33:47 +01:00
c5d52013e6 fix(core): update 2022-01-20 18:33:46 +01:00
64195e4c78 1.2.20 2022-01-20 17:14:12 +01:00
01b5b3dc1a fix(core): update 2022-01-20 17:14:11 +01:00
4 changed files with 23 additions and 19 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@pushrocks/smartsocket",
"version": "1.2.19",
"version": "1.2.22",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@pushrocks/smartsocket",
"version": "1.2.19",
"version": "1.2.22",
"license": "MIT",
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartsocket",
"version": "1.2.19",
"version": "1.2.22",
"description": "easy and secure websocket communication",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",

View File

@ -7,4 +7,5 @@ export type TConnectionStatus =
| 'connecting'
| 'connected'
| 'disconnecting'
| 'disconnected';
| 'disconnected'
| 'timedOut';

View File

@ -118,6 +118,7 @@ export class SmartsocketClient {
const timer = new plugins.smarttime.Timer(5000);
timer.start();
timer.completed.then(() => {
this.updateStatus('timedOut');
logger.log('warn', 'connection to server timed out.');
this.disconnect(true);
});
@ -184,28 +185,39 @@ export class SmartsocketClient {
return done.promise;
}
private disconnectRunning = false;
/**
* disconnect from the server
*/
public async disconnect(useAutoconnectSetting = false) {
if (this.eventStatus === 'disconnecting') {
public async disconnect(useAutoReconnectSetting = false) {
if (this.disconnectRunning) {
return;
}
this.disconnectRunning = true;
this.updateStatus('disconnecting');
this.tagStoreSubscription?.unsubscribe();
if (this.socketConnection) {
await this.socketConnection.disconnect();
this.socketConnection = undefined;
logger.log('ok', 'disconnected socket!');
} else {
this.disconnectRunning = false;
logger.log('warn', 'tried to disconnect, without a SocketConnection');
return;
}
logger.log('warn', `disconnected from server ${this.remoteShortId}`);
this.remoteShortId = null;
if (this.autoReconnect && useAutoconnectSetting && this.eventStatus !== 'connecting') {
if (this.autoReconnect && useAutoReconnectSetting && this.eventStatus !== 'connecting') {
this.updateStatus('connecting');
this.tryDebouncedReconnect();
} else if (this.eventStatus === 'connected') {
this.updateStatus('disconnected');
console.log('debounced reconnect!');
await plugins.smartdelay.delayForRandom(10000, 20000);
this.disconnectRunning = false;
await this.connect();
} else {
this.disconnectRunning = false;
}
}
@ -217,15 +229,6 @@ export class SmartsocketClient {
await this.disconnect();
}
/**
* try a reconnection
*/
public async tryDebouncedReconnect() {
console.log('debounced reconnect!');
await plugins.smartdelay.delayForRandom(10000, 20000);
await this.connect();
}
/**
* dispatches a server call
* @param functionNameArg