Compare commits

..

8 Commits

Author SHA1 Message Date
21dc933302 1.2.17 2022-01-19 19:05:45 +01:00
4e7455fa26 fix(core): update 2022-01-19 19:05:44 +01:00
c424d589ea 1.2.16 2022-01-19 18:36:14 +01:00
9435796333 fix(core): update 2022-01-19 18:36:13 +01:00
12d7310b90 1.2.15 2022-01-19 18:06:41 +01:00
9fc4db1e35 fix(core): update 2022-01-19 18:06:39 +01:00
895464115e 1.2.14 2022-01-19 16:37:46 +01:00
00f22f9651 fix(core): update 2022-01-19 16:37:45 +01:00
9 changed files with 1784 additions and 1934 deletions

13
.snyk
View File

@ -1,13 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.5
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-JSYAML-173999:
- '@pushrocks/smartexpress > @pushrocks/smartfile > js-yaml':
reason: None given
expires: '2019-05-24T15:16:11.291Z'
SNYK-JS-JSYAML-174129:
- '@pushrocks/smartexpress > @pushrocks/smartfile > js-yaml':
reason: None given
expires: '2019-05-24T15:16:11.291Z'
patch: {}

3508
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartsocket",
"version": "1.2.13",
"version": "1.2.17",
"description": "easy and secure websocket communication",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -21,7 +21,7 @@
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isohash": "^1.0.2",
"@pushrocks/isounique": "^1.0.4",
"@pushrocks/isounique": "^1.0.5",
"@pushrocks/lik": "^5.0.0",
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartenv": "^4.0.16",
@ -31,17 +31,15 @@
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smarttime": "^3.0.43",
"@types/socket.io": "^3.0.2",
"@types/socket.io-client": "^3.0.0",
"socket.io": "^3.1.0",
"socket.io-client": "^3.1.0"
"socket.io": "^4.4.1",
"socket.io-client": "^4.4.1"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tsbuild": "^2.1.29",
"@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.60",
"@pushrocks/tapbundle": "^3.2.15",
"@types/node": "^17.0.9",
"@types/node": "^17.0.10",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},

View File

@ -1,5 +1,150 @@
import { tap, expect } from '@pushrocks/tapbundle';
// tslint:disable-next-line:no-implicit-dependencies
import { expect, tap } from '@pushrocks/tapbundle';
tap.test('should run a test', async () => {});
import smartsocket = require('../ts/index');
let testSmartsocket: smartsocket.Smartsocket;
let testSmartsocketClient: smartsocket.SmartsocketClient;
let testSocketFunctionForServer: smartsocket.SocketFunction<any>;
let testSocketFunctionClient: smartsocket.SocketFunction<any>;
export interface IReqResClient {
method: 'testFunction1';
request: {
value1: string;
};
response: {
value1: string;
};
}
export interface IReqResServer {
method: 'testFunction2';
request: {
hi: string;
};
response: {
hi: string;
};
}
const testConfig = {
port: 3000,
};
// class smartsocket
tap.test('should create a new smartsocket', async () => {
testSmartsocket = new smartsocket.Smartsocket({ alias: 'testserver1', port: testConfig.port });
await testSmartsocket.start();
});
// class SocketFunction
tap.test('should register a new Function', async () => {
testSocketFunctionForServer = new smartsocket.SocketFunction({
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction1',
});
testSmartsocket.addSocketFunction(testSocketFunctionForServer);
testSocketFunctionClient = new smartsocket.SocketFunction({
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction2',
});
testSmartsocket.addSocketFunction(testSocketFunctionForServer);
});
// class SmartsocketClient
tap.test('should react to a new websocket connection from client', async () => {
testSmartsocketClient = new smartsocket.SmartsocketClient({
port: testConfig.port,
url: 'http://localhost',
alias: 'testClient1',
autoReconnect: true,
});
testSmartsocketClient.addSocketFunction(testSocketFunctionClient);
await testSmartsocketClient.connect();
});
tap.test('should be able to tag a connection from client', async (tools) => {
await testSmartsocketClient.addTag({
id: 'awesome',
payload: 'yes',
});
const tagOnServerSide = await testSmartsocket.socketConnections
.findSync((socketConnection) => {
return true;
})
.getTagById('awesome');
expect(tagOnServerSide.payload).to.equal('yes');
});
tap.test('should be able to tag a connection from server', async (tools) => {
await testSmartsocket.socketConnections
.findSync((socketConnection) => {
return true;
})
.addTag({
id: 'awesome2',
payload: 'absolutely',
});
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
expect(tagOnClientSide.payload).to.equal('absolutely');
});
tap.test('should be able to make a functionCall from client to server', async () => {
const response = await testSmartsocketClient.serverCall<IReqResClient>('testFunction1', {
value1: 'hello',
});
console.log(response);
expect(response.value1).to.equal('hello');
});
tap.test('should be able to make a functionCall from server to client', async () => {
const response = await testSmartsocket.clientCall<IReqResServer>(
'testFunction2',
{
hi: 'hi there from server',
},
testSmartsocket.socketConnections.findSync((socketConnection) => {
return true;
})
);
console.log(response);
expect(response.hi).to.equal('hi there from server');
});
tap.test('client should disconnect and reconnect', async (tools) => {
await testSmartsocketClient.disconnect();
await testSmartsocketClient.connect();
});
// class smartsocket
tap.test('should be able to switch to a new server', async (toolsArg) => {
await testSmartsocket.stop();
await toolsArg.delayFor(5000);
testSmartsocket = new smartsocket.Smartsocket({ alias: 'testserver2', port: testConfig.port });
await testSmartsocket.start();
await toolsArg.delayFor(30000);
});
tap.test('should be able to locate a connection tag after reconnect', async (tools) => {
console.log(testSmartsocket.socketConnections.getArray().length);
const tagOnServerSide = await testSmartsocket.socketConnections
.findSync((socketConnection) => {
return true;
})
.getTagById('awesome');
expect(tagOnServerSide.payload).to.equal('yes');
});
// terminate
tap.test('should close the server', async () => {
await testSmartsocketClient.stop();
await testSmartsocket.stop();
});
tap.start();

View File

@ -2,11 +2,9 @@
import { expect, tap } from '@pushrocks/tapbundle';
import smartsocket = require('../ts/index');
import * as isohash from '@pushrocks/isohash';
let testSmartsocket: smartsocket.Smartsocket;
let testSmartsocketClient: smartsocket.SmartsocketClient;
let testSocketConnection: smartsocket.SocketConnection;
let testSocketFunctionForServer: smartsocket.SocketFunction<any>;
let testSocketFunctionClient: smartsocket.SocketFunction<any>;
@ -57,7 +55,6 @@ tap.test('should register a new Function', async () => {
funcName: 'testFunction2',
});
testSmartsocket.addSocketFunction(testSocketFunctionForServer);
console.log(testSmartsocket.socketFunctions);
});
tap.test('should start listening when .started is called', async () => {
@ -72,7 +69,6 @@ tap.test('should react to a new websocket connection from client', async () => {
alias: 'testClient1',
});
testSmartsocketClient.addSocketFunction(testSocketFunctionClient);
console.log(testSmartsocketClient.socketFunctions);
await testSmartsocketClient.connect();
});

View File

@ -103,7 +103,7 @@ export class Smartsocket {
/**
* the standard handler for new socket connections
*/
private async _handleSocketConnection(socketArg: SocketIO.Socket) {
private async _handleSocketConnection(socketArg: pluginsTyped.socketIo.Socket) {
const socketConnection: SocketConnection = new SocketConnection({
alias: undefined,
authenticated: false,

View File

@ -91,11 +91,11 @@ export class SmartsocketClient {
public async connect() {
const done = plugins.smartpromise.defer();
const smartenvInstance = new plugins.smartenv.Smartenv();
const socketIoClient = await smartenvInstance.getEnvAwareModule({
const socketIoClient: any = await smartenvInstance.getEnvAwareModule({
nodeModuleName: 'socket.io-client',
webUrlArg: 'https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js',
webUrlArg: 'https://cdn.jsdelivr.net/npm/socket.io-client@4/dist/socket.io.js',
getFunction: () => {
return globalThis.io;
return (globalThis as any).io;
},
});
logger.log('info', 'trying to connect...');
@ -122,13 +122,13 @@ export class SmartsocketClient {
// authentication flow
this.socketConnection.socket.on(
'requestAuth',
(requestAuthPayload: interfaces.IRequestAuthPayload) => {
(dataArg: interfaces.IRequestAuthPayload) => {
timer.reset();
logger.log('info', 'server requested authentication');
logger.log('info', `server ${dataArg.serverAlias} requested authentication`);
// lets register the authenticated event
this.socketConnection.socket.on('authenticated', async () => {
this.remoteShortId = requestAuthPayload.serverAlias;
this.remoteShortId = dataArg.serverAlias;
logger.log('info', 'client is authenticated');
this.socketConnection.authenticated = true;
await this.socketConnection.listenToFunctionRequests();
@ -216,7 +216,7 @@ export class SmartsocketClient {
* try a reconnection
*/
public async tryDebouncedReconnect() {
await plugins.smartdelay.delayForRandom(10000, 50000);
await plugins.smartdelay.delayForRandom(10000, 20000);
await this.connect();
}

View File

@ -1,4 +1,5 @@
import * as plugins from './smartsocket.plugins';
import * as pluginsTyped from './smartsocket.pluginstyped';
import * as interfaces from './interfaces';
// import classes
@ -7,7 +8,6 @@ import { SocketFunction } from './smartsocket.classes.socketfunction';
import { SocketRequest, ISocketRequestDataObject } from './smartsocket.classes.socketrequest';
// socket.io
import * as pluginsTyped from './smartsocket.pluginstyped';
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
import { logger } from './smartsocket.logging';
@ -26,7 +26,7 @@ export interface ISocketConnectionConstructorOptions {
authenticated: boolean;
side: TSocketConnectionSide;
smartsocketHost: Smartsocket | SmartsocketClient;
socket: SocketIO.Socket | SocketIOClient.Socket;
socket: pluginsTyped.socketIo.Socket | pluginsTyped.socketIoClient.Socket;
}
/**
@ -47,7 +47,7 @@ export class SocketConnection {
public side: TSocketConnectionSide;
public authenticated: boolean = false;
public smartsocketRef: Smartsocket | SmartsocketClient;
public socket: SocketIO.Socket | SocketIOClient.Socket;
public socket: pluginsTyped.socketIo.Socket | pluginsTyped.socketIoClient.Socket;
public eventSubject = new plugins.smartrx.rxjs.Subject<interfaces.TConnectionStatus>();
public eventStatus: interfaces.TConnectionStatus = 'new';

View File

@ -11,6 +11,10 @@ export { smartexpress };
// third party scope
import type socketIo from 'socket.io';
import type socketIoClient from 'socket.io-client';
import type { Socket as ClientSocket, connect as ClientIo } from 'socket.io-client';
export { socketIoClient, socketIo };
export { socketIo };
export namespace socketIoClient {
export type Socket = ClientSocket;
export type connect = typeof ClientIo;
}