Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c5e60d804a | |||
c5d52013e6 | |||
64195e4c78 | |||
01b5b3dc1a |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsocket",
|
"name": "@pushrocks/smartsocket",
|
||||||
"version": "1.2.19",
|
"version": "1.2.21",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartsocket",
|
"name": "@pushrocks/smartsocket",
|
||||||
"version": "1.2.19",
|
"version": "1.2.21",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsocket",
|
"name": "@pushrocks/smartsocket",
|
||||||
"version": "1.2.19",
|
"version": "1.2.21",
|
||||||
"description": "easy and secure websocket communication",
|
"description": "easy and secure websocket communication",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
@ -7,4 +7,5 @@ export type TConnectionStatus =
|
|||||||
| 'connecting'
|
| 'connecting'
|
||||||
| 'connected'
|
| 'connected'
|
||||||
| 'disconnecting'
|
| 'disconnecting'
|
||||||
| 'disconnected';
|
| 'disconnected'
|
||||||
|
| 'timedOut';
|
||||||
|
@ -118,6 +118,7 @@ export class SmartsocketClient {
|
|||||||
const timer = new plugins.smarttime.Timer(5000);
|
const timer = new plugins.smarttime.Timer(5000);
|
||||||
timer.start();
|
timer.start();
|
||||||
timer.completed.then(() => {
|
timer.completed.then(() => {
|
||||||
|
this.updateStatus('timedOut');
|
||||||
logger.log('warn', 'connection to server timed out.');
|
logger.log('warn', 'connection to server timed out.');
|
||||||
this.disconnect(true);
|
this.disconnect(true);
|
||||||
});
|
});
|
||||||
@ -184,28 +185,37 @@ export class SmartsocketClient {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private disconnectRunning = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disconnect from the server
|
* disconnect from the server
|
||||||
*/
|
*/
|
||||||
public async disconnect(useAutoconnectSetting = false) {
|
public async disconnect(useAutoReconnectSetting = false) {
|
||||||
if (this.eventStatus === 'disconnecting') {
|
if (this.disconnectRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.disconnectRunning = true;
|
||||||
this.updateStatus('disconnecting');
|
this.updateStatus('disconnecting');
|
||||||
this.tagStoreSubscription?.unsubscribe();
|
this.tagStoreSubscription?.unsubscribe();
|
||||||
if (this.socketConnection) {
|
if (this.socketConnection) {
|
||||||
await this.socketConnection.disconnect();
|
await this.socketConnection.disconnect();
|
||||||
this.socketConnection = undefined;
|
this.socketConnection = undefined;
|
||||||
logger.log('ok', 'disconnected socket!');
|
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}`);
|
logger.log('warn', `disconnected from server ${this.remoteShortId}`);
|
||||||
this.remoteShortId = null;
|
this.remoteShortId = null;
|
||||||
|
|
||||||
if (this.autoReconnect && useAutoconnectSetting && this.eventStatus !== 'connecting') {
|
if (this.autoReconnect && useAutoReconnectSetting && this.eventStatus !== 'connecting') {
|
||||||
this.updateStatus('connecting');
|
this.updateStatus('connecting');
|
||||||
this.tryDebouncedReconnect();
|
await this.tryDebouncedReconnect();
|
||||||
} else if (this.eventStatus === 'connected') {
|
this.disconnectRunning = false;
|
||||||
this.updateStatus('disconnected');
|
} else {
|
||||||
|
this.disconnectRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user