Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
109c5197f3 | |||
c3d47c1f50 | |||
1b45fb45e9 | |||
c22adc9b57 | |||
35e87306dd | |||
1b20aa5992 |
770
package-lock.json
generated
770
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsocket",
|
"name": "@pushrocks/smartsocket",
|
||||||
"version": "1.1.35",
|
"version": "1.1.38",
|
||||||
"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",
|
||||||
@ -21,7 +21,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.5",
|
"@pushrocks/lik": "^3.0.5",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartexpress": "^3.0.19",
|
"@pushrocks/smartexpress": "^3.0.21",
|
||||||
"@pushrocks/smarthash": "^2.0.4",
|
"@pushrocks/smarthash": "^2.0.4",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
@ -33,12 +33,12 @@
|
|||||||
"socket.io-client": "^2.2.0"
|
"socket.io-client": "^2.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.8",
|
"@gitzone/tsbuild": "^2.1.11",
|
||||||
"@gitzone/tsrun": "^1.2.5",
|
"@gitzone/tsrun": "^1.2.6",
|
||||||
"@gitzone/tstest": "^1.0.20",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@pushrocks/tapbundle": "^3.0.9",
|
||||||
"@types/node": "^11.13.7",
|
"@types/node": "^12.0.6",
|
||||||
"tslint": "^5.16.0",
|
"tslint": "^5.17.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"private": false
|
"private": false
|
||||||
|
@ -39,7 +39,7 @@ tap.test('should add a socketrole', async () => {
|
|||||||
tap.test('should register a new Function', async () => {
|
tap.test('should register a new Function', async () => {
|
||||||
testSocketFunction1 = new smartsocket.SocketFunction({
|
testSocketFunction1 = new smartsocket.SocketFunction({
|
||||||
allowedRoles: [testSocketRole1],
|
allowedRoles: [testSocketRole1],
|
||||||
funcDef: async dataArg => {
|
funcDef: async (dataArg, socketConnectionArg) => {
|
||||||
return dataArg;
|
return dataArg;
|
||||||
},
|
},
|
||||||
funcName: 'testFunction1'
|
funcName: 'testFunction1'
|
||||||
|
@ -83,8 +83,8 @@ export class Smartsocket {
|
|||||||
shortId: plugins.shortid.generate(),
|
shortId: plugins.shortid.generate(),
|
||||||
side: 'requesting'
|
side: 'requesting'
|
||||||
});
|
});
|
||||||
socketRequest.dispatch().then((dataArg: ISocketFunctionCall) => {
|
socketRequest.dispatch().then((dataArg2: ISocketFunctionCall) => {
|
||||||
done.resolve(dataArg.funcDataArg);
|
done.resolve(dataArg2.funcDataArg);
|
||||||
});
|
});
|
||||||
const result = await done.promise;
|
const result = await done.promise;
|
||||||
return result;
|
return result;
|
||||||
|
@ -51,12 +51,12 @@ export let allSocketConnections = new Objectmap<SocketConnection>();
|
|||||||
* class SocketConnection represents a websocket connection
|
* class SocketConnection represents a websocket connection
|
||||||
*/
|
*/
|
||||||
export class SocketConnection {
|
export class SocketConnection {
|
||||||
alias: string;
|
public alias: string;
|
||||||
side: TSocketConnectionSide;
|
public side: TSocketConnectionSide;
|
||||||
authenticated: boolean = false;
|
public authenticated: boolean = false;
|
||||||
role: SocketRole;
|
public role: SocketRole;
|
||||||
smartsocketHost: Smartsocket;
|
public smartsocketHost: Smartsocket;
|
||||||
socket: any; // SocketIO.Socket | SocketIOClient.Socket
|
public socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||||
constructor(optionsArg: ISocketConnectionConstructorOptions) {
|
constructor(optionsArg: ISocketConnectionConstructorOptions) {
|
||||||
this.alias = optionsArg.alias;
|
this.alias = optionsArg.alias;
|
||||||
this.authenticated = optionsArg.authenticated;
|
this.authenticated = optionsArg.authenticated;
|
||||||
|
@ -3,6 +3,7 @@ import * as plugins from './smartsocket.plugins';
|
|||||||
// import classes
|
// import classes
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||||
|
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||||
|
|
||||||
// export interfaces
|
// export interfaces
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ import { SocketRole } from './smartsocket.classes.socketrole';
|
|||||||
*/
|
*/
|
||||||
export interface ISocketFunctionConstructorOptions {
|
export interface ISocketFunctionConstructorOptions {
|
||||||
funcName: string;
|
funcName: string;
|
||||||
funcDef: any;
|
funcDef: TFuncDef;
|
||||||
allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
|
allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,9 +27,7 @@ export interface ISocketFunctionCall {
|
|||||||
/**
|
/**
|
||||||
* interface for function definition of SocketFunction
|
* interface for function definition of SocketFunction
|
||||||
*/
|
*/
|
||||||
export interface IFuncDef {
|
export type TFuncDef = (dataArg: any, connectionArg: SocketConnection) => PromiseLike<any>;
|
||||||
(dataArg: any): PromiseLike<any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// export objects
|
// export objects
|
||||||
export let allSocketFunctions = new Objectmap<SocketFunction>();
|
export let allSocketFunctions = new Objectmap<SocketFunction>();
|
||||||
@ -40,7 +39,7 @@ export let allSocketFunctions = new Objectmap<SocketFunction>();
|
|||||||
*/
|
*/
|
||||||
export class SocketFunction {
|
export class SocketFunction {
|
||||||
name: string;
|
name: string;
|
||||||
funcDef: IFuncDef;
|
funcDef: TFuncDef;
|
||||||
roles: SocketRole[];
|
roles: SocketRole[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,10 +58,10 @@ export class SocketFunction {
|
|||||||
/**
|
/**
|
||||||
* invokes the function of this SocketFunction
|
* invokes the function of this SocketFunction
|
||||||
*/
|
*/
|
||||||
invoke(dataArg: ISocketFunctionCall): Promise<any> {
|
invoke(dataArg: ISocketFunctionCall, socketConnectionArg: SocketConnection): Promise<any> {
|
||||||
let done = plugins.smartpromise.defer();
|
let done = plugins.smartpromise.defer();
|
||||||
if (dataArg.funcName === this.name) {
|
if (dataArg.funcName === this.name) {
|
||||||
this.funcDef(dataArg.funcDataArg).then((resultData: any) => {
|
this.funcDef(dataArg.funcDataArg, socketConnectionArg).then((resultData: any) => {
|
||||||
let funcResponseData: ISocketFunctionCall = {
|
let funcResponseData: ISocketFunctionCall = {
|
||||||
funcName: this.name,
|
funcName: this.name,
|
||||||
funcDataArg: resultData
|
funcDataArg: resultData
|
||||||
|
@ -38,12 +38,12 @@ export let allSocketRequests = new Objectmap<SocketRequest>();
|
|||||||
|
|
||||||
// export classes
|
// export classes
|
||||||
export class SocketRequest {
|
export class SocketRequest {
|
||||||
status: TSocketRequestStatus = 'new';
|
public status: TSocketRequestStatus = 'new';
|
||||||
side: TSocketRequestSide;
|
public side: TSocketRequestSide;
|
||||||
shortid: string;
|
public shortid: string;
|
||||||
originSocketConnection: SocketConnection;
|
public originSocketConnection: SocketConnection;
|
||||||
funcCallData: ISocketFunctionCall;
|
public funcCallData: ISocketFunctionCall;
|
||||||
done = plugins.smartpromise.defer();
|
public done = plugins.smartpromise.defer();
|
||||||
constructor(optionsArg: SocketRequestConstructorOptions) {
|
constructor(optionsArg: SocketRequestConstructorOptions) {
|
||||||
this.side = optionsArg.side;
|
this.side = optionsArg.side;
|
||||||
this.shortid = optionsArg.shortId;
|
this.shortid = optionsArg.shortId;
|
||||||
@ -57,7 +57,7 @@ export class SocketRequest {
|
|||||||
/**
|
/**
|
||||||
* dispatches a socketrequest from the requesting to the receiving side
|
* dispatches a socketrequest from the requesting to the receiving side
|
||||||
*/
|
*/
|
||||||
dispatch() {
|
public dispatch() {
|
||||||
let requestData: ISocketRequestDataObject = {
|
let requestData: ISocketRequestDataObject = {
|
||||||
funcCallData: this.funcCallData,
|
funcCallData: this.funcCallData,
|
||||||
shortId: this.shortid
|
shortId: this.shortid
|
||||||
@ -69,7 +69,7 @@ export class SocketRequest {
|
|||||||
/**
|
/**
|
||||||
* handles the response that is received by the requesting side
|
* handles the response that is received by the requesting side
|
||||||
*/
|
*/
|
||||||
handleResponse(responseDataArg: ISocketRequestDataObject) {
|
public handleResponse(responseDataArg: ISocketRequestDataObject) {
|
||||||
plugins.smartlog.defaultLogger.log('info', 'handling response!');
|
plugins.smartlog.defaultLogger.log('info', 'handling response!');
|
||||||
this.done.resolve(responseDataArg.funcCallData);
|
this.done.resolve(responseDataArg.funcCallData);
|
||||||
allSocketRequests.remove(this);
|
allSocketRequests.remove(this);
|
||||||
@ -85,12 +85,15 @@ export class SocketRequest {
|
|||||||
this.funcCallData.funcName
|
this.funcCallData.funcName
|
||||||
);
|
);
|
||||||
if (!targetSocketFunction) {
|
if (!targetSocketFunction) {
|
||||||
defaultLogger.log('warn', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
|
defaultLogger.log(
|
||||||
|
'warn',
|
||||||
|
`There is no SocketFunction defined for ${this.funcCallData.funcName}`
|
||||||
|
);
|
||||||
defaultLogger.log('warn', `So now response is being sent.`);
|
defaultLogger.log('warn', `So now response is being sent.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugins.smartlog.defaultLogger.log('info', `invoking ${targetSocketFunction.name}`);
|
plugins.smartlog.defaultLogger.log('info', `invoking ${targetSocketFunction.name}`);
|
||||||
targetSocketFunction.invoke(this.funcCallData).then(resultData => {
|
targetSocketFunction.invoke(this.funcCallData, this.originSocketConnection).then(resultData => {
|
||||||
plugins.smartlog.defaultLogger.log('info', 'got resultData. Sending it to requesting party.');
|
plugins.smartlog.defaultLogger.log('info', 'got resultData. Sending it to requesting party.');
|
||||||
let requestData: ISocketRequestDataObject = {
|
let requestData: ISocketRequestDataObject = {
|
||||||
funcCallData: resultData,
|
funcCallData: resultData,
|
||||||
|
@ -5,8 +5,8 @@ import * as smartdelay from '@pushrocks/smartdelay';
|
|||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as shortid from 'shortid';
|
import * as shortid from 'shortid';
|
||||||
import * as socketIo from 'socket.io';
|
import socketIo from 'socket.io';
|
||||||
import * as socketIoClient from 'socket.io-client';
|
import socketIoClient from 'socket.io-client';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
|
Reference in New Issue
Block a user