fix(core): update

This commit is contained in:
Philipp Kunz 2020-09-24 18:04:11 +00:00
parent b0bf9d7c95
commit 57e6f058be
17 changed files with 236 additions and 174 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -18,60 +18,74 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
only:
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
- notpriv
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
release:
stage: release
script:
- npmci node install lts
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
@ -79,35 +93,39 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -115,5 +133,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,5 +1,6 @@
{
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",

View File

@ -2,8 +2,8 @@
"name": "@pushrocks/smartsocket",
"version": "1.1.59",
"description": "easy and secure websocket communication",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)"
@ -44,14 +44,18 @@
},
"private": false,
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -15,7 +15,7 @@ let testSocketFunction1: smartsocket.SocketFunction<any>;
let myseServer: smartexpress.Server;
const testConfig = {
port: 3000
port: 3000,
};
// class smartsocket
@ -28,7 +28,7 @@ tap.test('Should accept an smartExpressServer as server', async () => {
myseServer = new smartexpress.Server({
cors: true,
forceSsl: false,
port: testConfig.port
port: testConfig.port,
});
testSmartsocket.setExternalServer('smartexpress', myseServer);
@ -40,7 +40,7 @@ tap.test('Should accept an smartExpressServer as server', async () => {
tap.test('should add a socketrole', async () => {
testSocketRole1 = new smartsocket.SocketRole({
name: 'testRole1',
passwordHash: smarthash.sha256FromStringSync('testPassword')
passwordHash: smarthash.sha256FromStringSync('testPassword'),
});
testSmartsocket.addSocketRoles([testSocketRole1]);
});
@ -52,7 +52,7 @@ tap.test('should register a new Function', async () => {
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction1'
funcName: 'testFunction1',
});
testSmartsocket.addSocketFunction(testSocketFunction1);
console.log(testSmartsocket.socketFunctions);
@ -69,14 +69,14 @@ tap.test('should react to a new websocket connection from client', async () => {
url: 'http://localhost',
password: 'testPassword',
alias: 'testClient1',
role: 'testRole1'
role: 'testRole1',
});
testSmartsocketClient.addSocketFunction(testSocketFunction1);
console.log(testSmartsocketClient.socketFunctions);
await testSmartsocketClient.connect();
});
tap.test('client should disconnect and reconnect', async tools => {
tap.test('client should disconnect and reconnect', async (tools) => {
await testSmartsocketClient.disconnect();
await tools.delayFor(100);
await testSmartsocketClient.connect();
@ -88,7 +88,7 @@ tap.test('2 clients should connect in parallel', async () => {
tap.test('should be able to make a functionCall from client to server', async () => {
const response = await testSmartsocketClient.serverCall('testFunction1', {
value1: 'hello'
value1: 'hello',
});
console.log(response);
});

View File

@ -30,12 +30,12 @@ export interface IReqResServer {
hi: string;
};
response: {
hi: string
}
hi: string;
};
}
const testConfig = {
port: 3000
port: 3000,
};
// class smartsocket
@ -48,7 +48,7 @@ tap.test('should create a new smartsocket', async () => {
tap.test('should add a socketrole', async () => {
testSocketRole1 = new smartsocket.SocketRole({
name: 'testRole1',
passwordHash: smarthash.sha256FromStringSync('testPassword')
passwordHash: smarthash.sha256FromStringSync('testPassword'),
});
testSmartsocket.addSocketRoles([testSocketRole1]);
});
@ -60,7 +60,7 @@ tap.test('should register a new Function', async () => {
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction1'
funcName: 'testFunction1',
});
testSmartsocket.addSocketFunction(testSocketFunctionForServer);
@ -69,7 +69,7 @@ tap.test('should register a new Function', async () => {
funcDef: async (dataArg, socketConnectionArg) => {
return dataArg;
},
funcName: 'testFunction2'
funcName: 'testFunction2',
});
testSmartsocket.addSocketFunction(testSocketFunctionForServer);
console.log(testSmartsocket.socketFunctions);
@ -86,7 +86,7 @@ tap.test('should react to a new websocket connection from client', async () => {
url: 'http://localhost',
password: 'testPassword',
alias: 'testClient1',
role: 'testRole1'
role: 'testRole1',
});
testSmartsocketClient.addSocketFunction(testSocketFunctionClient);
console.log(testSmartsocketClient.socketFunctions);
@ -99,7 +99,7 @@ tap.test('2 clients should connect in parallel', async () => {
tap.test('should be able to make a functionCall from client to server', async () => {
const response = await testSmartsocketClient.serverCall<IReqResClient>('testFunction1', {
value1: 'hello'
value1: 'hello',
});
console.log(response);
expect(response.value1).to.equal('hello');
@ -109,9 +109,9 @@ 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'
hi: 'hi there from server',
},
testSmartsocket.socketConnections.find(socketConnection => {
testSmartsocket.socketConnections.find((socketConnection) => {
return true;
})
);
@ -119,7 +119,7 @@ tap.test('should be able to make a functionCall from server to client', async ()
expect(response.hi).to.equal('hi there from server');
});
tap.test('client should disconnect and reconnect', async tools => {
tap.test('client should disconnect and reconnect', async (tools) => {
await testSmartsocketClient.disconnect();
await tools.delayFor(100);
await testSmartsocketClient.connect();

View File

@ -2,4 +2,9 @@ export interface IRequestAuthPayload {
serverShortId: string;
}
export type TConnectionStatus = 'new' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
export type TConnectionStatus =
| 'new'
| 'connecting'
| 'connected'
| 'disconnecting'
| 'disconnected';

View File

@ -2,7 +2,11 @@ import * as plugins from './smartsocket.plugins';
// classes
import { SocketConnection } from './smartsocket.classes.socketconnection';
import { ISocketFunctionCallDataRequest, SocketFunction, ISocketFunctionCallDataResponse } from './smartsocket.classes.socketfunction';
import {
ISocketFunctionCallDataRequest,
SocketFunction,
ISocketFunctionCallDataResponse,
} from './smartsocket.classes.socketfunction';
import { SocketRequest } from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole';
import { SocketServer } from './smartsocket.classes.socketserver';
@ -44,7 +48,7 @@ export class Smartsocket {
public async start() {
this.io = plugins.socketIo(this.socketServer.getServerForSocketIo());
await this.socketServer.start();
this.io.on('connection', socketArg => {
this.io.on('connection', (socketArg) => {
this._handleSocketConnection(socketArg);
});
}
@ -55,10 +59,7 @@ export class Smartsocket {
public async stop() {
await plugins.smartdelay.delayFor(1000);
this.socketConnections.forEach((socketObjectArg: SocketConnection) => {
logger.log(
'info',
`disconnect socket with >>alias ${socketObjectArg.alias}`
);
logger.log('info', `disconnect socket with >>alias ${socketObjectArg.alias}`);
socketObjectArg.socket.disconnect();
});
this.socketConnections.wipe();
@ -81,11 +82,11 @@ export class Smartsocket {
const socketRequest = new SocketRequest<T>(this, {
funcCallData: {
funcDataArg: dataArg,
funcName: functionNameArg
funcName: functionNameArg,
},
originSocketConnection: targetSocketConnectionArg,
shortId: plugins.smartunique.shortId(),
side: 'requesting'
side: 'requesting',
});
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
const result = response.funcDataArg;
@ -116,7 +117,7 @@ export class Smartsocket {
role: undefined,
side: 'server',
smartsocketHost: this,
socket: socketArg
socket: socketArg,
});
logger.log('info', 'Socket connected. Trying to authenticate...');
this.socketConnections.add(socketConnection);

View File

@ -2,7 +2,10 @@ import * as plugins from './smartsocket.plugins';
import * as interfaces from './interfaces';
import { SocketConnection } from './smartsocket.classes.socketconnection';
import { ISocketFunctionCallDataRequest, SocketFunction } from './smartsocket.classes.socketfunction';
import {
ISocketFunctionCallDataRequest,
SocketFunction,
} from './smartsocket.classes.socketfunction';
import { ISocketRequestDataObject, SocketRequest } from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole';
import { logger } from './smartsocket.logging';
@ -47,7 +50,7 @@ export class SmartsocketClient {
this.serverPort = optionsArg.port;
this.socketRole = new SocketRole({
name: optionsArg.role,
passwordHash: optionsArg.password
passwordHash: optionsArg.password,
});
this.autoReconnect = optionsArg.autoReconnect;
}
@ -73,7 +76,7 @@ export class SmartsocketClient {
socket: plugins.socketIoClient(socketUrl, {
multiplex: false,
reconnectionAttempts: 5,
})
}),
});
const timer = new plugins.smarttime.Timer(5000);
@ -84,33 +87,35 @@ export class SmartsocketClient {
});
// authentication flow
this.socketConnection.socket.on('requestAuth', (requestAuthPayload: interfaces.IRequestAuthPayload) => {
timer.reset();
logger.log('info', 'server requested authentication');
this.socketConnection.socket.on(
'requestAuth',
(requestAuthPayload: interfaces.IRequestAuthPayload) => {
timer.reset();
logger.log('info', 'server requested authentication');
// lets register the authenticated event
this.socketConnection.socket.on('authenticated', () => {
this.remoteShortId = requestAuthPayload.serverShortId;
logger.log('info', 'client is authenticated');
this.socketConnection.authenticated = true;
this.socketConnection.listenToFunctionRequests();
done.resolve();
});
// lets register the authenticated event
this.socketConnection.socket.on('authenticated', () => {
this.remoteShortId = requestAuthPayload.serverShortId;
logger.log('info', 'client is authenticated');
this.socketConnection.authenticated = true;
this.socketConnection.listenToFunctionRequests();
done.resolve();
});
// lets register the forbidden event
this.socketConnection.socket.on('forbidden', async () => {
logger.log('warn', `disconnecting due to being forbidden to use the ressource`);
await this.disconnect();
});
// lets register the forbidden event
this.socketConnection.socket.on('forbidden', async () => {
logger.log('warn', `disconnecting due to being forbidden to use the ressource`);
await this.disconnect();
});
// lets provide the actual auth data
this.socketConnection.socket.emit('dataAuth', {
role: this.socketRole.name,
password: this.socketRole.passwordHash,
alias: this.alias
});
});
// lets provide the actual auth data
this.socketConnection.socket.emit('dataAuth', {
role: this.socketRole.name,
password: this.socketRole.passwordHash,
alias: this.alias,
});
}
);
// handle connection
this.socketConnection.socket.on('connect', async () => {
@ -162,7 +167,10 @@ export class SmartsocketClient {
* @param functionNameArg
* @param dataArg
*/
public async serverCall<T extends plugins.typedrequestInterfaces.ITypedRequest>(functionNameArg: T['method'], dataArg: T['request']): Promise<T['response']> {
public async serverCall<T extends plugins.typedrequestInterfaces.ITypedRequest>(
functionNameArg: T['method'],
dataArg: T['request']
): Promise<T['response']> {
const done = plugins.smartpromise.defer();
const socketRequest = new SocketRequest<T>(this, {
side: 'requesting',
@ -170,15 +178,15 @@ export class SmartsocketClient {
shortId: plugins.smartunique.shortId(),
funcCallData: {
funcName: functionNameArg,
funcDataArg: dataArg
}
funcDataArg: dataArg,
},
});
const response = await socketRequest.dispatch();
const result = response.funcDataArg;
return result;
}
private updateStatus (statusArg: interfaces.TConnectionStatus) {
private updateStatus(statusArg: interfaces.TConnectionStatus) {
if (this.eventStatus !== statusArg) {
this.eventSubject.next(statusArg);
}

View File

@ -90,10 +90,7 @@ export class SocketConnection {
public authenticate() {
const done = plugins.smartpromise.defer();
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', () => {});
if (SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
// TODO: authenticate password
@ -101,10 +98,7 @@ export class SocketConnection {
this.authenticated = true;
this.role = SocketRole.getSocketRoleByName(this.smartsocketRef, dataArg.role);
this.socket.emit('authenticated');
logger.log(
'ok',
`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`
);
logger.log('ok', `socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`);
done.resolve(this);
} else {
this.authenticated = false;
@ -113,7 +107,7 @@ export class SocketConnection {
}
});
const requestAuthPayload: interfaces.IRequestAuthPayload = {
serverShortId: this.smartsocketRef.shortId
serverShortId: this.smartsocketRef.shortId,
};
this.socket.emit('requestAuth', requestAuthPayload);
return done.promise;
@ -131,7 +125,7 @@ export class SocketConnection {
// check if requested function is available to the socket's scope
logger.log('info', 'function request received');
const referencedFunction: SocketFunction<any> = this.role.allowedFunctions.find(
socketFunctionArg => {
(socketFunctionArg) => {
return socketFunctionArg.name === dataArg.funcCallData.funcName;
}
);
@ -141,31 +135,22 @@ export class SocketConnection {
side: 'responding',
originSocketConnection: this,
shortId: dataArg.shortId,
funcCallData: dataArg.funcCallData
funcCallData: dataArg.funcCallData,
});
localSocketRequest.createResponse(); // takes care of creating response and sending it back
} else {
logger.log(
'warn',
'function not existent or out of access scope'
);
logger.log('warn', 'function not existent or out of access scope');
}
});
this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject<any>) => {
logger.log(
'info',
`received response for request with id ${dataArg.shortId}`
);
logger.log('info', `received response for request with id ${dataArg.shortId}`);
const targetSocketRequest = SocketRequest.getSocketRequestById(
this.smartsocketRef,
dataArg.shortId
);
targetSocketRequest.handleResponse(dataArg);
});
logger.log(
'info',
`now listening to function requests for ${this.alias}`
);
logger.log('info', `now listening to function requests for ${this.alias}`);
done.resolve(this);
} else {
const errMessage = 'socket needs to be authenticated first';
@ -181,7 +166,7 @@ export class SocketConnection {
this.updateStatus('disconnected');
}
private updateStatus (statusArg: interfaces.TConnectionStatus) {
private updateStatus(statusArg: interfaces.TConnectionStatus) {
if (this.eventStatus !== statusArg) {
this.eventSubject.next(statusArg);
}

View File

@ -11,7 +11,9 @@ import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
/**
* interface of the contructor options of class SocketFunction
*/
export interface ISocketFunctionConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
export interface ISocketFunctionConstructorOptions<
T extends plugins.typedrequestInterfaces.ITypedRequest
> {
funcName: T['method'];
funcDef: TFuncDef<T>;
allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
@ -20,7 +22,9 @@ export interface ISocketFunctionConstructorOptions<T extends plugins.typedreques
/**
* interface of the Socket Function call, in other words the object that routes a call to a function
*/
export interface ISocketFunctionCallDataRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
export interface ISocketFunctionCallDataRequest<
T extends plugins.typedrequestInterfaces.ITypedRequest
> {
funcName: T['method'];
funcDataArg: T['request'];
}
@ -28,7 +32,9 @@ export interface ISocketFunctionCallDataRequest<T extends plugins.typedrequestIn
/**
* interface of the Socket Function call, in other words the object that routes a call to a function
*/
export interface ISocketFunctionCallDataResponse<T extends plugins.typedrequestInterfaces.ITypedRequest> {
export interface ISocketFunctionCallDataResponse<
T extends plugins.typedrequestInterfaces.ITypedRequest
> {
funcName: T['method'];
funcDataArg: T['response'];
}
@ -36,7 +42,10 @@ export interface ISocketFunctionCallDataResponse<T extends plugins.typedrequestI
/**
* interface for function definition of SocketFunction
*/
export type TFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (dataArg: T['request'], connectionArg: SocketConnection) => PromiseLike<T['response']>;
export type TFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (
dataArg: T['request'],
connectionArg: SocketConnection
) => PromiseLike<T['response']>;
// export classes
@ -49,7 +58,7 @@ export class SocketFunction<T extends plugins.typedrequestInterfaces.ITypedReque
smartsocketRefArg: Smartsocket | SmartsocketClient,
functionNameArg: string
): SocketFunction<Q> {
return smartsocketRefArg.socketFunctions.find(socketFunctionArg => {
return smartsocketRefArg.socketFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === functionNameArg;
});
}
@ -74,11 +83,14 @@ export class SocketFunction<T extends plugins.typedrequestInterfaces.ITypedReque
/**
* invokes the function of this SocketFunction
*/
public async invoke(dataArg: ISocketFunctionCallDataRequest<T>, socketConnectionArg: SocketConnection): Promise<ISocketFunctionCallDataResponse<T>> {
public async invoke(
dataArg: ISocketFunctionCallDataRequest<T>,
socketConnectionArg: SocketConnection
): Promise<ISocketFunctionCallDataResponse<T>> {
if (dataArg.funcName === this.name) {
const funcResponseData: ISocketFunctionCallDataResponse<T> = {
funcName: this.name,
funcDataArg: await this.funcDef(dataArg.funcDataArg, socketConnectionArg)
funcDataArg: await this.funcDef(dataArg.funcDataArg, socketConnectionArg),
};
return funcResponseData;
} else {

View File

@ -1,7 +1,11 @@
import * as plugins from './smartsocket.plugins';
// import interfaces
import { SocketFunction, ISocketFunctionCallDataRequest, ISocketFunctionCallDataResponse } from './smartsocket.classes.socketfunction';
import {
SocketFunction,
ISocketFunctionCallDataRequest,
ISocketFunctionCallDataResponse,
} from './smartsocket.classes.socketfunction';
// import classes
import { SocketConnection } from './smartsocket.classes.socketconnection';
@ -16,7 +20,9 @@ export type TSocketRequestSide = 'requesting' | 'responding';
/**
* interface of constructor of class SocketRequest
*/
export interface ISocketRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
export interface ISocketRequestConstructorOptions<
T extends plugins.typedrequestInterfaces.ITypedRequest
> {
side: TSocketRequestSide;
originSocketConnection: SocketConnection;
shortId: string;
@ -39,7 +45,7 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
smartsocketRef: Smartsocket | SmartsocketClient,
shortIdArg: string
): SocketRequest<any> {
return smartsocketRef.socketRequests.find(socketRequestArg => {
return smartsocketRef.socketRequests.find((socketRequestArg) => {
return socketRequestArg.shortid === shortIdArg;
});
}
@ -74,7 +80,7 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
public dispatch(): Promise<ISocketFunctionCallDataResponse<T>> {
const requestData: ISocketRequestDataObject<T> = {
funcCallData: this.funcCallData,
shortId: this.shortid
shortId: this.shortid,
};
this.originSocketConnection.socket.emit('function', requestData);
return this.done.promise;
@ -101,22 +107,21 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
);
if (!targetSocketFunction) {
logger.log(
'warn',
`There is no SocketFunction defined for ${this.funcCallData.funcName}`
);
logger.log('warn', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
logger.log('warn', `So now response is being sent.`);
return;
}
logger.log('info', `invoking ${targetSocketFunction.name}`);
targetSocketFunction.invoke(this.funcCallData, this.originSocketConnection).then(resultData => {
logger.log('info', 'got resultData. Sending it to requesting party.');
const responseData: ISocketRequestDataObject<T> = {
funcCallData: resultData,
shortId: this.shortid
};
this.originSocketConnection.socket.emit('functionResponse', responseData);
this.smartsocketRef.socketRequests.remove(this);
});
targetSocketFunction
.invoke(this.funcCallData, this.originSocketConnection)
.then((resultData) => {
logger.log('info', 'got resultData. Sending it to requesting party.');
const responseData: ISocketRequestDataObject<T> = {
funcCallData: resultData,
shortId: this.shortid,
};
this.originSocketConnection.socket.emit('functionResponse', responseData);
this.smartsocketRef.socketRequests.remove(this);
});
}
}

View File

@ -23,7 +23,7 @@ export class SocketRole {
referenceSmartsocket: Smartsocket | SmartsocketClient,
socketRoleNameArg: string
): SocketRole {
return referenceSmartsocket.socketRoles.find(socketRoleArg => {
return referenceSmartsocket.socketRoles.find((socketRoleArg) => {
return socketRoleArg.name === socketRoleNameArg;
});
}

View File

@ -60,7 +60,10 @@ export class SocketServer {
throw new Error('there should be a port specified for smartsocket');
}
this.httpServer.listen(this.smartsocket.options.port, () => {
logger.log('success', `Server started in standalone mode on ${this.smartsocket.options.port}`);
logger.log(
'success',
`Server started in standalone mode on ${this.smartsocket.options.port}`
);
done.resolve();
});
} else {

View File

@ -1,7 +1,7 @@
// apiglobal scope
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export {typedrequestInterfaces};
export { typedrequestInterfaces };
// pushrocks scope
import * as lik from '@pushrocks/lik';
@ -14,7 +14,6 @@ import * as smarttime from '@pushrocks/smarttime';
import * as smartunique from '@pushrocks/smartunique';
import * as smartrx from '@pushrocks/smartrx';
export {
lik,
smartlog,
@ -24,14 +23,11 @@ export {
smartpromise,
smarttime,
smartunique,
smartrx
smartrx,
};
// third party scope
import socketIo from 'socket.io';
import socketIoClient from 'socket.io-client';
export {
socketIo,
socketIoClient
};
export { socketIo, socketIoClient };