Compare commits

...

4 Commits

Author SHA1 Message Date
e188b18016 1.1.43 2019-08-13 09:37:23 +02:00
33c0fa3746 fix(core): update 2019-08-13 09:37:23 +02:00
52be1415ee 1.1.42 2019-08-12 22:46:57 +02:00
e75d5eabdb fix(core): update 2019-08-12 22:46:57 +02:00
9 changed files with 36 additions and 23 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartsocket", "name": "@pushrocks/smartsocket",
"version": "1.1.41", "version": "1.1.43",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartsocket", "name": "@pushrocks/smartsocket",
"version": "1.1.41", "version": "1.1.43",
"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",

View File

@ -93,9 +93,7 @@ tap.test('should be able to make a functionCall from client to server', async ()
console.log(response); console.log(response);
}); });
tap.test('should be able to make a functionCall from server to client', async () => { tap.test('should be able to make a functionCall from server to client', async () => {});
});
// terminate // terminate
tap.test('should close the server', async () => { tap.test('should close the server', async () => {

View File

@ -10,7 +10,8 @@ import smartsocket = require('../ts/index');
let testSmartsocket: smartsocket.Smartsocket; let testSmartsocket: smartsocket.Smartsocket;
let testSmartsocketClient: smartsocket.SmartsocketClient; let testSmartsocketClient: smartsocket.SmartsocketClient;
let testSocketRole1: smartsocket.SocketRole; let testSocketRole1: smartsocket.SocketRole;
let testSocketFunction1: smartsocket.SocketFunction; let testSocketFunctionServer: smartsocket.SocketFunction;
let testSocketFunctionClient: smartsocket.SocketFunction;
const testConfig = { const testConfig = {
port: 3000 port: 3000
@ -33,14 +34,23 @@ tap.test('should add a socketrole', async () => {
// class SocketFunction // class SocketFunction
tap.test('should register a new Function', async () => { tap.test('should register a new Function', async () => {
testSocketFunction1 = new smartsocket.SocketFunction({ testSocketFunctionServer = new smartsocket.SocketFunction({
allowedRoles: [testSocketRole1], allowedRoles: [testSocketRole1],
funcDef: async (dataArg, socketConnectionArg) => { funcDef: async (dataArg, socketConnectionArg) => {
return dataArg; return dataArg;
}, },
funcName: 'testFunction1' funcName: 'testFunction1'
}); });
testSmartsocket.addSocketFunction(testSocketFunction1); testSmartsocket.addSocketFunction(testSocketFunctionServer);
testSocketFunctionClient = new smartsocket.SocketFunction({
allowedRoles: [],
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction1'
});
testSmartsocket.addSocketFunction(testSocketFunctionServer);
console.log(testSmartsocket.socketFunctions); console.log(testSmartsocket.socketFunctions);
}); });
@ -57,7 +67,7 @@ tap.test('should react to a new websocket connection from client', async () => {
alias: 'testClient1', alias: 'testClient1',
role: 'testRole1' role: 'testRole1'
}); });
testSmartsocketClient.addSocketFunction(testSocketFunction1); testSmartsocketClient.addSocketFunction(testSocketFunctionClient);
console.log(testSmartsocketClient.socketFunctions); console.log(testSmartsocketClient.socketFunctions);
await testSmartsocketClient.connect(); await testSmartsocketClient.connect();
}); });

View File

@ -5,10 +5,7 @@ import { Objectmap } from '@pushrocks/lik';
// import classes // import classes
import { Smartsocket } from './smartsocket.classes.smartsocket'; import { Smartsocket } from './smartsocket.classes.smartsocket';
import { SocketFunction } from './smartsocket.classes.socketfunction'; import { SocketFunction } from './smartsocket.classes.socketfunction';
import { import { SocketRequest, ISocketRequestDataObject } from './smartsocket.classes.socketrequest';
SocketRequest,
ISocketRequestDataObject,
} from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole'; import { SocketRole } from './smartsocket.classes.socketrole';
// socket.io // socket.io
@ -147,7 +144,10 @@ export class SocketConnection {
'info', 'info',
`received response for request with id ${dataArg.shortId}` `received response for request with id ${dataArg.shortId}`
); );
const targetSocketRequest = SocketRequest.getSocketRequestById(this.smartsocketRef, dataArg.shortId); const targetSocketRequest = SocketRequest.getSocketRequestById(
this.smartsocketRef,
dataArg.shortId
);
targetSocketRequest.handleResponse(dataArg); targetSocketRequest.handleResponse(dataArg);
}); });
plugins.smartlog.defaultLogger.log( plugins.smartlog.defaultLogger.log(

View File

@ -38,7 +38,10 @@ export type TFuncDef = (dataArg: any, connectionArg: SocketConnection) => Promis
*/ */
export class SocketFunction { export class SocketFunction {
// STATIC // STATIC
public static getSocketFunctionByName (smartsocketRefArg: Smartsocket | SmartsocketClient, functionNameArg: string): SocketFunction { public static getSocketFunctionByName(
smartsocketRefArg: Smartsocket | SmartsocketClient,
functionNameArg: string
): SocketFunction {
console.log(smartsocketRefArg.socketFunctions); console.log(smartsocketRefArg.socketFunctions);
return smartsocketRefArg.socketFunctions.find(socketFunctionArg => { return smartsocketRefArg.socketFunctions.find(socketFunctionArg => {
return socketFunctionArg.name === functionNameArg; return socketFunctionArg.name === functionNameArg;

View File

@ -55,8 +55,10 @@ export class SocketRequest {
public smartsocketRef: Smartsocket | SmartsocketClient; public smartsocketRef: Smartsocket | SmartsocketClient;
constructor(
constructor(smartsocketRefArg: Smartsocket | SmartsocketClient, optionsArg: SocketRequestConstructorOptions) { smartsocketRefArg: Smartsocket | SmartsocketClient,
optionsArg: SocketRequestConstructorOptions
) {
this.smartsocketRef = smartsocketRefArg; this.smartsocketRef = smartsocketRefArg;
this.side = optionsArg.side; this.side = optionsArg.side;
this.shortid = optionsArg.shortId; this.shortid = optionsArg.shortId;

View File

@ -1,6 +1,5 @@
import * as plugins from './smartsocket.plugins'; import * as plugins from './smartsocket.plugins';
// import classes // import classes
import { Objectmap } from '@pushrocks/lik'; import { Objectmap } from '@pushrocks/lik';
import { SocketFunction } from './smartsocket.classes.socketfunction'; import { SocketFunction } from './smartsocket.classes.socketfunction';
@ -23,7 +22,7 @@ export class SocketRole {
// STATIC // STATIC
public static getSocketRoleByName( public static getSocketRoleByName(
referenceSmartsocket: Smartsocket | SmartsocketClient, referenceSmartsocket: Smartsocket | SmartsocketClient,
socketRoleNameArg: string, socketRoleNameArg: string
): SocketRole { ): SocketRole {
return referenceSmartsocket.socketRoles.find(socketRoleArg => { return referenceSmartsocket.socketRoles.find(socketRoleArg => {
return socketRoleArg.name === socketRoleNameArg; return socketRoleArg.name === socketRoleNameArg;
@ -34,7 +33,8 @@ export class SocketRole {
dataArg: ISocketConnectionAuthenticationObject, dataArg: ISocketConnectionAuthenticationObject,
referenceSmartsocket: Smartsocket | SmartsocketClient referenceSmartsocket: Smartsocket | SmartsocketClient
): boolean { ): boolean {
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role).passwordHash; const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
.passwordHash;
const computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password); const computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password);
return targetPasswordHash === computedCompareHash; return targetPasswordHash === computedCompareHash;
} }