Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
75aa1f6f0d | |||
3f073ab9b3 | |||
08c1618ea8 | |||
eb181fa2f6 | |||
c901ab75d3 | |||
075c59ed2c |
717
package-lock.json
generated
717
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsocket",
|
"name": "@pushrocks/smartsocket",
|
||||||
"version": "1.1.49",
|
"version": "1.1.52",
|
||||||
"description": "easy and secure websocket communication",
|
"description": "easy and secure websocket communication",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -21,25 +21,24 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.7",
|
"@apiglobal/typedrequest-interfaces": "^1.0.7",
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.11",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@pushrocks/smartexpress": "^3.0.40",
|
"@pushrocks/smartexpress": "^3.0.52",
|
||||||
"@pushrocks/smarthash": "^2.0.6",
|
"@pushrocks/smarthash": "^2.0.6",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@types/shortid": "0.0.29",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"@types/socket.io": "^2.1.2",
|
"@types/socket.io": "^2.1.4",
|
||||||
"@types/socket.io-client": "^1.4.32",
|
"@types/socket.io-client": "^1.4.32",
|
||||||
"shortid": "^2.2.15",
|
"socket.io": "^2.3.0",
|
||||||
"socket.io": "^2.2.0",
|
"socket.io-client": "^2.3.0"
|
||||||
"socket.io-client": "^2.2.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^12.7.4",
|
"@types/node": "^12.12.5",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^5.20.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
|
@ -21,7 +21,7 @@ export interface IReqResClient {
|
|||||||
};
|
};
|
||||||
response: {
|
response: {
|
||||||
value1: string;
|
value1: string;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IReqResServer {
|
export interface IReqResServer {
|
||||||
|
@ -16,6 +16,10 @@ export interface ISmartsocketConstructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Smartsocket {
|
export class Smartsocket {
|
||||||
|
/**
|
||||||
|
* a unique id to detect server restarts
|
||||||
|
*/
|
||||||
|
public id = plugins.smartunique.shortId();
|
||||||
public options: ISmartsocketConstructorOptions;
|
public options: ISmartsocketConstructorOptions;
|
||||||
public io: SocketIO.Server;
|
public io: SocketIO.Server;
|
||||||
public socketConnections = new Objectmap<SocketConnection>();
|
public socketConnections = new Objectmap<SocketConnection>();
|
||||||
@ -80,7 +84,7 @@ export class Smartsocket {
|
|||||||
funcName: functionNameArg
|
funcName: functionNameArg
|
||||||
},
|
},
|
||||||
originSocketConnection: targetSocketConnectionArg,
|
originSocketConnection: targetSocketConnectionArg,
|
||||||
shortId: plugins.shortid.generate(),
|
shortId: plugins.smartunique.shortId(),
|
||||||
side: 'requesting'
|
side: 'requesting'
|
||||||
});
|
});
|
||||||
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
|
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
|
||||||
|
@ -70,6 +70,14 @@ export class SmartsocketClient {
|
|||||||
this.socketConnection.listenToFunctionRequests();
|
this.socketConnection.listenToFunctionRequests();
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// handle errors
|
||||||
|
this.socketConnection.socket.on('reconnect_failed', async () => {
|
||||||
|
this.disconnect();
|
||||||
|
});
|
||||||
|
this.socketConnection.socket.on('connect_error', async () => {
|
||||||
|
this.disconnect();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
@ -78,10 +86,20 @@ export class SmartsocketClient {
|
|||||||
* disconnect from the server
|
* disconnect from the server
|
||||||
*/
|
*/
|
||||||
public async disconnect() {
|
public async disconnect() {
|
||||||
|
if (this.socketConnection) {
|
||||||
this.socketConnection.socket.disconnect(true);
|
this.socketConnection.socket.disconnect(true);
|
||||||
this.socketConnection = undefined;
|
this.socketConnection = undefined;
|
||||||
plugins.smartlog.defaultLogger.log('ok', 'disconnected!');
|
plugins.smartlog.defaultLogger.log('ok', 'disconnected!');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* try a reconnection
|
||||||
|
*/
|
||||||
|
public async tryDebouncedReconnect() {
|
||||||
|
await plugins.smartdelay.delayForRandom(10000, 60000);
|
||||||
|
await this.connect();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dispatches a server call
|
* dispatches a server call
|
||||||
@ -93,7 +111,7 @@ export class SmartsocketClient {
|
|||||||
const socketRequest = new SocketRequest<T>(this, {
|
const socketRequest = new SocketRequest<T>(this, {
|
||||||
side: 'requesting',
|
side: 'requesting',
|
||||||
originSocketConnection: this.socketConnection,
|
originSocketConnection: this.socketConnection,
|
||||||
shortId: plugins.shortid.generate(),
|
shortId: plugins.smartunique.shortId(),
|
||||||
funcCallData: {
|
funcCallData: {
|
||||||
funcName: functionNameArg,
|
funcName: functionNameArg,
|
||||||
funcDataArg: dataArg
|
funcDataArg: dataArg
|
||||||
|
@ -10,6 +10,7 @@ import * as smarthash from '@pushrocks/smarthash';
|
|||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -18,16 +19,15 @@ export {
|
|||||||
smarthash,
|
smarthash,
|
||||||
smartdelay,
|
smartdelay,
|
||||||
smartexpress,
|
smartexpress,
|
||||||
smartpromise
|
smartpromise,
|
||||||
|
smartunique,
|
||||||
};
|
};
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as shortid from 'shortid';
|
|
||||||
import socketIo from 'socket.io';
|
import socketIo from 'socket.io';
|
||||||
import socketIoClient from 'socket.io-client';
|
import socketIoClient from 'socket.io-client';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
shortid,
|
|
||||||
socketIo,
|
socketIo,
|
||||||
socketIoClient
|
socketIoClient
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user