Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
e188b18016 | |||
33c0fa3746 | |||
52be1415ee | |||
e75d5eabdb | |||
fb99848df1 | |||
1bd39d0755 | |||
d24c5f628c | |||
33fbabdd72 | |||
9d26fff986 | |||
41151e5436 | |||
109c5197f3 | |||
c3d47c1f50 | |||
1b45fb45e9 | |||
c22adc9b57 | |||
35e87306dd | |||
1b20aa5992 | |||
a63f14da47 | |||
86cf94c5dc | |||
0d39d6f237 | |||
1856ad5cfc | |||
b5dab810e8 | |||
f145b85b1c | |||
a8c647c5c7 | |||
22472e0adf | |||
333ddb4d9c | |||
126f020bf8 | |||
7677b1bb48 | |||
114379c5b3 | |||
79ae7d2039 | |||
d2cb6a3045 | |||
963619b2ed | |||
976abaaed7 | |||
ef322c32ac | |||
475911a968 | |||
5530e29da4 | |||
5f1d2c83c6 | |||
b84dd36885 | |||
c2d64ba39a | |||
85a5d7cdaf | |||
69380a2dbc | |||
fc292d83b9 | |||
b29961df95 | |||
f774a82ad5 | |||
5a45f4750b | |||
fc6227ef96 | |||
873aba3e0b | |||
f9bed9da8a | |||
d296064bfa | |||
1b0922759a | |||
aef4f9c591 | |||
abf546eec3 | |||
483cb38175 | |||
b2bd66a6a6 | |||
cfc3e8788d | |||
23c14c032c | |||
c92dae809f | |||
7200464e4b | |||
eaa97f0598 | |||
cde8270313 | |||
1b073ac8f6 | |||
3f3857df1e | |||
02e17a52c3 | |||
287c2a73c5 | |||
dea3746bb0 | |||
fc2a55bb0d | |||
99eca912d3 | |||
0b6929af8f | |||
0aa073f2a7 | |||
7170e58457 | |||
cccee35f2c | |||
118ec84ec5 | |||
dd31eea263 | |||
477429143d | |||
ea6fa14133 | |||
02065e36a6 | |||
f34358db81 | |||
fddf54b2b1 | |||
e1dbdc1a15 | |||
f3031a1d4e | |||
47ca497d48 | |||
c7e3c4537b | |||
62b36ab859 | |||
4563aade16 | |||
47596bfa59 | |||
6543d60019 |
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,3 +1,22 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
111
.gitlab-ci.yml
111
.gitlab-ci.yml
@ -1,36 +1,119 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:18-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
13
.snyk
Normal file
13
.snyk
Normal file
@ -0,0 +1,13 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.5
|
||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
||||
ignore:
|
||||
SNYK-JS-JSYAML-173999:
|
||||
- '@pushrocks/smartexpress > @pushrocks/smartfile > js-yaml':
|
||||
reason: None given
|
||||
expires: '2019-05-24T15:16:11.291Z'
|
||||
SNYK-JS-JSYAML-174129:
|
||||
- '@pushrocks/smartexpress > @pushrocks/smartfile > js-yaml':
|
||||
reason: None given
|
||||
expires: '2019-05-24T15:16:11.291Z'
|
||||
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
123
README.md
123
README.md
@ -1,76 +1,111 @@
|
||||
# smartsocket
|
||||
easy and secure websocket communication, Typescript ready
|
||||
# @pushrocks/smartsocket
|
||||
easy and secure websocket communication
|
||||
|
||||
## Status
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartsocket)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartsocket)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartsocket)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsocket/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartsocket/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartsocket/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartsocket)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartsocket)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
We recommend the use of typescript.
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
Under the hood we use socket.io and shortid for managed data exchange.
|
||||
|
||||
### Serverside
|
||||
|
||||
```typescript
|
||||
import * as smartsocket from "smartsocket";
|
||||
import * as smartsocket from 'smartsocket';
|
||||
import * as q from q; // q is a promise library
|
||||
|
||||
// The "Smartsocket" listens on a port and can receive new "SocketConnection" requests.
|
||||
let mySmartsocket = new smartsocket.Smartsocket({
|
||||
port: 3000 // the port smartsocket will listen on
|
||||
port: 3000 // the port smartsocket will listen on
|
||||
});
|
||||
|
||||
// optional:
|
||||
// run this with anothoer existing server like express
|
||||
declare var someExpressServer; // read the express docs about how express actually works
|
||||
mySmartsocket.setServer(someExpressServer);
|
||||
|
||||
// A "SocketRole" can be referenced by "SocketFunction"s.
|
||||
// All "SocketRequest"s carry authentication data for a specific "SocketRole".
|
||||
// "SocketFunction"s know which "SocketRole"s are allowed to execute them
|
||||
let mySocketRole = new smartsocket.SocketRole({
|
||||
name: "someRoleName",
|
||||
passwordHash: "someHashedString"
|
||||
name: 'someRoleName',
|
||||
passwordHash: 'someHashedString'
|
||||
});
|
||||
|
||||
// A "SocketFunction" executes a referenced function and passes in any data of the corresponding "SocketRequest".
|
||||
// The referenced function must return a promise and resolve with data of type any.
|
||||
// Any "SocketRequest" carries a unique identifier. If the referenced function's promise resolved any passed on argument will be returned to the requesting party
|
||||
let testSocketFunction1 = new smartsocket.SocketFunction({
|
||||
funcName:"testSocketFunction1",
|
||||
funcDef:(data) => {
|
||||
|
||||
}, // the function to execute
|
||||
allowedRoles:[mySocketRole] // all roles that have access to a specific function
|
||||
funcName: 'testSocketFunction1',
|
||||
funcDef: data => {
|
||||
console.log('testSocketFunction1 executed successfully!');
|
||||
},
|
||||
allowedRoles: [mySocketRole] // all roles that have access to a specific function
|
||||
});
|
||||
|
||||
mySmartsocket.clientCall("","restart",data,someTargetConnection)
|
||||
.then((responseData) => {
|
||||
|
||||
});
|
||||
// A "Smartsocket" exposes a .clientCall() that gets
|
||||
// 1. the name of the "SocketFunction" on the client side
|
||||
// 2. the data to pass in
|
||||
// 3. And a target "SocketConnection" (there can be multiple connections at once)
|
||||
// any unique id association is done internally
|
||||
mySmartsocket.clientCall('restart', data, someTargetConnection).then(responseData => {});
|
||||
```
|
||||
|
||||
#### Client side
|
||||
|
||||
```typescript
|
||||
import * as smartsocket from "smartsocket";
|
||||
import * as smartsocket from 'smartsocket';
|
||||
|
||||
// A "SmartsocketClient" is different from a "Smartsocket" in that it doesn't expose any public address.
|
||||
// Thus any new "SocketConnection"s must be innitiated from a "SmartsocketClient".
|
||||
let testSmartsocketClient = new smartsocket.SmartsocketClient({
|
||||
port: testConfig.port,
|
||||
url: "http://localhost",
|
||||
password: "testPassword",
|
||||
alias: "testClient1",
|
||||
role: "testRole1"
|
||||
port: testConfig.port,
|
||||
url: 'http://localhost',
|
||||
password: 'testPassword',
|
||||
alias: 'testClient1',
|
||||
role: 'testRole1'
|
||||
});
|
||||
testSmartsocketClient.connect()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
// You can .connect() and .disconnect() from a "Smartsocket"
|
||||
testSmartsocketClient.connect().then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
// The client can also specify "SocketFunction"s. It can also specify "SocketRole"s in case a client connects to multiple servers at once
|
||||
let testSocketFunction2 = new smartsocket.SocketFunction({
|
||||
funcName: "testSocketFunction2",
|
||||
funcDef: (data) => {}, // the function to execute, has to return promise
|
||||
allowedRoles:[]
|
||||
funcName: 'testSocketFunction2',
|
||||
funcDef: data => {}, // the function to execute, has to return promise
|
||||
allowedRoles: []
|
||||
});
|
||||
|
||||
let functionCalldata = {
|
||||
funcName: "",
|
||||
funcData: {
|
||||
someKey:"someValue"
|
||||
}
|
||||
}
|
||||
|
||||
mySmartsocketClient.serverCall("function",functionCallData)
|
||||
.then((functionResponseData) => { // the functionResponseData comes from the server... awesome, right?
|
||||
|
||||
});;
|
||||
// A "SmartsocketClient" can call functions on the serverside using .serverCall() analog to the "Smartsocket"'s .clientCall method.
|
||||
mySmartsocketClient.serverCall('function', functionCallData).then(functionResponseData => {
|
||||
// the functionResponseData comes from the server... awesome, right?
|
||||
});
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
you can easily chain dependent requests on either the server or client side with promises.
|
||||
`data` is always a js object that you can design for your specific needs.
|
||||
It supports buffers for large binary data network exchange.
|
||||
> you can easily chain dependent requests on either the server or client side with promises.
|
||||
> `data` is always a js object that you can design for your specific needs.
|
||||
> It supports buffers for large binary data network exchange.
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
5
dist/index.d.ts
vendored
5
dist/index.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export * from "./smartsocket.classes.smartsocket";
|
||||
export * from "./smartsocket.classes.smartsocketclient";
|
||||
export * from "./smartsocket.classes.socketfunction";
|
||||
export * from "./smartsocket.classes.socketrole";
|
||||
export { allSocketConnections } from "./smartsocket.classes.socketconnection";
|
14
dist/index.js
vendored
14
dist/index.js
vendored
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
// export main classes
|
||||
__export(require("./smartsocket.classes.smartsocket"));
|
||||
__export(require("./smartsocket.classes.smartsocketclient"));
|
||||
// export further classes and objects
|
||||
__export(require("./smartsocket.classes.socketfunction"));
|
||||
__export(require("./smartsocket.classes.socketrole"));
|
||||
var smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
|
||||
exports.allSocketConnections = smartsocket_classes_socketconnection_1.allSocketConnections;
|
||||
// need something more exposed? Create an issue on GitLab!
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsc0JBQXNCO0FBQ3RCLGlCQUFjLG1DQUFtQyxDQUFDLEVBQUE7QUFDbEQsaUJBQWMseUNBQXlDLENBQUMsRUFBQTtBQUV4RCxxQ0FBcUM7QUFDckMsaUJBQWMsc0NBQXNDLENBQUMsRUFBQTtBQUNyRCxpQkFBYyxrQ0FBa0MsQ0FBQyxFQUFBO0FBQ2pELHFEQUFtQyx3Q0FBd0MsQ0FBQztBQUFwRSwyRkFBb0U7QUFFNUUsMERBQTBEIn0=
|
27
dist/smartsocket.classes.smartsocket.d.ts
vendored
27
dist/smartsocket.classes.smartsocket.d.ts
vendored
@ -1,27 +0,0 @@
|
||||
/// <reference types="socket.io" />
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
export interface ISmartsocketConstructorOptions {
|
||||
port: number;
|
||||
}
|
||||
export declare class Smartsocket {
|
||||
options: ISmartsocketConstructorOptions;
|
||||
io: SocketIO.Server;
|
||||
openSockets: Objectmap<SocketConnection>;
|
||||
constructor(optionsArg: ISmartsocketConstructorOptions);
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocketConnection(socketArg);
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
startServer: () => void;
|
||||
closeServer: () => void;
|
||||
/**
|
||||
* allows call to specific client.
|
||||
*/
|
||||
clientCall(functionNameArg: string, dataArg: any, targetSocketConnectionArg: SocketConnection): plugins.q.Promise<{}>;
|
||||
}
|
76
dist/smartsocket.classes.smartsocket.js
vendored
76
dist/smartsocket.classes.smartsocket.js
vendored
@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
// classes
|
||||
const lik_1 = require("lik");
|
||||
const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
|
||||
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
|
||||
;
|
||||
class Smartsocket {
|
||||
constructor(optionsArg) {
|
||||
this.openSockets = new lik_1.Objectmap();
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
this.startServer = () => {
|
||||
this.io = plugins.socketIo(this.options.port);
|
||||
this.io.on("connection", (socketArg) => {
|
||||
this._handleSocketConnection(socketArg);
|
||||
});
|
||||
};
|
||||
this.closeServer = () => {
|
||||
this.openSockets.forEach((socketObjectArg) => {
|
||||
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
};
|
||||
this.options = optionsArg;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
_handleSocketConnection(socketArg) {
|
||||
let socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
|
||||
alias: undefined,
|
||||
authenticated: false,
|
||||
role: undefined,
|
||||
side: "server",
|
||||
socket: socketArg
|
||||
});
|
||||
plugins.beautylog.log("Socket connected. Trying to authenticate...");
|
||||
this.openSockets.add(socketConnection);
|
||||
socketConnection.authenticate()
|
||||
.then(() => {
|
||||
return socketConnection.listenToFunctionRequests();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
;
|
||||
// communication
|
||||
/**
|
||||
* allows call to specific client.
|
||||
*/
|
||||
clientCall(functionNameArg, dataArg, targetSocketConnectionArg) {
|
||||
let done = plugins.q.defer();
|
||||
let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
|
||||
side: "requesting",
|
||||
originSocketConnection: targetSocketConnectionArg,
|
||||
shortId: plugins.shortid.generate(),
|
||||
funcCallData: {
|
||||
funcName: functionNameArg,
|
||||
funcDataArg: dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch()
|
||||
.then((dataArg) => {
|
||||
done.resolve(dataArg.funcDataArg);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
exports.Smartsocket = Smartsocket;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUVoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUMxRSxvREFBOEIscUNBQXFDLENBQUMsQ0FBQTtBQUtuRSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUEyQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLFlBQVksRUFBRSxDQUFDLFNBQVM7Z0JBQy9CLElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxTQUFTLEN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UFDLENBQUM7YUFDRCxLQUFLLENBQUMsQ0FBQyxHQUFHO1lBQ1AsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQztRQUNyQixDQUFDLENBQUMsQ0FBQztJQUNYLENBQUM7O0lBcUJELGdCQUFnQjtJQUVoQjs7T0FFRztJQUNILFVBQVUsQ0FBQyxlQUFzQixFQUFDLE9BQVcsRUFBQyx5QkFBMEM7UUFDcEYsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixJQUFJLGFBQWEsR0FBRyxJQUFJLGlEQUFhLENBQUM7WUFDbEMsSUFBSSxFQUFDLFlBQVk7WUFDakIsc0JBQXNCLEVBQUMseUJBQXlCO1lBQ2hELE9BQU8sRUFBQyxPQUFPLENBQUMsT0FBTyxDQUFDLFFBQVEsRUFBRTtZQUNsQyxZQUFZLEVBQUM7Z0JBQ1QsUUFBUSxFQUFFLGVBQWU7Z0JBQ3pCLFdBQVcsRUFBQyxPQUFPO2FBQ3RCO1NBQ0osQ0FBQyxDQUFDO1FBQ0gsYUFBYSxDQUFDLFFBQVEsRUFBRTthQUNuQixJQUFJLENBQUMsQ0FBQyxPQUEyQjtZQUM5QixJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUN0QyxDQUFDLENBQUMsQ0FBQztRQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7QUFDTCxDQUFDO0FBdkVZLG1CQUFXLGNBdUV2QixDQUFBIn0=
|
28
dist/smartsocket.classes.smartsocketclient.d.ts
vendored
28
dist/smartsocket.classes.smartsocketclient.d.ts
vendored
@ -1,28 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
/**
|
||||
* interface for class SmartsocketClient
|
||||
*/
|
||||
export interface ISmartsocketClientOptions {
|
||||
port: number;
|
||||
url: string;
|
||||
alias: string;
|
||||
role: string;
|
||||
password: string;
|
||||
}
|
||||
export declare class SmartsocketClient {
|
||||
alias: string;
|
||||
role: string;
|
||||
socketConnection: SocketConnection;
|
||||
serverUrl: string;
|
||||
serverPort: number;
|
||||
serverPassword: string;
|
||||
constructor(optionsArg: ISmartsocketClientOptions);
|
||||
/**
|
||||
* connect the client to the server
|
||||
*/
|
||||
connect(): plugins.q.Promise<{}>;
|
||||
disconnect(): plugins.q.Promise<{}>;
|
||||
serverCall(functionNameArg: string, dataArg: any): plugins.q.Promise<{}>;
|
||||
}
|
74
dist/smartsocket.classes.smartsocketclient.js
vendored
74
dist/smartsocket.classes.smartsocketclient.js
vendored
@ -1,74 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
// import classes
|
||||
const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
|
||||
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
|
||||
class SmartsocketClient {
|
||||
constructor(optionsArg) {
|
||||
this.alias = optionsArg.alias;
|
||||
this.role = optionsArg.role;
|
||||
this.serverUrl = optionsArg.url;
|
||||
this.serverPort = optionsArg.port;
|
||||
this.serverPassword = optionsArg.password;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* connect the client to the server
|
||||
*/
|
||||
connect() {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.log("trying to connect...");
|
||||
let socketUrl = `${this.serverUrl}:${this.serverPort}`;
|
||||
this.socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
|
||||
alias: this.alias,
|
||||
authenticated: false,
|
||||
role: undefined,
|
||||
side: "client",
|
||||
socket: plugins.socketIoClient(socketUrl, { multiplex: false })
|
||||
});
|
||||
this.socketConnection.socket.on("requestAuth", () => {
|
||||
console.log("server requested authentication");
|
||||
this.socketConnection.socket.emit("dataAuth", {
|
||||
role: this.role,
|
||||
password: this.serverPassword,
|
||||
alias: this.alias
|
||||
});
|
||||
this.socketConnection.socket.on("authenticated", () => {
|
||||
console.log("client is authenticated");
|
||||
this.socketConnection.authenticated = true;
|
||||
this.socketConnection.listenToFunctionRequests();
|
||||
done.resolve();
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
disconnect() {
|
||||
let done = plugins.q.defer();
|
||||
this.socketConnection.socket.disconnect();
|
||||
this.socketConnection = undefined;
|
||||
plugins.beautylog.ok("disconnected!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
serverCall(functionNameArg, dataArg) {
|
||||
let done = plugins.q.defer();
|
||||
let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
|
||||
side: "requesting",
|
||||
originSocketConnection: this.socketConnection,
|
||||
shortId: plugins.shortid.generate(),
|
||||
funcCallData: {
|
||||
funcName: functionNameArg,
|
||||
funcDataArg: dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch()
|
||||
.then((dataArg) => {
|
||||
done.resolve(dataArg.funcDataArg);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.SmartsocketClient = SmartsocketClient;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUl6QixDQUFDLENBSitDO0FBT2hELGlCQUFpQjtBQUNqQix1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUUxRSxvREFBOEIscUNBQXFDLENBQUMsQ0FBQTtBQVlwRTtJQU9JL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LEVBQUMsT0FBVztRQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQzdCLElBQUksYUFBYSxHQUFHLElBQUksaURBQWEsQ0FBQztZQUNsQyxJQUFJLEVBQUMsWUFBWTtZQUNqQixzQkFBc0IsRUFBQyxJQUFJLENBQUMsZ0JBQWdCO1lBQzVDLE9BQU8sRUFBQyxPQUFPLENBQUMsT0FBTyxDQUFDLFFBQVEsRUFBRTtZQUNsQyxZQUFZLEVBQUM7Z0JBQ1QsUUFBUSxFQUFFLGVBQWU7Z0JBQ3pCLFdBQVcsRUFBQyxPQUFPO2FBQ3RCO1NBQ0osQ0FBQyxDQUFDO1FBQ0gsYUFBYSxDQUFDLFFBQVEsRUFBRTthQUNuQixJQUFJLENBQUMsQ0FBQyxPQUEyQjtZQUM5QixJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUN0QyxDQUFDLENBQUMsQ0FBQztRQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBRUwsQ0FBQztBQXZFWSx5QkFBaUIsb0JBdUU3QixDQUFBIn0=
|
48
dist/smartsocket.classes.socketconnection.d.ts
vendored
48
dist/smartsocket.classes.socketconnection.d.ts
vendored
@ -1,48 +0,0 @@
|
||||
/// <reference types="socket.io" />
|
||||
/// <reference types="socket.io-client" />
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
/**
|
||||
* defines is a SocketConnection is server or client side. Important for mesh setups.
|
||||
*/
|
||||
export declare type TSocketConnectionSide = "server" | "client";
|
||||
/**
|
||||
* interface for constructor of class SocketConnection
|
||||
*/
|
||||
export interface ISocketConnectionConstructorOptions {
|
||||
alias: string;
|
||||
authenticated: boolean;
|
||||
role: SocketRole;
|
||||
side: TSocketConnectionSide;
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
}
|
||||
/**
|
||||
* interface for authentication data
|
||||
*/
|
||||
export interface ISocketConnectionAuthenticationObject {
|
||||
role: "coreflowContainer";
|
||||
password: "somePassword";
|
||||
alias: "coreflow1";
|
||||
}
|
||||
export declare let allSocketConnections: Objectmap<SocketConnection>;
|
||||
/**
|
||||
* class SocketConnection represents a websocket connection
|
||||
*/
|
||||
export declare class SocketConnection {
|
||||
alias: string;
|
||||
side: TSocketConnectionSide;
|
||||
authenticated: boolean;
|
||||
role: SocketRole;
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
constructor(optionsArg: ISocketConnectionConstructorOptions);
|
||||
/**
|
||||
* authenticate the socket
|
||||
*/
|
||||
authenticate(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* listen to function requests
|
||||
*/
|
||||
listenToFunctionRequests(): plugins.q.Promise<{}>;
|
||||
}
|
105
dist/smartsocket.classes.socketconnection.js
vendored
105
dist/smartsocket.classes.socketconnection.js
vendored
@ -1,105 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
const helpers = require("./smartsocket.helpers");
|
||||
const lik_1 = require("lik");
|
||||
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
|
||||
;
|
||||
;
|
||||
// export classes
|
||||
exports.allSocketConnections = new lik_1.Objectmap();
|
||||
/**
|
||||
* class SocketConnection represents a websocket connection
|
||||
*/
|
||||
class SocketConnection {
|
||||
constructor(optionsArg) {
|
||||
this.authenticated = false;
|
||||
this.alias = optionsArg.alias;
|
||||
this.authenticated = optionsArg.authenticated;
|
||||
this.role = optionsArg.role;
|
||||
this.side = optionsArg.side;
|
||||
this.socket = optionsArg.socket;
|
||||
// standard behaviour that is always true
|
||||
exports.allSocketConnections.add(this);
|
||||
this.socket.on("disconnect", () => {
|
||||
plugins.beautylog.info(`SocketConnection with >alias ${this.alias} on >side ${this.side} disconnected`);
|
||||
exports.allSocketConnections.remove(this);
|
||||
});
|
||||
}
|
||||
;
|
||||
// authenticating --------------------------
|
||||
/**
|
||||
* authenticate the socket
|
||||
*/
|
||||
authenticate() {
|
||||
let done = plugins.q.defer();
|
||||
this.socket.on("dataAuth", (dataArg) => {
|
||||
plugins.beautylog.log("received authentication data. now hashing and comparing...");
|
||||
this.socket.removeListener("dataAuth", () => { });
|
||||
if (helpers.checkPasswordForRole(dataArg)) {
|
||||
this.alias = dataArg.alias;
|
||||
this.authenticated = true;
|
||||
this.role = helpers.getSocketRoleByName(dataArg.role);
|
||||
this.socket.emit("authenticated");
|
||||
plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`);
|
||||
done.resolve(this);
|
||||
}
|
||||
else {
|
||||
this.authenticated = false;
|
||||
this.socket.disconnect();
|
||||
done.reject("not authenticated");
|
||||
}
|
||||
;
|
||||
});
|
||||
this.socket.emit("requestAuth");
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
// listening -------------------------------
|
||||
/**
|
||||
* listen to function requests
|
||||
*/
|
||||
listenToFunctionRequests() {
|
||||
let done = plugins.q.defer();
|
||||
if (this.authenticated) {
|
||||
this.socket.on("function", (dataArg) => {
|
||||
// check if requested function is available to the socket's scope
|
||||
plugins.beautylog.log("function request received");
|
||||
let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
|
||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||
});
|
||||
if (referencedFunction !== undefined) {
|
||||
plugins.beautylog.ok("function in access scope");
|
||||
let localSocketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
|
||||
side: "responding",
|
||||
originSocketConnection: this,
|
||||
shortId: dataArg.shortId,
|
||||
funcCallData: dataArg.funcCallData
|
||||
});
|
||||
localSocketRequest.createResponse(); // takes care of creating response and sending it back
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.warn("function not existent or out of access scope");
|
||||
}
|
||||
;
|
||||
});
|
||||
this.socket.on("functionResponse", (dataArg) => {
|
||||
plugins.beautylog.info(`received response for request with id ${dataArg.shortId}`);
|
||||
let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId);
|
||||
targetSocketRequest.handleResponse(dataArg);
|
||||
});
|
||||
plugins.beautylog.log(`now listening to function requests for ${this.alias}`);
|
||||
done.resolve(this);
|
||||
}
|
||||
else {
|
||||
let errMessage;
|
||||
plugins.beautylog.error(errMessage);
|
||||
done.reject(errMessage);
|
||||
}
|
||||
;
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.SocketConnection = SocketConnection;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsc0JBQXdCLEtBQUssQ0FBQyxDQUFBO0FBSTlCLG9EQUEyRSxxQ0FBcUMsQ0FBQyxDQUFBO0FBbUJoSCxDQUFDO0FBU0QsQ0FBQztBQUVGLGlCQUFpQjtBQUNOLDRCQUFvQixHQUFHLElBQUksZUFBUyxFQUFvQixDQUFDO0FBRXBFOztHQUVHO0FBQ0g7SUFNSSxZQUFZLFVBQStDO1FBSDNELGtCQUFhLEdBQVksS0FBSyxDQUFDO1FBSTNCLElBQUksQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFDLEtBQUssQ0FBQztRQUM5QixJQUFJLENBQUMsYUFBYSxHQUFHLFVBQVUsQ0FBQyxhQU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hFLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLHlDQUF5QyxPQUFPLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztnQkFDbkYsSUFBSSxtQkFBbUIsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO2dCQUN4RSxtQkFBbUIsQ0FBQyxjQUFjLENBQUMsT0FBTyxDQUFDLENBQUM7WUFDaEQsQ0FBQyxDQUFDLENBQUM7WUFDSCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQywwQ0FBMEMsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUM7WUFDOUUsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUN2QixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixJQUFJLFVBQW9ELENBQUM7WUFDekQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsVUFBVSxDQUFDLENBQUM7WUFDcEMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsQ0FBQztRQUM1QixDQUFDO1FBQUEsQ0FBQztRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBSUwsQ0FBQztBQTVGWSx3QkFBZ0IsbUJBNEY1QixDQUFBO0FBQUEsQ0FBQyJ9
|
46
dist/smartsocket.classes.socketfunction.d.ts
vendored
46
dist/smartsocket.classes.socketfunction.d.ts
vendored
@ -1,46 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
/**
|
||||
* interface of the contructor options of class SocketFunction
|
||||
*/
|
||||
export interface ISocketFunctionConstructorOptions {
|
||||
funcName: string;
|
||||
funcDef: any;
|
||||
allowedRoles: SocketRole[];
|
||||
}
|
||||
/**
|
||||
* interface of the Socket Function call, in other words the object that routes a call to a function
|
||||
*/
|
||||
export interface ISocketFunctionCall {
|
||||
funcName: string;
|
||||
funcDataArg: any;
|
||||
}
|
||||
/**
|
||||
* interface for function definition of SocketFunction
|
||||
*/
|
||||
export interface IFuncDef {
|
||||
(dataArg: any): PromiseLike<any>;
|
||||
}
|
||||
export declare let allSocketFunctions: Objectmap<SocketFunction>;
|
||||
/**
|
||||
* class that respresents a function that can be transparently called using a SocketConnection
|
||||
*/
|
||||
export declare class SocketFunction {
|
||||
name: string;
|
||||
funcDef: IFuncDef;
|
||||
roles: SocketRole[];
|
||||
/**
|
||||
* the constructor for SocketFunction
|
||||
*/
|
||||
constructor(optionsArg: ISocketFunctionConstructorOptions);
|
||||
/**
|
||||
* notifies a role about access to this SocketFunction
|
||||
*/
|
||||
private _notifyRole(socketRoleArg);
|
||||
/**
|
||||
* invokes the function of this SocketFunction
|
||||
*/
|
||||
invoke(dataArg: ISocketFunctionCall): plugins.q.Promise<any>;
|
||||
}
|
57
dist/smartsocket.classes.socketfunction.js
vendored
57
dist/smartsocket.classes.socketfunction.js
vendored
@ -1,57 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
// import classes
|
||||
const lik_1 = require("lik");
|
||||
;
|
||||
;
|
||||
// export objects
|
||||
exports.allSocketFunctions = new lik_1.Objectmap();
|
||||
// export classes
|
||||
/**
|
||||
* class that respresents a function that can be transparently called using a SocketConnection
|
||||
*/
|
||||
class SocketFunction {
|
||||
/**
|
||||
* the constructor for SocketFunction
|
||||
*/
|
||||
constructor(optionsArg) {
|
||||
this.name = optionsArg.funcName;
|
||||
this.funcDef = optionsArg.funcDef;
|
||||
this.roles = optionsArg.allowedRoles;
|
||||
for (let socketRoleArg of this.roles) {
|
||||
this._notifyRole(socketRoleArg);
|
||||
}
|
||||
;
|
||||
exports.allSocketFunctions.add(this); // map instance with Objectmap
|
||||
}
|
||||
;
|
||||
/**
|
||||
* notifies a role about access to this SocketFunction
|
||||
*/
|
||||
_notifyRole(socketRoleArg) {
|
||||
socketRoleArg.addSocketFunction(this);
|
||||
}
|
||||
/**
|
||||
* invokes the function of this SocketFunction
|
||||
*/
|
||||
invoke(dataArg) {
|
||||
let done = plugins.q.defer();
|
||||
if (dataArg.funcName === this.name) {
|
||||
this.funcDef(dataArg.funcDataArg)
|
||||
.then((resultData) => {
|
||||
let funcResponseData = {
|
||||
funcName: this.name,
|
||||
funcDataArg: resultData
|
||||
};
|
||||
done.resolve(funcResponseData);
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw new Error("SocketFunction.name does not match the data argument's .name!");
|
||||
}
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.SocketFunction = SocketFunction;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQVkvQixDQUFDO0FBUUQsQ0FBQztBQVNGLGlCQUFpQjtBQUNOLDBCQUFrQixHQUFHLElBQUksZUFBUyxFQUFrQixDQUFDO0FBRWhFLGlCQUFpQjtBQUVqQjs7R0FFRztBQUNIO0lBS0k7O09BRUc7SUFDSCxZQUFZLFVBQTZDO1FBQ3JELElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLFFBQVEsQ0FBQztRQUNoQyxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFP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QztRQUNyRixDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFFTCxDQUFDO0FBOUNZLHNCQUFjLGlCQThDMUIsQ0FBQSJ9
|
46
dist/smartsocket.classes.socketrequest.d.ts
vendored
46
dist/smartsocket.classes.socketrequest.d.ts
vendored
@ -1,46 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
export declare type TSocketRequestStatus = "new" | "pending" | "finished";
|
||||
export declare type TSocketRequestSide = "requesting" | "responding";
|
||||
/**
|
||||
* interface of constructor of class SocketRequest
|
||||
*/
|
||||
export interface SocketRequestConstructorOptions {
|
||||
side: TSocketRequestSide;
|
||||
originSocketConnection: SocketConnection;
|
||||
shortId: string;
|
||||
funcCallData?: ISocketFunctionCall;
|
||||
}
|
||||
/**
|
||||
* request object that is sent initially and may or may not receive a response
|
||||
*/
|
||||
export interface ISocketRequestDataObject {
|
||||
funcCallData: ISocketFunctionCall;
|
||||
shortId: string;
|
||||
responseTimeout?: number;
|
||||
}
|
||||
export declare let allSocketRequests: Objectmap<SocketRequest>;
|
||||
export declare class SocketRequest {
|
||||
status: TSocketRequestStatus;
|
||||
side: TSocketRequestSide;
|
||||
shortid: string;
|
||||
originSocketConnection: SocketConnection;
|
||||
funcCallData: ISocketFunctionCall;
|
||||
done: plugins.q.Deferred<{}>;
|
||||
constructor(optionsArg: SocketRequestConstructorOptions);
|
||||
/**
|
||||
* dispatches a socketrequest from the requesting to the receiving side
|
||||
*/
|
||||
dispatch(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* handles the response that is received by the requesting side
|
||||
*/
|
||||
handleResponse(responseDataArg: ISocketRequestDataObject): void;
|
||||
/**
|
||||
* creates the response on the responding side
|
||||
*/
|
||||
createResponse(): void;
|
||||
}
|
64
dist/smartsocket.classes.socketrequest.js
vendored
64
dist/smartsocket.classes.socketrequest.js
vendored
@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
const helpers = require("./smartsocket.helpers");
|
||||
// import classes
|
||||
const lik_1 = require("lik");
|
||||
;
|
||||
;
|
||||
//export objects
|
||||
exports.allSocketRequests = new lik_1.Objectmap();
|
||||
// export classes
|
||||
class SocketRequest {
|
||||
constructor(optionsArg) {
|
||||
this.status = "new";
|
||||
this.done = plugins.q.defer();
|
||||
this.side = optionsArg.side;
|
||||
this.shortid = optionsArg.shortId;
|
||||
this.funcCallData = optionsArg.funcCallData;
|
||||
this.originSocketConnection = optionsArg.originSocketConnection;
|
||||
exports.allSocketRequests.add(this);
|
||||
}
|
||||
;
|
||||
// requesting --------------------------
|
||||
/**
|
||||
* dispatches a socketrequest from the requesting to the receiving side
|
||||
*/
|
||||
dispatch() {
|
||||
let requestData = {
|
||||
funcCallData: this.funcCallData,
|
||||
shortId: this.shortid
|
||||
};
|
||||
this.originSocketConnection.socket.emit("function", requestData);
|
||||
return this.done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* handles the response that is received by the requesting side
|
||||
*/
|
||||
handleResponse(responseDataArg) {
|
||||
plugins.beautylog.log("handling response!");
|
||||
this.done.resolve(responseDataArg.funcCallData);
|
||||
exports.allSocketRequests.remove(this);
|
||||
}
|
||||
// responding --------------------------
|
||||
/**
|
||||
* creates the response on the responding side
|
||||
*/
|
||||
createResponse() {
|
||||
let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
|
||||
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
|
||||
targetSocketFunction.invoke(this.funcCallData)
|
||||
.then((resultData) => {
|
||||
plugins.beautylog.log("got resultData. Sending it to requesting party.");
|
||||
let requestData = {
|
||||
funcCallData: resultData,
|
||||
shortId: this.shortid
|
||||
};
|
||||
this.originSocketConnection.socket.emit("functionResponse", requestData);
|
||||
exports.allSocketRequests.remove(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.SocketRequest = SocketRequest;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFLakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQWdCL0IsQ0FBQztBQVNELENBQUM7QUFFRixnQkFBZ0I7QUFDTCx5QkFBaUIsR0FBRyxJQUFJLGVBQVMsRUFBaUIsQ0FBQztBQUU5RCxpQkFBaUI7QUFDakI7SUFPSSxZQUFZLFVBQTJDO1FBTnZELFdBQU0sR0FBeUIsS0FBSyxDQUFDO1FBS3JDLFNBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO1FBRXJCLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUM7UUFDbEMsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQzVDLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxVQUFVLENBQUMsc0JBQXNCLENBQUM7UUFDaEUseUJBQWlCLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2hDLENBQUM7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FBVyxHQUE2QjtnQkFDeEMsWUFBWSxFQUFFLFVBQVU7Z0JBQ3hCLE9BQU8sRUFBRSxJQUFJLENBQUMsT0FBTzthQUN4QixDQUFDO1lBQ0YsSUFBSSxDQUFDLHNCQUFzQixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsa0JBQWtCLEVBQUMsV0FBVyxDQUFDLENBQUM7WUFDeEUseUJBQWlCLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQ25DLENBQUMsQ0FBQyxDQUFDO0lBQ1gsQ0FBQztBQUNMLENBQUM7QUF6RFkscUJBQWEsZ0JBeUR6QixDQUFBO0FBQUEsQ0FBQyJ9
|
20
dist/smartsocket.classes.socketrole.d.ts
vendored
20
dist/smartsocket.classes.socketrole.d.ts
vendored
@ -1,20 +0,0 @@
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
export declare let allSocketRoles: Objectmap<SocketRole>;
|
||||
/**
|
||||
* interface for class SocketRole
|
||||
*/
|
||||
export interface SocketRoleOptions {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
}
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
export declare class SocketRole {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
allowedFunctions: Objectmap<SocketFunction>;
|
||||
constructor(optionsArg: SocketRoleOptions);
|
||||
addSocketFunction(socketFunctionArg: SocketFunction): void;
|
||||
}
|
21
dist/smartsocket.classes.socketrole.js
vendored
21
dist/smartsocket.classes.socketrole.js
vendored
@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
// import classes
|
||||
const lik_1 = require("lik");
|
||||
exports.allSocketRoles = new lik_1.Objectmap();
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
class SocketRole {
|
||||
constructor(optionsArg) {
|
||||
this.allowedFunctions = new lik_1.Objectmap();
|
||||
this.name = optionsArg.name;
|
||||
this.passwordHash = optionsArg.passwordHash;
|
||||
exports.allSocketRoles.add(this);
|
||||
}
|
||||
;
|
||||
addSocketFunction(socketFunctionArg) {
|
||||
this.allowedFunctions.add(socketFunctionArg);
|
||||
}
|
||||
}
|
||||
exports.SocketRole = SocketRole;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxpQkFBaUI7QUFDakIsc0JBQTBCLEtBQUssQ0FBQyxDQUFBO0FBSXJCLHNCQUFjLEdBQUcsSUFBSSxlQUFTLEVBQWMsQ0FBQztBQVd4RDs7R0FFRztBQUNIO0lBSUksWUFBWSxVQUE2QjtRQUR6QyxxQkFBZ0IsR0FBRyxJQUFJLGVBQVMsRUFBa0IsQ0FBQztRQUUvQyxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQzVDLHNCQUFjLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQzdCLENBQUM7O0lBQ0QsaUJBQWlCLENBQUMsaUJBQWdDO1FBQzlDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxHQUFHLENBQUMsaUJBQWlCLENBQUMsQ0FBQztJQUNqRCxDQUFDO0FBQ0wsQ0FBQztBQVpZLGtCQUFVLGFBWXRCLENBQUEifQ==
|
14
dist/smartsocket.helpers.d.ts
vendored
14
dist/smartsocket.helpers.d.ts
vendored
@ -1,14 +0,0 @@
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
import { ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketRequest, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
export declare let checkPasswordForRole: (dataArg: ISocketConnectionAuthenticationObject) => boolean;
|
||||
export declare let getSocketFunctionByName: (functionNameArg: string) => SocketFunction;
|
||||
/**
|
||||
* get corresponding Socketrequest instance by shortId
|
||||
*/
|
||||
export declare let getSocketRequestById: (shortIdArg: string, requestSide?: TSocketRequestSide) => SocketRequest;
|
||||
/**
|
||||
* get corresponding SocketRole instance by name
|
||||
*/
|
||||
export declare let getSocketRoleByName: (socketRoleNameArg: string) => SocketRole;
|
30
dist/smartsocket.helpers.js
vendored
30
dist/smartsocket.helpers.js
vendored
@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
const smartsocket_classes_socketfunction_1 = require("./smartsocket.classes.socketfunction");
|
||||
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
|
||||
const smartsocket_classes_socketrole_1 = require("./smartsocket.classes.socketrole");
|
||||
// SocketConnection helpers
|
||||
exports.checkPasswordForRole = (dataArg) => {
|
||||
let targetPasswordHash = exports.getSocketRoleByName(dataArg.role).passwordHash;
|
||||
let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password);
|
||||
return targetPasswordHash === computedCompareHash;
|
||||
};
|
||||
// SocketFunction helpers
|
||||
exports.getSocketFunctionByName = (functionNameArg) => {
|
||||
return smartsocket_classes_socketfunction_1.allSocketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg; });
|
||||
};
|
||||
// SocketRequest helpers
|
||||
/**
|
||||
* get corresponding Socketrequest instance by shortId
|
||||
*/
|
||||
exports.getSocketRequestById = (shortIdArg, requestSide) => {
|
||||
return smartsocket_classes_socketrequest_1.allSocketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg; });
|
||||
};
|
||||
// SocketRole helpers
|
||||
/**
|
||||
* get corresponding SocketRole instance by name
|
||||
*/
|
||||
exports.getSocketRoleByName = (socketRoleNameArg) => {
|
||||
return smartsocket_classes_socketrole_1.allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg; });
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFJakQscURBQW1ELHNDQUFzQyxDQUFDLENBQUE7QUFFMUYsb0RBQXFFLHFDQUFxQyxDQUFDLENBQUE7QUFDM0csaURBQTJDLGtDQUFrQyxDQUFDLENBQUE7QUFFOUUsMkJBQTJCO0FBQ2hCLDRCQUFvQixHQUFHLENBQUMsT0FBOEM7SUFDN0UsSUFBSSxrQkFBa0IsR0FBRywyQkFBbUIsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsWUFBWSxDQUFDO0lBQ3hFLElBQUksbUJBQW1CLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxvQkFBb0IsQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDbEYsTUFBTSxDQUFDLGtCQUFrQixLQUFLLG1CQUFtQixDQUFDO0FBQ3RELENBQUMsQ0FBQTtBQUdELHlCQUF5QjtBQUNkLCtCQUF1QixHQUFHLENBQUMsZUFBdUI7SUFDekQsTUFBTSxDQUFDLHVEQUFrQixDQUFDLElBQUksQ0FBQyxDQUFDLGlCQUFpQixPQUFPLE1BQU0sQ0FBQyxpQkFBaUIsQ0FBQyxJQUFJLEtBQUssZUFBZSxDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDakgsQ0FBQyxDQUFBO0FBRUQsd0JBQXdCO0FBRXhCOztHQUVHO0FBQ1EsNEJBQW9CLEdBQUcsQ0FBQyxVQUFrQixFQUFFLFdBQWdDO0lBQ25GLE1BQU0sQ0FBQyxxREFBaUIsQ0FBQyxJQUFJLENBQUMsQ0FBQyxnQkFBZ0IsT0FBTyxNQUFNLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxLQUFLLFVBQVUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0FBQzNHLENBQUMsQ0FBQTtBQUVELHFCQUFxQjtBQUVyQjs7R0FFRztBQUNRLDJCQUFtQixHQUFHLENBQUMsaUJBQXlCO0lBQ3ZELE1BQU0sQ0FBQywrQ0FBYyxDQUFDLElBQUksQ0FBQyxDQUFDLGFBQWEsT0FBTyxNQUFNLENBQUMsYUFBYSxDQUFDLElBQUksS0FBSyxpQkFBaUIsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0FBQ3RHLENBQUMsQ0FBQyJ9
|
9
dist/smartsocket.plugins.d.ts
vendored
9
dist/smartsocket.plugins.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import nodehash = require("nodehash");
|
||||
export import q = require("q");
|
||||
export import shortid = require("shortid");
|
||||
export import socketIo = require("socket.io");
|
||||
export import socketIoClient = require("socket.io-client");
|
||||
export import taskbuffer = require("taskbuffer");
|
11
dist/smartsocket.plugins.js
vendored
11
dist/smartsocket.plugins.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.lik = require("lik");
|
||||
exports.nodehash = require("nodehash");
|
||||
exports.q = require("q");
|
||||
exports.shortid = require("shortid");
|
||||
exports.socketIo = require("socket.io");
|
||||
exports.socketIoClient = require("socket.io-client");
|
||||
exports.taskbuffer = require("taskbuffer");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsV0FBRyxXQUFZLEtBQUssQ0FBQyxDQUFDO0FBQ3RCLGdCQUFRLFdBQVcsVUFBVSxDQUFDLENBQUM7QUFDL0IsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sV0FBVyxTQUFTLENBQUMsQ0FBQztBQUM3QixnQkFBUSxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2hDLHNCQUFjLFdBQVcsa0JBQWtCLENBQUMsQ0FBQztBQUM3QyxrQkFBVSxXQUFXLFlBQVksQ0FBQyxDQUFDIn0=
|
@ -1,5 +1,17 @@
|
||||
{
|
||||
"npmts":{
|
||||
"coverageTreshold":50
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartsocket",
|
||||
"shortDescription": "easy and secure websocket communication",
|
||||
"npmPackagename": "@pushrocks/smartsocket",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
3290
package-lock.json
generated
Normal file
3290
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
57
package.json
57
package.json
@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "smartsocket",
|
||||
"version": "1.1.3",
|
||||
"description": "easy and secure websocket communication, Typescript ready",
|
||||
"name": "@pushrocks/smartsocket",
|
||||
"version": "1.1.43",
|
||||
"description": "easy and secure websocket communication",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -18,22 +19,38 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartsocket#README",
|
||||
"dependencies": {
|
||||
"@types/q": "0.x.x",
|
||||
"@types/shortid": "0.0.27",
|
||||
"@types/socket.io": "^1.4.26",
|
||||
"@types/socket.io-client": "^1.4.26",
|
||||
"beautylog": "^5.0.23",
|
||||
"lik": "^1.0.15",
|
||||
"nodehash": "^1.0.4",
|
||||
"q": "^1.4.1",
|
||||
"shortid": "^2.2.6",
|
||||
"socket.io": "^1.4.8",
|
||||
"socket.io-client": "^1.4.8",
|
||||
"taskbuffer": "^1.0.8"
|
||||
"@pushrocks/lik": "^3.0.10",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartexpress": "^3.0.38",
|
||||
"@pushrocks/smarthash": "^2.0.6",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@types/shortid": "0.0.29",
|
||||
"@types/socket.io": "^2.1.2",
|
||||
"@types/socket.io-client": "^1.4.32",
|
||||
"shortid": "^2.2.14",
|
||||
"socket.io": "^2.2.0",
|
||||
"socket.io-client": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.8",
|
||||
"should": "^11.1.0",
|
||||
"typings-test": "^1.0.2"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.11",
|
||||
"@types/node": "^12.7.1",
|
||||
"tslint": "^5.18.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
1
test/common/test.ts
Normal file
1
test/common/test.ts
Normal file
@ -0,0 +1 @@
|
||||
console.log('TODO');
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
104
test/test.expressserver.ts
Normal file
104
test/test.expressserver.ts
Normal file
@ -0,0 +1,104 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
|
||||
import socketIoClient = require('socket.io-client');
|
||||
import smartsocket = require('../ts/index');
|
||||
|
||||
let testSmartsocket: smartsocket.Smartsocket;
|
||||
let testSmartsocketClient: smartsocket.SmartsocketClient;
|
||||
let testSocketRole1: smartsocket.SocketRole;
|
||||
let testSocketFunction1: smartsocket.SocketFunction;
|
||||
let myseServer: smartexpress.Server;
|
||||
|
||||
const testConfig = {
|
||||
port: 3000
|
||||
};
|
||||
|
||||
// class smartsocket
|
||||
tap.test('should create a new smartsocket', async () => {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
|
||||
expect(testSmartsocket).be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
|
||||
tap.test('Should accept an smartExpressServer as server', async () => {
|
||||
myseServer = new smartexpress.Server({
|
||||
cors: true,
|
||||
forceSsl: false,
|
||||
port: testConfig.port
|
||||
});
|
||||
|
||||
testSmartsocket.setExternalServer('smartexpress', myseServer);
|
||||
|
||||
await myseServer.start();
|
||||
});
|
||||
|
||||
// class socketrole
|
||||
tap.test('should add a socketrole', async () => {
|
||||
testSocketRole1 = new smartsocket.SocketRole({
|
||||
name: 'testRole1',
|
||||
passwordHash: smarthash.sha256FromStringSync('testPassword')
|
||||
});
|
||||
testSmartsocket.addSocketRoles([testSocketRole1]);
|
||||
});
|
||||
|
||||
// class SocketFunction
|
||||
tap.test('should register a new Function', async () => {
|
||||
testSocketFunction1 = new smartsocket.SocketFunction({
|
||||
allowedRoles: [testSocketRole1],
|
||||
funcDef: async (dataArg, socketConnectionArg) => {
|
||||
return dataArg;
|
||||
},
|
||||
funcName: 'testFunction1'
|
||||
});
|
||||
testSmartsocket.addSocketFunction(testSocketFunction1);
|
||||
console.log(testSmartsocket.socketFunctions);
|
||||
});
|
||||
|
||||
tap.test('should start listening when .started is called', async () => {
|
||||
await testSmartsocket.start();
|
||||
});
|
||||
|
||||
// class SmartsocketClient
|
||||
tap.test('should react to a new websocket connection from client', async () => {
|
||||
testSmartsocketClient = new smartsocket.SmartsocketClient({
|
||||
port: testConfig.port,
|
||||
url: 'http://localhost',
|
||||
password: 'testPassword',
|
||||
alias: 'testClient1',
|
||||
role: 'testRole1'
|
||||
});
|
||||
testSmartsocketClient.addSocketFunction(testSocketFunction1);
|
||||
console.log(testSmartsocketClient.socketFunctions);
|
||||
await testSmartsocketClient.connect();
|
||||
});
|
||||
|
||||
tap.test('client should disconnect and reconnect', async tools => {
|
||||
await testSmartsocketClient.disconnect();
|
||||
await tools.delayFor(100);
|
||||
await testSmartsocketClient.connect();
|
||||
});
|
||||
|
||||
tap.test('2 clients should connect in parallel', async () => {
|
||||
// TODO: implement parallel test
|
||||
});
|
||||
|
||||
tap.test('should be able to make a functionCall from client to server', async () => {
|
||||
const response = await testSmartsocketClient.serverCall('testFunction1', {
|
||||
value1: 'hello'
|
||||
});
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
tap.test('should be able to make a functionCall from server to client', async () => {});
|
||||
|
||||
// terminate
|
||||
tap.test('should close the server', async () => {
|
||||
await testSmartsocket.stop();
|
||||
await myseServer.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
105
test/test.js
105
test/test.js
@ -1,105 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
require("should");
|
||||
const smartsocket = require("../dist/index");
|
||||
const q = require("q");
|
||||
const nodehash = require("nodehash");
|
||||
let testSmartsocket;
|
||||
let testSmartsocketClient;
|
||||
let testSocketRole1;
|
||||
let testSocketFunction1;
|
||||
let testConfig = {
|
||||
port: 3000
|
||||
};
|
||||
describe("smartsocket", function () {
|
||||
describe("class Smartsocket", function () {
|
||||
it("should create a new smartsocket", function () {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
|
||||
testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
it("should start listening when .started is called", function () {
|
||||
testSmartsocket.startServer();
|
||||
});
|
||||
});
|
||||
describe("class SocketRole", function () {
|
||||
testSocketRole1 = new smartsocket.SocketRole({
|
||||
name: "testRole1",
|
||||
passwordHash: nodehash.sha256FromStringSync("testPassword")
|
||||
});
|
||||
});
|
||||
describe("class SocketFunction", function () {
|
||||
it("should register a new Function", function () {
|
||||
testSocketFunction1 = new smartsocket.SocketFunction({
|
||||
funcName: "testFunction1",
|
||||
funcDef: (dataArg) => {
|
||||
let done = q.defer();
|
||||
done.resolve(dataArg);
|
||||
return done.promise;
|
||||
},
|
||||
allowedRoles: [testSocketRole1]
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("class SmartsocketClient", function () {
|
||||
it("should react to a new websocket connection from client", function (done) {
|
||||
this.timeout(10000);
|
||||
testSmartsocketClient = new smartsocket.SmartsocketClient({
|
||||
port: testConfig.port,
|
||||
url: "http://localhost",
|
||||
password: "testPassword",
|
||||
alias: "testClient1",
|
||||
role: "testRole1"
|
||||
});
|
||||
testSmartsocketClient.connect()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("client should disconnect and reconnect", function (done) {
|
||||
this.timeout(10000);
|
||||
testSmartsocketClient.disconnect()
|
||||
.then(() => {
|
||||
let done = q.defer();
|
||||
setTimeout(() => {
|
||||
testSmartsocketClient.connect()
|
||||
.then(done.resolve);
|
||||
}, 0);
|
||||
return done.promise;
|
||||
})
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("2 clients should connect in parallel", function () {
|
||||
});
|
||||
it("should be able to make a functionCall from client to server", function (done) {
|
||||
this.timeout(5000);
|
||||
testSmartsocketClient.serverCall("testFunction1", {
|
||||
value1: "hello"
|
||||
}).then((dataArg) => {
|
||||
console.log(dataArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should be able to make a functionCall from server to client", function (done) {
|
||||
this.timeout(5000);
|
||||
let targetSocket = (() => {
|
||||
return smartsocket.allSocketConnections.find((socketConnectionArg) => {
|
||||
return socketConnectionArg.alias === "testClient1";
|
||||
});
|
||||
})();
|
||||
testSmartsocket.clientCall("testFunction1", {
|
||||
value1: "helloFromServer"
|
||||
}, targetSocket).then((dataArg) => {
|
||||
console.log(dataArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("terminating smartsocket", function () {
|
||||
it("should close the server", function () {
|
||||
testSmartsocket.closeServer();
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFdBQVcsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUM5QyxNQUFPLENBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUN4QixNQUFPLFFBQVEsV0FBVyxVQUFVLENBQUMsQ0FBQztBQUV0QyxJQUFJLG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0FBQyxtQkFBbUIsQ0FBQyxLQUFLLEtBQUssYUFBYSxDQUFDO2dCQUN2RCxDQUFDLENBQUMsQ0FBQztZQUNQLENBQUMsQ0FBQyxFQUFFLENBQUM7WUFDTCxlQUFlLENBQUMsVUFBVSxDQUFDLGVBQWUsRUFBQztnQkFDdkMsTUFBTSxFQUFDLGlCQUFpQjthQUMzQixFQUFDLFlBQVksQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLE9BQU87Z0JBQ3pCLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7Z0JBQ3JCLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDUCxDQUFDLENBQUMsQ0FBQztJQUVQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLHlCQUF5QixFQUFFO1FBQ2hDLEVBQUUsQ0FBQyx5QkFBeUIsRUFBRTtZQUMxQixlQUFlLENBQUMsV0FBVyxFQUFFLENBQUM7UUFDbEMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0=
|
197
test/test.ts
197
test/test.ts
@ -1,109 +1,104 @@
|
||||
import "typings-test";
|
||||
import "should";
|
||||
import socketIoClient = require("socket.io-client");
|
||||
import smartsocket = require("../dist/index");
|
||||
import q = require("q");
|
||||
import nodehash = require("nodehash");
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
import socketIoClient = require('socket.io-client');
|
||||
import smartsocket = require('../ts/index');
|
||||
|
||||
let testSmartsocket: smartsocket.Smartsocket;
|
||||
let testSmartsocketClient: smartsocket.SmartsocketClient;
|
||||
let testSocketRole1: smartsocket.SocketRole;
|
||||
let testSocketFunction1:smartsocket.SocketFunction;
|
||||
let testSocketFunctionServer: smartsocket.SocketFunction;
|
||||
let testSocketFunctionClient: smartsocket.SocketFunction;
|
||||
|
||||
let testConfig = {
|
||||
port: 3000
|
||||
}
|
||||
const testConfig = {
|
||||
port: 3000
|
||||
};
|
||||
|
||||
describe("smartsocket", function () {
|
||||
describe("class Smartsocket", function () {
|
||||
it("should create a new smartsocket", function () {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
|
||||
testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
it("should start listening when .started is called", function () {
|
||||
testSmartsocket.startServer();
|
||||
});
|
||||
});
|
||||
describe("class SocketRole", function(){
|
||||
testSocketRole1 = new smartsocket.SocketRole({
|
||||
name:"testRole1",
|
||||
passwordHash:nodehash.sha256FromStringSync("testPassword")
|
||||
})
|
||||
})
|
||||
describe("class SocketFunction", function () {
|
||||
it("should register a new Function", function () {
|
||||
testSocketFunction1 = new smartsocket.SocketFunction({
|
||||
funcName:"testFunction1",
|
||||
funcDef: (dataArg) => {
|
||||
let done = q.defer();
|
||||
done.resolve(dataArg);
|
||||
return done.promise;
|
||||
},
|
||||
allowedRoles:[testSocketRole1]
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("class SmartsocketClient", function () {
|
||||
it("should react to a new websocket connection from client", function (done) {
|
||||
this.timeout(10000);
|
||||
testSmartsocketClient = new smartsocket.SmartsocketClient({
|
||||
port: testConfig.port,
|
||||
url: "http://localhost",
|
||||
password: "testPassword",
|
||||
alias: "testClient1",
|
||||
role: "testRole1"
|
||||
});
|
||||
testSmartsocketClient.connect()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("client should disconnect and reconnect", function (done) {
|
||||
this.timeout(10000);
|
||||
testSmartsocketClient.disconnect()
|
||||
.then(() => {
|
||||
let done = q.defer();
|
||||
setTimeout(() => {
|
||||
testSmartsocketClient.connect()
|
||||
.then(done.resolve)
|
||||
}, 0)
|
||||
return done.promise;
|
||||
})
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("2 clients should connect in parallel", function () {
|
||||
// class smartsocket
|
||||
tap.test('should create a new smartsocket', async () => {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
|
||||
expect(testSmartsocket).be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
|
||||
});
|
||||
it("should be able to make a functionCall from client to server",function(done){
|
||||
this.timeout(5000);
|
||||
testSmartsocketClient.serverCall("testFunction1",{
|
||||
value1:"hello"
|
||||
}).then((dataArg) => {
|
||||
console.log(dataArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should be able to make a functionCall from server to client",function(done){
|
||||
this.timeout(5000);
|
||||
let targetSocket = (() => {
|
||||
return smartsocket.allSocketConnections.find((socketConnectionArg)=>{
|
||||
return socketConnectionArg.alias === "testClient1";
|
||||
});
|
||||
})();
|
||||
testSmartsocket.clientCall("testFunction1",{
|
||||
value1:"helloFromServer"
|
||||
},targetSocket).then((dataArg) => {
|
||||
console.log(dataArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
// class socketrole
|
||||
tap.test('should add a socketrole', async () => {
|
||||
testSocketRole1 = new smartsocket.SocketRole({
|
||||
name: 'testRole1',
|
||||
passwordHash: smarthash.sha256FromStringSync('testPassword')
|
||||
});
|
||||
testSmartsocket.addSocketRoles([testSocketRole1]);
|
||||
});
|
||||
|
||||
});
|
||||
describe("terminating smartsocket", function () {
|
||||
it("should close the server", function () {
|
||||
testSmartsocket.closeServer();
|
||||
});
|
||||
})
|
||||
});
|
||||
// class SocketFunction
|
||||
tap.test('should register a new Function', async () => {
|
||||
testSocketFunctionServer = new smartsocket.SocketFunction({
|
||||
allowedRoles: [testSocketRole1],
|
||||
funcDef: async (dataArg, socketConnectionArg) => {
|
||||
return dataArg;
|
||||
},
|
||||
funcName: 'testFunction1'
|
||||
});
|
||||
testSmartsocket.addSocketFunction(testSocketFunctionServer);
|
||||
|
||||
testSocketFunctionClient = new smartsocket.SocketFunction({
|
||||
allowedRoles: [],
|
||||
funcDef: async (dataArg, socketConnectionArg) => {
|
||||
return dataArg;
|
||||
},
|
||||
funcName: 'testFunction1'
|
||||
});
|
||||
testSmartsocket.addSocketFunction(testSocketFunctionServer);
|
||||
console.log(testSmartsocket.socketFunctions);
|
||||
});
|
||||
|
||||
tap.test('should start listening when .started is called', async () => {
|
||||
await testSmartsocket.start();
|
||||
});
|
||||
|
||||
// class SmartsocketClient
|
||||
tap.test('should react to a new websocket connection from client', async () => {
|
||||
testSmartsocketClient = new smartsocket.SmartsocketClient({
|
||||
port: testConfig.port,
|
||||
url: 'http://localhost',
|
||||
password: 'testPassword',
|
||||
alias: 'testClient1',
|
||||
role: 'testRole1'
|
||||
});
|
||||
testSmartsocketClient.addSocketFunction(testSocketFunctionClient);
|
||||
console.log(testSmartsocketClient.socketFunctions);
|
||||
await testSmartsocketClient.connect();
|
||||
});
|
||||
|
||||
tap.test('client should disconnect and reconnect', async tools => {
|
||||
await testSmartsocketClient.disconnect();
|
||||
await tools.delayFor(100);
|
||||
await testSmartsocketClient.connect();
|
||||
});
|
||||
|
||||
tap.test('2 clients should connect in parallel', async () => {
|
||||
// TODO: implement parallel test
|
||||
});
|
||||
|
||||
tap.test('should be able to make a functionCall from client to server', async () => {
|
||||
const response = await testSmartsocketClient.serverCall('testFunction1', {
|
||||
value1: 'hello'
|
||||
});
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
tap.test('should be able to make a functionCall from server to client', async () => {
|
||||
const response = await testSmartsocketClient.serverCall('testFunction1', {
|
||||
hi: 'hi there from client'
|
||||
});
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// terminate
|
||||
tap.test('should close the server', async () => {
|
||||
await testSmartsocket.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
15
ts/index.ts
15
ts/index.ts
@ -1,13 +1,10 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// export main classes
|
||||
export * from "./smartsocket.classes.smartsocket";
|
||||
export * from "./smartsocket.classes.smartsocketclient";
|
||||
export * from './smartsocket.classes.smartsocket';
|
||||
export * from './smartsocket.classes.smartsocketclient';
|
||||
|
||||
// export further classes and objects
|
||||
export * from "./smartsocket.classes.socketfunction";
|
||||
export * from "./smartsocket.classes.socketrole";
|
||||
export * from "./smartsocket.classes.socketconnection";
|
||||
export {allSocketConnections} from "./smartsocket.classes.socketconnection";
|
||||
|
||||
// need something more exposed? Create an issue on GitLab!
|
||||
export * from './smartsocket.classes.socketfunction';
|
||||
export * from './smartsocket.classes.socketrole';
|
||||
export * from './smartsocket.classes.socketconnection';
|
||||
|
@ -1,86 +1,131 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as helpers from "./smartsocket.helpers";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// classes
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketFunction,ISocketFunctionCall} from "./smartsocket.classes.socketfunction";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketRequest } from "./smartsocket.classes.socketrequest";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||
import { ISocketFunctionCall, SocketFunction } from './smartsocket.classes.socketfunction';
|
||||
import { SocketRequest } from './smartsocket.classes.socketrequest';
|
||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||
import { SocketServer } from './smartsocket.classes.socketserver';
|
||||
|
||||
// socket.io
|
||||
import * as SocketIO from 'socket.io';
|
||||
|
||||
export interface ISmartsocketConstructorOptions {
|
||||
port: number;
|
||||
};
|
||||
port?: number;
|
||||
}
|
||||
|
||||
export class Smartsocket {
|
||||
options: ISmartsocketConstructorOptions
|
||||
io: SocketIO.Server;
|
||||
openSockets = new Objectmap<SocketConnection>();
|
||||
constructor(optionsArg: ISmartsocketConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
};
|
||||
public options: ISmartsocketConstructorOptions;
|
||||
public io: SocketIO.Server;
|
||||
public openSockets = new Objectmap<SocketConnection>();
|
||||
public socketRoles = new Objectmap<SocketRole>();
|
||||
public socketFunctions = new Objectmap<SocketFunction>();
|
||||
public socketRequests = new Objectmap<SocketRequest>();
|
||||
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocketConnection(socketArg) {
|
||||
let socketConnection: SocketConnection = new SocketConnection({
|
||||
alias:undefined,
|
||||
authenticated:false,
|
||||
role:undefined,
|
||||
side:"server",
|
||||
socket:socketArg
|
||||
});
|
||||
plugins.beautylog.log("Socket connected. Trying to authenticate...")
|
||||
this.openSockets.add(socketConnection);
|
||||
socketConnection.authenticate()
|
||||
.then(() => {
|
||||
return socketConnection.listenToFunctionRequests();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
private socketServer = new SocketServer(this);
|
||||
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
constructor(optionsArg: ISmartsocketConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
startServer = () => {
|
||||
this.io = plugins.socketIo(this.options.port);
|
||||
this.io.on("connection", (socketArg) => {
|
||||
this._handleSocketConnection(socketArg);
|
||||
});
|
||||
// tslint:disable-next-line:member-ordering
|
||||
public async setExternalServer(serverType: 'smartexpress', serverArg: any) {
|
||||
await this.socketServer.setExternalServer(serverType, serverArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* starts smartsocket
|
||||
*/
|
||||
public async start() {
|
||||
this.io = plugins.socketIo(this.socketServer.getServerForSocketIo());
|
||||
await this.socketServer.start();
|
||||
this.io.on('connection', socketArg => {
|
||||
this._handleSocketConnection(socketArg);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* stops smartsocket
|
||||
*/
|
||||
public async stop() {
|
||||
await plugins.smartdelay.delayFor(1000);
|
||||
this.openSockets.forEach((socketObjectArg: SocketConnection) => {
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`disconnect socket with >>alias ${socketObjectArg.alias}`
|
||||
);
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
|
||||
// stop the corresponging server
|
||||
this.socketServer.stop();
|
||||
}
|
||||
|
||||
// communication
|
||||
|
||||
/**
|
||||
* allows call to specific client.
|
||||
*/
|
||||
public async clientCall(
|
||||
functionNameArg: string,
|
||||
dataArg: any,
|
||||
targetSocketConnectionArg: SocketConnection
|
||||
) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const socketRequest = new SocketRequest(this, {
|
||||
funcCallData: {
|
||||
funcDataArg: dataArg,
|
||||
funcName: functionNameArg
|
||||
},
|
||||
originSocketConnection: targetSocketConnectionArg,
|
||||
shortId: plugins.shortid.generate(),
|
||||
side: 'requesting'
|
||||
});
|
||||
socketRequest.dispatch().then((dataArg2: ISocketFunctionCall) => {
|
||||
done.resolve(dataArg2.funcDataArg);
|
||||
});
|
||||
const result = await done.promise;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds socketRoles
|
||||
*/
|
||||
public addSocketRoles(socketRolesArray: SocketRole[]): void {
|
||||
for (const socketRole of socketRolesArray) {
|
||||
this.socketRoles.add(socketRole);
|
||||
}
|
||||
closeServer = () => {
|
||||
this.openSockets.forEach((socketObjectArg: SocketConnection) => {
|
||||
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
// communication
|
||||
public addSocketFunction(socketFunction: SocketFunction) {
|
||||
this.socketFunctions.add(socketFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* allows call to specific client.
|
||||
*/
|
||||
clientCall(functionNameArg:string,dataArg:any,targetSocketConnectionArg:SocketConnection){
|
||||
let done = plugins.q.defer();
|
||||
let socketRequest = new SocketRequest({
|
||||
side:"requesting",
|
||||
originSocketConnection:targetSocketConnectionArg,
|
||||
shortId:plugins.shortid.generate(),
|
||||
funcCallData:{
|
||||
funcName: functionNameArg,
|
||||
funcDataArg:dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch()
|
||||
.then((dataArg:ISocketFunctionCall) => {
|
||||
done.resolve(dataArg.funcDataArg);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocketConnection(socketArg) {
|
||||
const socketConnection: SocketConnection = new SocketConnection({
|
||||
alias: undefined,
|
||||
authenticated: false,
|
||||
role: undefined,
|
||||
side: 'server',
|
||||
smartsocketHost: this,
|
||||
socket: socketArg
|
||||
});
|
||||
plugins.smartlog.defaultLogger.log('info', 'Socket connected. Trying to authenticate...');
|
||||
this.openSockets.add(socketConnection);
|
||||
socketConnection
|
||||
.authenticate()
|
||||
.then(() => {
|
||||
return socketConnection.listenToFunctionRequests();
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +1,100 @@
|
||||
import * as plugins from "./smartsocket.plugins"
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||
import { ISocketFunctionCall, SocketFunction } from './smartsocket.classes.socketfunction';
|
||||
import { ISocketRequestDataObject, SocketRequest } from './smartsocket.classes.socketrequest';
|
||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||
|
||||
// import interfaces
|
||||
import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
|
||||
import { ISocketRequestDataObject } from "./smartsocket.classes.socketrequest"
|
||||
|
||||
// import classes
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketRequest } from "./smartsocket.classes.socketrequest";
|
||||
/**
|
||||
* interface for class SmartsocketClient
|
||||
*/
|
||||
export interface ISmartsocketClientOptions {
|
||||
port: number;
|
||||
url: string;
|
||||
alias:string; // an alias makes it easier to identify this client in a multo client environment
|
||||
role:string;
|
||||
password: string; // by setting a password access to functions can be limited
|
||||
port: number;
|
||||
url: string;
|
||||
alias: string; // an alias makes it easier to identify this client in a multo client environment
|
||||
role: string;
|
||||
password: string; // by setting a password access to functions can be limited
|
||||
}
|
||||
|
||||
export class SmartsocketClient {
|
||||
alias:string;
|
||||
role:string;
|
||||
socketConnection:SocketConnection;
|
||||
serverUrl:string;
|
||||
serverPort:number;
|
||||
serverPassword:string;
|
||||
constructor(optionsArg:ISmartsocketClientOptions){
|
||||
this.alias = optionsArg.alias;
|
||||
this.role = optionsArg.role;
|
||||
this.serverUrl = optionsArg.url
|
||||
this.serverPort = optionsArg.port;
|
||||
this.serverPassword = optionsArg.password
|
||||
};
|
||||
public alias: string;
|
||||
public role: string;
|
||||
public socketConnection: SocketConnection;
|
||||
public serverUrl: string;
|
||||
public serverPort: number;
|
||||
public serverPassword: string;
|
||||
|
||||
/**
|
||||
* connect the client to the server
|
||||
*/
|
||||
connect(){
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.log("trying to connect...");
|
||||
let socketUrl = `${this.serverUrl}:${this.serverPort}`;
|
||||
this.socketConnection = new SocketConnection({
|
||||
alias:this.alias,
|
||||
authenticated:false,
|
||||
role:undefined,
|
||||
side:"client",
|
||||
socket: plugins.socketIoClient(socketUrl,{multiplex:false})
|
||||
});
|
||||
this.socketConnection.socket.on("requestAuth", () => {
|
||||
console.log("server requested authentication");
|
||||
this.socketConnection.socket.emit("dataAuth", {
|
||||
role: this.role,
|
||||
password: this.serverPassword,
|
||||
alias: this.alias
|
||||
});
|
||||
this.socketConnection.socket.on("authenticated",() => {
|
||||
console.log("client is authenticated");
|
||||
this.socketConnection.authenticated = true;
|
||||
this.socketConnection.listenToFunctionRequests();
|
||||
done.resolve();
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
disconnect(){
|
||||
let done = plugins.q.defer();
|
||||
this.socketConnection.socket.disconnect();
|
||||
this.socketConnection = undefined;
|
||||
plugins.beautylog.ok("disconnected!");
|
||||
public socketFunctions = new plugins.lik.Objectmap<SocketFunction>();
|
||||
public socketRequests = new plugins.lik.Objectmap<SocketRequest>();
|
||||
public socketRoles = new plugins.lik.Objectmap<SocketRole>();
|
||||
|
||||
constructor(optionsArg: ISmartsocketClientOptions) {
|
||||
this.alias = optionsArg.alias;
|
||||
this.role = optionsArg.role;
|
||||
this.serverUrl = optionsArg.url;
|
||||
this.serverPort = optionsArg.port;
|
||||
this.serverPassword = optionsArg.password;
|
||||
}
|
||||
|
||||
public addSocketFunction(socketFunction: SocketFunction) {
|
||||
this.socketFunctions.add(socketFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* connect the client to the server
|
||||
*/
|
||||
public connect() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
plugins.smartlog.defaultLogger.log('info', 'trying to connect...');
|
||||
const socketUrl = `${this.serverUrl}:${this.serverPort}`;
|
||||
this.socketConnection = new SocketConnection({
|
||||
alias: this.alias,
|
||||
authenticated: false,
|
||||
role: undefined,
|
||||
side: 'client',
|
||||
smartsocketHost: this,
|
||||
socket: plugins.socketIoClient(socketUrl, { multiplex: false })
|
||||
});
|
||||
this.socketConnection.socket.on('requestAuth', () => {
|
||||
console.log('server requested authentication');
|
||||
this.socketConnection.socket.emit('dataAuth', {
|
||||
role: this.role,
|
||||
password: this.serverPassword,
|
||||
alias: this.alias
|
||||
});
|
||||
this.socketConnection.socket.on('authenticated', () => {
|
||||
console.log('client is authenticated');
|
||||
this.socketConnection.authenticated = true;
|
||||
this.socketConnection.listenToFunctionRequests();
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
serverCall(functionNameArg:string,dataArg:any){
|
||||
let done = plugins.q.defer();
|
||||
let socketRequest = new SocketRequest({
|
||||
side:"requesting",
|
||||
originSocketConnection:this.socketConnection,
|
||||
shortId:plugins.shortid.generate(),
|
||||
funcCallData:{
|
||||
funcName: functionNameArg,
|
||||
funcDataArg:dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch()
|
||||
.then((dataArg:ISocketFunctionCall) => {
|
||||
done.resolve(dataArg.funcDataArg);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
public disconnect() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
this.socketConnection.socket.disconnect();
|
||||
this.socketConnection = undefined;
|
||||
plugins.smartlog.defaultLogger.log('ok', 'disconnected!');
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
public serverCall(functionNameArg: string, dataArg: any) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const socketRequest = new SocketRequest(this, {
|
||||
side: 'requesting',
|
||||
originSocketConnection: this.socketConnection,
|
||||
shortId: plugins.shortid.generate(),
|
||||
funcCallData: {
|
||||
funcName: functionNameArg,
|
||||
funcDataArg: dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch().then((dataArg2: ISocketFunctionCall) => {
|
||||
done.resolve(dataArg2.funcDataArg);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,44 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as helpers from "./smartsocket.helpers";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
import {Objectmap} from "lik";
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
|
||||
// import classes
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketRequest, ISocketRequestDataObject, allSocketRequests } from "./smartsocket.classes.socketrequest";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
import { SocketFunction } from './smartsocket.classes.socketfunction';
|
||||
import { SocketRequest, ISocketRequestDataObject } from './smartsocket.classes.socketrequest';
|
||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||
|
||||
// socket.io
|
||||
import * as SocketIO from 'socket.io';
|
||||
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
|
||||
|
||||
// export interfaces
|
||||
|
||||
/**
|
||||
* defines is a SocketConnection is server or client side. Important for mesh setups.
|
||||
*/
|
||||
export type TSocketConnectionSide = "server" | "client";
|
||||
export type TSocketConnectionSide = 'server' | 'client';
|
||||
|
||||
/**
|
||||
* interface for constructor of class SocketConnection
|
||||
*/
|
||||
export interface ISocketConnectionConstructorOptions {
|
||||
alias: string;
|
||||
authenticated: boolean;
|
||||
role: SocketRole;
|
||||
side: TSocketConnectionSide;
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
};
|
||||
alias: string;
|
||||
authenticated: boolean;
|
||||
role: SocketRole;
|
||||
side: TSocketConnectionSide;
|
||||
smartsocketHost: Smartsocket | SmartsocketClient;
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* interface for authentication data
|
||||
*/
|
||||
export interface ISocketConnectionAuthenticationObject {
|
||||
role: "coreflowContainer",
|
||||
password: "somePassword",
|
||||
alias: "coreflow1"
|
||||
};
|
||||
role: 'coreflowContainer';
|
||||
password: 'somePassword';
|
||||
alias: 'coreflow1';
|
||||
}
|
||||
|
||||
// export classes
|
||||
export let allSocketConnections = new Objectmap<SocketConnection>();
|
||||
@ -42,95 +47,121 @@ export let allSocketConnections = new Objectmap<SocketConnection>();
|
||||
* class SocketConnection represents a websocket connection
|
||||
*/
|
||||
export class SocketConnection {
|
||||
alias: string;
|
||||
side:TSocketConnectionSide;
|
||||
authenticated: boolean = false;
|
||||
role: SocketRole;
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
constructor(optionsArg: ISocketConnectionConstructorOptions) {
|
||||
this.alias = optionsArg.alias;
|
||||
this.authenticated = optionsArg.authenticated;
|
||||
this.role = optionsArg.role;
|
||||
this.side = optionsArg.side;
|
||||
this.socket = optionsArg.socket;
|
||||
|
||||
// standard behaviour that is always true
|
||||
allSocketConnections.add(this);
|
||||
this.socket.on("disconnect", () => {
|
||||
plugins.beautylog.info(`SocketConnection with >alias ${this.alias} on >side ${this.side} disconnected`);
|
||||
allSocketConnections.remove(this);
|
||||
});
|
||||
};
|
||||
public alias: string;
|
||||
public side: TSocketConnectionSide;
|
||||
public authenticated: boolean = false;
|
||||
public role: SocketRole;
|
||||
public smartsocketRef: Smartsocket | SmartsocketClient;
|
||||
public socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
constructor(optionsArg: ISocketConnectionConstructorOptions) {
|
||||
this.alias = optionsArg.alias;
|
||||
this.authenticated = optionsArg.authenticated;
|
||||
this.role = optionsArg.role;
|
||||
this.side = optionsArg.side;
|
||||
this.smartsocketRef = optionsArg.smartsocketHost;
|
||||
this.socket = optionsArg.socket;
|
||||
|
||||
// authenticating --------------------------
|
||||
// standard behaviour that is always true
|
||||
allSocketConnections.add(this);
|
||||
this.socket.on('disconnect', () => {
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`SocketConnection with >alias ${this.alias} on >side ${this.side} disconnected`
|
||||
);
|
||||
this.socket.disconnect();
|
||||
allSocketConnections.remove(this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticate the socket
|
||||
*/
|
||||
authenticate() {
|
||||
let done = plugins.q.defer();
|
||||
this.socket.on("dataAuth", (dataArg:ISocketConnectionAuthenticationObject) => {
|
||||
plugins.beautylog.log("received authentication data. now hashing and comparing...");
|
||||
this.socket.removeListener("dataAuth", () => { });
|
||||
if (helpers.checkPasswordForRole(dataArg)) { // TODO: authenticate password
|
||||
this.alias = dataArg.alias
|
||||
this.authenticated = true;
|
||||
this.role = helpers.getSocketRoleByName(dataArg.role);
|
||||
this.socket.emit("authenticated");
|
||||
plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`);
|
||||
done.resolve(this);
|
||||
} else {
|
||||
this.authenticated = false;
|
||||
this.socket.disconnect();
|
||||
done.reject("not authenticated");
|
||||
};
|
||||
});
|
||||
this.socket.emit("requestAuth");
|
||||
return done.promise;
|
||||
};
|
||||
// authenticating --------------------------
|
||||
|
||||
// listening -------------------------------
|
||||
/**
|
||||
* authenticate the socket
|
||||
*/
|
||||
public authenticate() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
this.socket.on('dataAuth', (dataArg: ISocketConnectionAuthenticationObject) => {
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
'received authentication data. now hashing and comparing...'
|
||||
);
|
||||
this.socket.removeListener('dataAuth', () => {});
|
||||
if (SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
|
||||
// TODO: authenticate password
|
||||
this.alias = dataArg.alias;
|
||||
this.authenticated = true;
|
||||
this.role = SocketRole.getSocketRoleByName(this.smartsocketRef, dataArg.role);
|
||||
this.socket.emit('authenticated');
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'ok',
|
||||
`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`
|
||||
);
|
||||
done.resolve(this);
|
||||
} else {
|
||||
this.authenticated = false;
|
||||
this.socket.disconnect();
|
||||
done.reject('not authenticated');
|
||||
}
|
||||
});
|
||||
this.socket.emit('requestAuth');
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* listen to function requests
|
||||
*/
|
||||
listenToFunctionRequests(){
|
||||
let done = plugins.q.defer();
|
||||
if(this.authenticated){
|
||||
this.socket.on("function", (dataArg:ISocketRequestDataObject) => {
|
||||
// check if requested function is available to the socket's scope
|
||||
plugins.beautylog.log("function request received");
|
||||
let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
|
||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||
});
|
||||
if(referencedFunction !== undefined){
|
||||
plugins.beautylog.ok!("function in access scope");
|
||||
let localSocketRequest = new SocketRequest({
|
||||
side:"responding",
|
||||
originSocketConnection:this,
|
||||
shortId:dataArg.shortId,
|
||||
funcCallData:dataArg.funcCallData
|
||||
});
|
||||
localSocketRequest.createResponse(); // takes care of creating response and sending it back
|
||||
} else {
|
||||
plugins.beautylog.warn("function not existent or out of access scope");
|
||||
};
|
||||
});
|
||||
this.socket.on("functionResponse", (dataArg:ISocketRequestDataObject) => {
|
||||
plugins.beautylog.info(`received response for request with id ${dataArg.shortId}`);
|
||||
let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId);
|
||||
targetSocketRequest.handleResponse(dataArg);
|
||||
});
|
||||
plugins.beautylog.log(`now listening to function requests for ${this.alias}`);
|
||||
done.resolve(this);
|
||||
// listening -------------------------------
|
||||
|
||||
/**
|
||||
* listen to function requests
|
||||
*/
|
||||
public listenToFunctionRequests() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
if (this.authenticated) {
|
||||
this.socket.on('function', (dataArg: ISocketRequestDataObject) => {
|
||||
// check if requested function is available to the socket's scope
|
||||
plugins.smartlog.defaultLogger.log('info', 'function request received');
|
||||
const referencedFunction: SocketFunction = this.role.allowedFunctions.find(
|
||||
socketFunctionArg => {
|
||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||
}
|
||||
);
|
||||
if (referencedFunction !== undefined) {
|
||||
plugins.smartlog.defaultLogger.log('ok', 'function in access scope');
|
||||
const localSocketRequest = new SocketRequest(this.smartsocketRef, {
|
||||
side: 'responding',
|
||||
originSocketConnection: this,
|
||||
shortId: dataArg.shortId,
|
||||
funcCallData: dataArg.funcCallData
|
||||
});
|
||||
localSocketRequest.createResponse(); // takes care of creating response and sending it back
|
||||
} else {
|
||||
let errMessage: "socket needs to be authenticated first";
|
||||
plugins.beautylog.error(errMessage);
|
||||
done.reject(errMessage);
|
||||
};
|
||||
return done.promise;
|
||||
};
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'warn',
|
||||
'function not existent or out of access scope'
|
||||
);
|
||||
}
|
||||
});
|
||||
this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject) => {
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`received response for request with id ${dataArg.shortId}`
|
||||
);
|
||||
const targetSocketRequest = SocketRequest.getSocketRequestById(
|
||||
this.smartsocketRef,
|
||||
dataArg.shortId
|
||||
);
|
||||
targetSocketRequest.handleResponse(dataArg);
|
||||
});
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`now listening to function requests for ${this.alias}`
|
||||
);
|
||||
done.resolve(this);
|
||||
} else {
|
||||
const errMessage = 'socket needs to be authenticated first';
|
||||
plugins.smartlog.defaultLogger.log('error', errMessage);
|
||||
done.reject(errMessage);
|
||||
}
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
// sending ----------------------
|
||||
|
||||
};
|
||||
// sending ----------------------
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// import classes
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
import { SocketRole } from './smartsocket.classes.socketrole';
|
||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
|
||||
|
||||
// export interfaces
|
||||
|
||||
@ -10,28 +13,23 @@ import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
* interface of the contructor options of class SocketFunction
|
||||
*/
|
||||
export interface ISocketFunctionConstructorOptions {
|
||||
funcName: string;
|
||||
funcDef: any;
|
||||
allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
|
||||
};
|
||||
funcName: string;
|
||||
funcDef: TFuncDef;
|
||||
allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
|
||||
}
|
||||
|
||||
/**
|
||||
* interface of the Socket Function call, in other words the object that routes a call to a function
|
||||
*/
|
||||
export interface ISocketFunctionCall {
|
||||
funcName:string;
|
||||
funcDataArg:any;
|
||||
};
|
||||
funcName: string;
|
||||
funcDataArg: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* interface for function definition of SocketFunction
|
||||
*/
|
||||
export interface IFuncDef {
|
||||
(dataArg:any):PromiseLike<any>
|
||||
}
|
||||
|
||||
// export objects
|
||||
export let allSocketFunctions = new Objectmap<SocketFunction>();
|
||||
export type TFuncDef = (dataArg: any, connectionArg: SocketConnection) => PromiseLike<any>;
|
||||
|
||||
// export classes
|
||||
|
||||
@ -39,49 +37,57 @@ export let allSocketFunctions = new Objectmap<SocketFunction>();
|
||||
* class that respresents a function that can be transparently called using a SocketConnection
|
||||
*/
|
||||
export class SocketFunction {
|
||||
name: string;
|
||||
funcDef: IFuncDef;
|
||||
roles: SocketRole[];
|
||||
// STATIC
|
||||
public static getSocketFunctionByName(
|
||||
smartsocketRefArg: Smartsocket | SmartsocketClient,
|
||||
functionNameArg: string
|
||||
): SocketFunction {
|
||||
console.log(smartsocketRefArg.socketFunctions);
|
||||
return smartsocketRefArg.socketFunctions.find(socketFunctionArg => {
|
||||
return socketFunctionArg.name === functionNameArg;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* the constructor for SocketFunction
|
||||
*/
|
||||
constructor(optionsArg: ISocketFunctionConstructorOptions) {
|
||||
this.name = optionsArg.funcName;
|
||||
this.funcDef = optionsArg.funcDef;
|
||||
this.roles = optionsArg.allowedRoles;
|
||||
for (let socketRoleArg of this.roles){
|
||||
this._notifyRole(socketRoleArg);
|
||||
};
|
||||
allSocketFunctions.add(this); // map instance with Objectmap
|
||||
};
|
||||
// INSTANCE
|
||||
public name: string;
|
||||
public funcDef: TFuncDef;
|
||||
public roles: SocketRole[];
|
||||
|
||||
/**
|
||||
* notifies a role about access to this SocketFunction
|
||||
*/
|
||||
private _notifyRole(socketRoleArg:SocketRole){
|
||||
socketRoleArg.addSocketFunction(this);
|
||||
/**
|
||||
* the constructor for SocketFunction
|
||||
*/
|
||||
constructor(optionsArg: ISocketFunctionConstructorOptions) {
|
||||
this.name = optionsArg.funcName;
|
||||
this.funcDef = optionsArg.funcDef;
|
||||
this.roles = optionsArg.allowedRoles;
|
||||
for (const socketRoleArg of this.roles) {
|
||||
this._notifyRole(socketRoleArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* invokes the function of this SocketFunction
|
||||
*/
|
||||
invoke(dataArg:ISocketFunctionCall):plugins.q.Promise<any> {
|
||||
let done = plugins.q.defer();
|
||||
if(dataArg.funcName === this.name){
|
||||
this.funcDef(dataArg.funcDataArg)
|
||||
.then((resultData:any) => {
|
||||
let funcResponseData:ISocketFunctionCall = {
|
||||
funcName:this.name,
|
||||
funcDataArg:resultData
|
||||
}
|
||||
done.resolve(funcResponseData);
|
||||
});
|
||||
|
||||
} else {
|
||||
throw new Error("SocketFunction.name does not match the data argument's .name!");
|
||||
}
|
||||
return done.promise;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* invokes the function of this SocketFunction
|
||||
*/
|
||||
public invoke(dataArg: ISocketFunctionCall, socketConnectionArg: SocketConnection): Promise<any> {
|
||||
const done = plugins.smartpromise.defer();
|
||||
if (dataArg.funcName === this.name) {
|
||||
this.funcDef(dataArg.funcDataArg, socketConnectionArg).then((resultData: any) => {
|
||||
const funcResponseData: ISocketFunctionCall = {
|
||||
funcName: this.name,
|
||||
funcDataArg: resultData
|
||||
};
|
||||
done.resolve(funcResponseData);
|
||||
});
|
||||
} else {
|
||||
throw new Error("SocketFunction.name does not match the data argument's .name!");
|
||||
}
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* notifies a role about access to this SocketFunction
|
||||
*/
|
||||
private _notifyRole(socketRoleArg: SocketRole) {
|
||||
socketRoleArg.addSocketFunction(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,96 +1,123 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as helpers from "./smartsocket.helpers";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// import interfaces
|
||||
import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketFunction, ISocketFunctionCall } from './smartsocket.classes.socketfunction';
|
||||
|
||||
// import classes
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
import { SocketConnection } from './smartsocket.classes.socketconnection';
|
||||
import { defaultLogger } from '@pushrocks/smartlog';
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
|
||||
|
||||
// export interfaces
|
||||
export type TSocketRequestStatus = "new" | "pending" | "finished";
|
||||
export type TSocketRequestSide = "requesting" | "responding";
|
||||
export type TSocketRequestStatus = 'new' | 'pending' | 'finished';
|
||||
export type TSocketRequestSide = 'requesting' | 'responding';
|
||||
|
||||
/**
|
||||
* interface of constructor of class SocketRequest
|
||||
*/
|
||||
export interface SocketRequestConstructorOptions {
|
||||
side: TSocketRequestSide;
|
||||
originSocketConnection: SocketConnection;
|
||||
shortId: string;
|
||||
funcCallData?: ISocketFunctionCall;
|
||||
};
|
||||
side: TSocketRequestSide;
|
||||
originSocketConnection: SocketConnection;
|
||||
shortId: string;
|
||||
funcCallData?: ISocketFunctionCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* request object that is sent initially and may or may not receive a response
|
||||
*/
|
||||
export interface ISocketRequestDataObject {
|
||||
funcCallData: ISocketFunctionCall;
|
||||
shortId: string;
|
||||
responseTimeout?: number;
|
||||
};
|
||||
|
||||
//export objects
|
||||
export let allSocketRequests = new Objectmap<SocketRequest>();
|
||||
funcCallData: ISocketFunctionCall;
|
||||
shortId: string;
|
||||
responseTimeout?: number;
|
||||
}
|
||||
|
||||
// export classes
|
||||
export class SocketRequest {
|
||||
status: TSocketRequestStatus = "new";
|
||||
side: TSocketRequestSide;
|
||||
shortid: string;
|
||||
originSocketConnection: SocketConnection;
|
||||
funcCallData: ISocketFunctionCall
|
||||
done = plugins.q.defer();
|
||||
constructor(optionsArg: SocketRequestConstructorOptions) {
|
||||
this.side = optionsArg.side;
|
||||
this.shortid = optionsArg.shortId;
|
||||
this.funcCallData = optionsArg.funcCallData;
|
||||
this.originSocketConnection = optionsArg.originSocketConnection;
|
||||
allSocketRequests.add(this);
|
||||
// STATIC
|
||||
public static getSocketRequestById(
|
||||
smartsocketRef: Smartsocket | SmartsocketClient,
|
||||
shortIdArg: string
|
||||
): SocketRequest {
|
||||
return smartsocketRef.socketRequests.find(socketRequestArg => {
|
||||
return socketRequestArg.shortid === shortIdArg;
|
||||
});
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public status: TSocketRequestStatus = 'new';
|
||||
public side: TSocketRequestSide;
|
||||
public shortid: string;
|
||||
public originSocketConnection: SocketConnection;
|
||||
public funcCallData: ISocketFunctionCall;
|
||||
public done = plugins.smartpromise.defer();
|
||||
|
||||
public smartsocketRef: Smartsocket | SmartsocketClient;
|
||||
|
||||
constructor(
|
||||
smartsocketRefArg: Smartsocket | SmartsocketClient,
|
||||
optionsArg: SocketRequestConstructorOptions
|
||||
) {
|
||||
this.smartsocketRef = smartsocketRefArg;
|
||||
this.side = optionsArg.side;
|
||||
this.shortid = optionsArg.shortId;
|
||||
this.funcCallData = optionsArg.funcCallData;
|
||||
this.originSocketConnection = optionsArg.originSocketConnection;
|
||||
this.smartsocketRef.socketRequests.add(this);
|
||||
}
|
||||
|
||||
// requesting --------------------------
|
||||
|
||||
/**
|
||||
* dispatches a socketrequest from the requesting to the receiving side
|
||||
*/
|
||||
public dispatch() {
|
||||
const requestData: ISocketRequestDataObject = {
|
||||
funcCallData: this.funcCallData,
|
||||
shortId: this.shortid
|
||||
};
|
||||
this.originSocketConnection.socket.emit('function', requestData);
|
||||
return this.done.promise;
|
||||
}
|
||||
|
||||
// requesting --------------------------
|
||||
/**
|
||||
* handles the response that is received by the requesting side
|
||||
*/
|
||||
public handleResponse(responseDataArg: ISocketRequestDataObject) {
|
||||
plugins.smartlog.defaultLogger.log('info', 'handling response!');
|
||||
this.done.resolve(responseDataArg.funcCallData);
|
||||
this.smartsocketRef.socketRequests.remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* dispatches a socketrequest from the requesting to the receiving side
|
||||
*/
|
||||
dispatch() {
|
||||
let requestData: ISocketRequestDataObject = {
|
||||
funcCallData: this.funcCallData,
|
||||
shortId: this.shortid
|
||||
}
|
||||
this.originSocketConnection.socket.emit("function", requestData);
|
||||
return this.done.promise;
|
||||
};
|
||||
// responding --------------------------
|
||||
|
||||
/**
|
||||
* handles the response that is received by the requesting side
|
||||
*/
|
||||
handleResponse(responseDataArg: ISocketRequestDataObject) {
|
||||
plugins.beautylog.log("handling response!");
|
||||
this.done.resolve(responseDataArg.funcCallData);
|
||||
allSocketRequests.remove(this);
|
||||
/**
|
||||
* creates the response on the responding side
|
||||
*/
|
||||
public async createResponse(): Promise<void> {
|
||||
const targetSocketFunction: SocketFunction = SocketFunction.getSocketFunctionByName(
|
||||
this.smartsocketRef,
|
||||
this.funcCallData.funcName
|
||||
);
|
||||
|
||||
if (!targetSocketFunction) {
|
||||
defaultLogger.log(
|
||||
'warn',
|
||||
`There is no SocketFunction defined for ${this.funcCallData.funcName}`
|
||||
);
|
||||
defaultLogger.log('warn', `So now response is being sent.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// responding --------------------------
|
||||
|
||||
/**
|
||||
* creates the response on the responding side
|
||||
*/
|
||||
createResponse() {
|
||||
let targetSocketFunction: SocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
|
||||
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
|
||||
targetSocketFunction.invoke(this.funcCallData)
|
||||
.then((resultData) => {
|
||||
plugins.beautylog.log("got resultData. Sending it to requesting party.")
|
||||
let requestData: ISocketRequestDataObject = {
|
||||
funcCallData: resultData,
|
||||
shortId: this.shortid
|
||||
};
|
||||
this.originSocketConnection.socket.emit("functionResponse",requestData);
|
||||
allSocketRequests.remove(this);
|
||||
});
|
||||
}
|
||||
};
|
||||
plugins.smartlog.defaultLogger.log('info', `invoking ${targetSocketFunction.name}`);
|
||||
targetSocketFunction.invoke(this.funcCallData, this.originSocketConnection).then(resultData => {
|
||||
plugins.smartlog.defaultLogger.log('info', 'got resultData. Sending it to requesting party.');
|
||||
const requestData: ISocketRequestDataObject = {
|
||||
funcCallData: resultData,
|
||||
shortId: this.shortid
|
||||
};
|
||||
this.originSocketConnection.socket.emit('functionResponse', requestData);
|
||||
this.smartsocketRef.socketRequests.remove(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,53 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// import classes
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketFunction } from "./smartsocket.classes.socketfunction";
|
||||
|
||||
|
||||
export let allSocketRoles = new Objectmap<SocketRole>();
|
||||
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
import { SocketFunction } from './smartsocket.classes.socketfunction';
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient';
|
||||
import { ISocketConnectionAuthenticationObject } from './smartsocket.classes.socketconnection';
|
||||
|
||||
/**
|
||||
* interface for class SocketRole
|
||||
*/
|
||||
export interface SocketRoleOptions {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
export class SocketRole {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
allowedFunctions = new Objectmap<SocketFunction>();
|
||||
constructor(optionsArg: SocketRoleOptions) {
|
||||
this.name = optionsArg.name;
|
||||
this.passwordHash = optionsArg.passwordHash;
|
||||
allSocketRoles.add(this);
|
||||
};
|
||||
addSocketFunction(socketFunctionArg:SocketFunction){
|
||||
this.allowedFunctions.add(socketFunctionArg);
|
||||
}
|
||||
}
|
||||
// STATIC
|
||||
public static getSocketRoleByName(
|
||||
referenceSmartsocket: Smartsocket | SmartsocketClient,
|
||||
socketRoleNameArg: string
|
||||
): SocketRole {
|
||||
return referenceSmartsocket.socketRoles.find(socketRoleArg => {
|
||||
return socketRoleArg.name === socketRoleNameArg;
|
||||
});
|
||||
}
|
||||
|
||||
public static checkPasswordForRole(
|
||||
dataArg: ISocketConnectionAuthenticationObject,
|
||||
referenceSmartsocket: Smartsocket | SmartsocketClient
|
||||
): boolean {
|
||||
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
|
||||
.passwordHash;
|
||||
const computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password);
|
||||
return targetPasswordHash === computedCompareHash;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public name: string;
|
||||
public passwordHash: string;
|
||||
public allowedFunctions = new Objectmap<SocketFunction>();
|
||||
constructor(optionsArg: SocketRoleOptions) {
|
||||
this.name = optionsArg.name;
|
||||
this.passwordHash = optionsArg.passwordHash;
|
||||
}
|
||||
public addSocketFunction(socketFunctionArg: SocketFunction) {
|
||||
this.allowedFunctions.add(socketFunctionArg);
|
||||
}
|
||||
}
|
||||
|
77
ts/smartsocket.classes.socketserver.ts
Normal file
77
ts/smartsocket.classes.socketserver.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
|
||||
// used in case no other server is supplied
|
||||
import * as http from 'http';
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
|
||||
/**
|
||||
* class socketServer
|
||||
* handles the attachment of socketIo to whatever server is in play
|
||||
*/
|
||||
export class SocketServer {
|
||||
private smartsocket: Smartsocket;
|
||||
private httpServer: http.Server;
|
||||
// wether httpServer is standalone
|
||||
private standaloneServer = false;
|
||||
private expressServer: any;
|
||||
|
||||
constructor(smartSocketInstance: Smartsocket) {
|
||||
this.smartsocket = smartSocketInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the server with another server
|
||||
* also works with an express style server
|
||||
*/
|
||||
public async setExternalServer(
|
||||
serverType: 'smartexpress',
|
||||
serverArg: plugins.smartexpress.Server
|
||||
) {
|
||||
await serverArg.startedPromise;
|
||||
this.httpServer = serverArg.httpServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the server for socket.io
|
||||
*/
|
||||
public getServerForSocketIo() {
|
||||
if (this.httpServer) {
|
||||
return this.httpServer;
|
||||
} else {
|
||||
this.httpServer = new http.Server();
|
||||
this.standaloneServer = true;
|
||||
return this.httpServer;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* starts listening to incoming sockets:
|
||||
*/
|
||||
public async start() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
// handle http servers
|
||||
// in case an external server has been set "this.standaloneServer" should be false
|
||||
if (this.httpServer && this.standaloneServer) {
|
||||
if (!this.smartsocket.options.port) {
|
||||
console.log('there should be a port specifed for smartsocket!');
|
||||
throw new Error('there should be a port specified for smartsocket');
|
||||
}
|
||||
this.httpServer.listen(this.smartsocket.options.port, () => {
|
||||
console.log(`Server started in standalone mode on ${this.smartsocket.options.port}`);
|
||||
done.resolve();
|
||||
});
|
||||
} else {
|
||||
done.resolve();
|
||||
}
|
||||
|
||||
// nothing else to do if express server is set
|
||||
await done.promise;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* closes the server
|
||||
*/
|
||||
public async stop() {}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
// classes
|
||||
import { Smartsocket } from "./smartsocket.classes.smartsocket";
|
||||
import { SocketFunction, allSocketFunctions } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketConnection, ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketRequest, allSocketRequests, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
|
||||
import { SocketRole, allSocketRoles } from "./smartsocket.classes.socketrole";
|
||||
|
||||
// SocketConnection helpers
|
||||
export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject): boolean => {
|
||||
let targetPasswordHash = getSocketRoleByName(dataArg.role).passwordHash;
|
||||
let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password);
|
||||
return targetPasswordHash === computedCompareHash;
|
||||
}
|
||||
|
||||
|
||||
// SocketFunction helpers
|
||||
export let getSocketFunctionByName = (functionNameArg: string): SocketFunction => {
|
||||
return allSocketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg });
|
||||
}
|
||||
|
||||
// SocketRequest helpers
|
||||
|
||||
/**
|
||||
* get corresponding Socketrequest instance by shortId
|
||||
*/
|
||||
export let getSocketRequestById = (shortIdArg: string, requestSide?: TSocketRequestSide): SocketRequest => {
|
||||
return allSocketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg })
|
||||
}
|
||||
|
||||
// SocketRole helpers
|
||||
|
||||
/**
|
||||
* get corresponding SocketRole instance by name
|
||||
*/
|
||||
export let getSocketRoleByName = (socketRoleNameArg: string): SocketRole => {
|
||||
return allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg })
|
||||
};
|
||||
|
@ -1,9 +1,21 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import nodehash = require("nodehash");
|
||||
export import q = require("q");
|
||||
export import shortid = require("shortid");
|
||||
export import socketIo = require("socket.io");
|
||||
export import socketIoClient = require("socket.io-client");
|
||||
export import taskbuffer = require("taskbuffer");
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as shortid from 'shortid';
|
||||
import socketIo from 'socket.io';
|
||||
import socketIoClient from 'socket.io-client';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartlog,
|
||||
smarthash,
|
||||
smartdelay,
|
||||
smartexpress,
|
||||
smartpromise,
|
||||
shortid,
|
||||
socketIo,
|
||||
socketIoClient
|
||||
};
|
||||
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user