fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-12 22:46:57 +02:00
parent fb99848df1
commit e75d5eabdb
7 changed files with 21 additions and 18 deletions

View File

@ -53,4 +53,4 @@
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ]
} }

View File

@ -1 +1 @@
console.log('TODO'); console.log('TODO');

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

@ -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,18 +22,19 @@ 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;
}); });
} }
public static checkPasswordForRole ( public static checkPasswordForRole(
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;
} }