fix(core): update
This commit is contained in:
parent
a40a83f0bf
commit
c6ad490a6f
1006
package-lock.json
generated
1006
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,14 +20,16 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/smartsocket#README",
|
"homepage": "https://gitlab.com/pushrocks/smartsocket#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||||
|
"@pushrocks/isohash": "^1.0.2",
|
||||||
|
"@pushrocks/isounique": "^1.0.4",
|
||||||
"@pushrocks/lik": "^4.0.17",
|
"@pushrocks/lik": "^4.0.17",
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
|
"@pushrocks/smartenv": "^4.0.11",
|
||||||
"@pushrocks/smartexpress": "^3.0.76",
|
"@pushrocks/smartexpress": "^3.0.76",
|
||||||
"@pushrocks/smarthash": "^2.1.6",
|
|
||||||
"@pushrocks/smartlog": "^2.0.39",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrx": "^2.0.19",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/smartunique": "^3.0.3",
|
"@pushrocks/smarttime": "^3.0.35",
|
||||||
"@types/socket.io": "^2.1.11",
|
"@types/socket.io": "^2.1.11",
|
||||||
"@types/socket.io-client": "^1.4.33",
|
"@types/socket.io-client": "^1.4.33",
|
||||||
"socket.io": "^2.3.0",
|
"socket.io": "^2.3.0",
|
||||||
@ -36,7 +38,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.48",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.11.2",
|
"@types/node": "^14.11.2",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smartsocket.plugins';
|
import * as plugins from './smartsocket.plugins';
|
||||||
|
import * as pluginsTyped from './smartsocket.pluginstyped';
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||||
@ -11,8 +12,6 @@ import { SocketRequest } from './smartsocket.classes.socketrequest';
|
|||||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||||
import { SocketServer } from './smartsocket.classes.socketserver';
|
import { SocketServer } from './smartsocket.classes.socketserver';
|
||||||
|
|
||||||
// socket.io
|
|
||||||
import * as SocketIO from 'socket.io';
|
|
||||||
import { logger } from './smartsocket.logging';
|
import { logger } from './smartsocket.logging';
|
||||||
|
|
||||||
export interface ISmartsocketConstructorOptions {
|
export interface ISmartsocketConstructorOptions {
|
||||||
@ -23,9 +22,10 @@ export class Smartsocket {
|
|||||||
/**
|
/**
|
||||||
* a unique id to detect server restarts
|
* a unique id to detect server restarts
|
||||||
*/
|
*/
|
||||||
public shortId = plugins.smartunique.shortId();
|
public shortId = plugins.isounique.uni();
|
||||||
|
public smartenv = new plugins.smartenv.Smartenv();
|
||||||
public options: ISmartsocketConstructorOptions;
|
public options: ISmartsocketConstructorOptions;
|
||||||
public io: SocketIO.Server;
|
public io: pluginsTyped.socketIo.Server;
|
||||||
public socketConnections = new plugins.lik.ObjectMap<SocketConnection>();
|
public socketConnections = new plugins.lik.ObjectMap<SocketConnection>();
|
||||||
public socketRoles = new plugins.lik.ObjectMap<SocketRole>();
|
public socketRoles = new plugins.lik.ObjectMap<SocketRole>();
|
||||||
public socketFunctions = new plugins.lik.ObjectMap<SocketFunction<any>>();
|
public socketFunctions = new plugins.lik.ObjectMap<SocketFunction<any>>();
|
||||||
@ -46,7 +46,8 @@ export class Smartsocket {
|
|||||||
* starts smartsocket
|
* starts smartsocket
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
this.io = plugins.socketIo(this.socketServer.getServerForSocketIo());
|
const socketIoModule = this.smartenv.getSafeNodeModule('socket.io');
|
||||||
|
this.io = socketIoModule(this.socketServer.getServerForSocketIo());
|
||||||
await this.socketServer.start();
|
await this.socketServer.start();
|
||||||
this.io.on('connection', (socketArg) => {
|
this.io.on('connection', (socketArg) => {
|
||||||
this._handleSocketConnection(socketArg);
|
this._handleSocketConnection(socketArg);
|
||||||
@ -85,7 +86,7 @@ export class Smartsocket {
|
|||||||
funcName: functionNameArg,
|
funcName: functionNameArg,
|
||||||
},
|
},
|
||||||
originSocketConnection: targetSocketConnectionArg,
|
originSocketConnection: targetSocketConnectionArg,
|
||||||
shortId: plugins.smartunique.shortId(),
|
shortId: plugins.isounique.uni(),
|
||||||
side: 'requesting',
|
side: 'requesting',
|
||||||
});
|
});
|
||||||
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
|
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
|
||||||
@ -110,7 +111,7 @@ export class Smartsocket {
|
|||||||
/**
|
/**
|
||||||
* the standard handler for new socket connections
|
* the standard handler for new socket connections
|
||||||
*/
|
*/
|
||||||
private async _handleSocketConnection(socketArg: plugins.socketIo.Socket) {
|
private async _handleSocketConnection(socketArg: pluginsTyped.socketIo.Socket) {
|
||||||
const socketConnection: SocketConnection = new SocketConnection({
|
const socketConnection: SocketConnection = new SocketConnection({
|
||||||
alias: undefined,
|
alias: undefined,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smartsocket.plugins';
|
import * as plugins from './smartsocket.plugins';
|
||||||
|
import * as pluginsTyped from './smartsocket.pluginstyped';
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||||
@ -24,7 +25,7 @@ export interface ISmartsocketClientOptions {
|
|||||||
|
|
||||||
export class SmartsocketClient {
|
export class SmartsocketClient {
|
||||||
// a unique id
|
// a unique id
|
||||||
public shortId = plugins.smartunique.shortId();
|
public shortId = plugins.isounique.uni();
|
||||||
|
|
||||||
// the shortId of the remote we connect to
|
// the shortId of the remote we connect to
|
||||||
public remoteShortId: string = null;
|
public remoteShortId: string = null;
|
||||||
@ -175,7 +176,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.smartunique.shortId(),
|
shortId: plugins.isounique.uni(),
|
||||||
funcCallData: {
|
funcCallData: {
|
||||||
funcName: functionNameArg,
|
funcName: functionNameArg,
|
||||||
funcDataArg: dataArg,
|
funcDataArg: dataArg,
|
||||||
|
@ -92,7 +92,7 @@ export class SocketConnection {
|
|||||||
this.socket.on('dataAuth', async (dataArg: ISocketConnectionAuthenticationObject) => {
|
this.socket.on('dataAuth', async (dataArg: ISocketConnectionAuthenticationObject) => {
|
||||||
logger.log('info', 'received authentication data. now hashing and comparing...');
|
logger.log('info', 'received authentication data. now hashing and comparing...');
|
||||||
this.socket.removeListener('dataAuth', () => {});
|
this.socket.removeListener('dataAuth', () => {});
|
||||||
if (SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
|
if (await SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
|
||||||
// TODO: authenticate password
|
// TODO: authenticate password
|
||||||
this.alias = dataArg.alias;
|
this.alias = dataArg.alias;
|
||||||
this.authenticated = true;
|
this.authenticated = true;
|
||||||
@ -123,14 +123,14 @@ export class SocketConnection {
|
|||||||
if (this.authenticated) {
|
if (this.authenticated) {
|
||||||
this.socket.on('function', (dataArg: ISocketRequestDataObject<any>) => {
|
this.socket.on('function', (dataArg: ISocketRequestDataObject<any>) => {
|
||||||
// check if requested function is available to the socket's scope
|
// check if requested function is available to the socket's scope
|
||||||
logger.log('info', 'function request received');
|
// logger.log('info', 'function request received');
|
||||||
const referencedFunction: SocketFunction<any> = this.role.allowedFunctions.find(
|
const referencedFunction: SocketFunction<any> = this.role.allowedFunctions.find(
|
||||||
(socketFunctionArg) => {
|
(socketFunctionArg) => {
|
||||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (referencedFunction) {
|
if (referencedFunction) {
|
||||||
logger.log('ok', 'function in access scope');
|
// logger.log('ok', 'function in access scope');
|
||||||
const localSocketRequest = new SocketRequest(this.smartsocketRef, {
|
const localSocketRequest = new SocketRequest(this.smartsocketRef, {
|
||||||
side: 'responding',
|
side: 'responding',
|
||||||
originSocketConnection: this,
|
originSocketConnection: this,
|
||||||
|
@ -107,8 +107,7 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!targetSocketFunction) {
|
if (!targetSocketFunction) {
|
||||||
logger.log('warn', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
|
logger.log('error', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
|
||||||
logger.log('warn', `So now response is being sent.`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.log('info', `invoking ${targetSocketFunction.name}`);
|
logger.log('info', `invoking ${targetSocketFunction.name}`);
|
||||||
|
@ -28,13 +28,13 @@ export class SocketRole {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static checkPasswordForRole(
|
public static async checkPasswordForRole(
|
||||||
dataArg: ISocketConnectionAuthenticationObject,
|
dataArg: ISocketConnectionAuthenticationObject,
|
||||||
referenceSmartsocket: Smartsocket | SmartsocketClient
|
referenceSmartsocket: Smartsocket | SmartsocketClient
|
||||||
): boolean {
|
): Promise<boolean> {
|
||||||
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
|
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
|
||||||
.passwordHash;
|
.passwordHash;
|
||||||
const computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password);
|
const computedCompareHash = await plugins.isohash.sha256FromString(dataArg.password);
|
||||||
return targetPasswordHash === computedCompareHash;
|
return targetPasswordHash === computedCompareHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import * as plugins from './smartsocket.plugins';
|
import * as plugins from './smartsocket.plugins';
|
||||||
|
import * as pluginsTyped from './smartsocket.pluginstyped';
|
||||||
|
|
||||||
// used in case no other server is supplied
|
// used in case no other server is supplied
|
||||||
import * as http from 'http';
|
|
||||||
import * as https from 'https';
|
|
||||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||||
import { logger } from './smartsocket.logging';
|
import { logger } from './smartsocket.logging';
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ import { logger } from './smartsocket.logging';
|
|||||||
*/
|
*/
|
||||||
export class SocketServer {
|
export class SocketServer {
|
||||||
private smartsocket: Smartsocket;
|
private smartsocket: Smartsocket;
|
||||||
private httpServer: http.Server | https.Server;
|
private httpServer: pluginsTyped.http.Server | pluginsTyped.https.Server;
|
||||||
// wether httpServer is standalone
|
// wether httpServer is standalone
|
||||||
private standaloneServer = false;
|
private standaloneServer = false;
|
||||||
private expressServer: any;
|
private expressServer: any;
|
||||||
@ -27,7 +26,7 @@ export class SocketServer {
|
|||||||
*/
|
*/
|
||||||
public async setExternalServer(
|
public async setExternalServer(
|
||||||
serverType: 'smartexpress',
|
serverType: 'smartexpress',
|
||||||
serverArg: plugins.smartexpress.Server
|
serverArg: pluginsTyped.smartexpress.Server
|
||||||
) {
|
) {
|
||||||
await serverArg.startedPromise;
|
await serverArg.startedPromise;
|
||||||
this.httpServer = serverArg.httpServer;
|
this.httpServer = serverArg.httpServer;
|
||||||
@ -40,7 +39,8 @@ export class SocketServer {
|
|||||||
if (this.httpServer) {
|
if (this.httpServer) {
|
||||||
return this.httpServer;
|
return this.httpServer;
|
||||||
} else {
|
} else {
|
||||||
this.httpServer = new http.Server();
|
const httpModule = this.smartsocket.smartenv.getSafeNodeModule('http');
|
||||||
|
this.httpServer = new httpModule.Server();
|
||||||
this.standaloneServer = true;
|
this.standaloneServer = true;
|
||||||
return this.httpServer;
|
return this.httpServer;
|
||||||
}
|
}
|
||||||
|
3
ts/smartsocket.classes.socketstats.ts
Normal file
3
ts/smartsocket.classes.socketstats.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import * as plugins from './smartsocket.plugins';
|
||||||
|
|
||||||
|
export class SocketStats {}
|
@ -4,30 +4,31 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
|||||||
export { typedrequestInterfaces };
|
export { typedrequestInterfaces };
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
|
import * as isohash from '@pushrocks/isohash';
|
||||||
|
import * as isounique from '@pushrocks/isounique';
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
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 smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
import * as smartunique from '@pushrocks/smartunique';
|
|
||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
isohash,
|
||||||
|
isounique,
|
||||||
lik,
|
lik,
|
||||||
|
smartenv,
|
||||||
smartlog,
|
smartlog,
|
||||||
smarthash,
|
|
||||||
smartdelay,
|
smartdelay,
|
||||||
smartexpress,
|
|
||||||
smartpromise,
|
smartpromise,
|
||||||
smarttime,
|
smarttime,
|
||||||
smartunique,
|
|
||||||
smartrx,
|
smartrx,
|
||||||
};
|
};
|
||||||
|
|
||||||
// third party scope
|
// third party
|
||||||
import socketIo from 'socket.io';
|
|
||||||
import socketIoClient from 'socket.io-client';
|
import socketIoClient from 'socket.io-client';
|
||||||
|
|
||||||
export { socketIo, socketIoClient };
|
export {
|
||||||
|
socketIoClient
|
||||||
|
};
|
||||||
|
20
ts/smartsocket.pluginstyped.ts
Normal file
20
ts/smartsocket.pluginstyped.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// node native
|
||||||
|
import type http from 'http';
|
||||||
|
import type https from 'https';
|
||||||
|
|
||||||
|
export {
|
||||||
|
http,
|
||||||
|
https
|
||||||
|
};
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
import type * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartexpress
|
||||||
|
};
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import type socketIo from 'socket.io';
|
||||||
|
|
||||||
|
export { socketIo };
|
Loading…
Reference in New Issue
Block a user