|
|
@ -8,13 +8,20 @@ easy and secure websocket communication
|
|
|
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsocket/)
|
|
|
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsocket/)
|
|
|
|
|
|
|
|
|
|
|
|
## Status for master
|
|
|
|
## Status for master
|
|
|
|
[](https://gitlab.com/pushrocks/smartsocket/commits/master)
|
|
|
|
|
|
|
|
[](https://gitlab.com/pushrocks/smartsocket/commits/master)
|
|
|
|
Status Category | Status Badge
|
|
|
|
[](https://www.npmjs.com/package/@pushrocks/smartsocket)
|
|
|
|
-- | --
|
|
|
|
[](https://snyk.io/test/npm/@pushrocks/smartsocket)
|
|
|
|
GitLab Pipelines | [](https://lossless.cloud)
|
|
|
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
|
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
|
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
|
|
npm | [](https://lossless.cloud)
|
|
|
|
[](https://prettier.io/)
|
|
|
|
Snyk | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
TypeScript Support | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
|
|
|
|
|
|
Code Style | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
|
|
|
|
|
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
@ -30,7 +37,7 @@ import * as q from q; // q is a promise library
|
|
|
|
|
|
|
|
|
|
|
|
// The "Smartsocket" listens on a port and can receive new "SocketConnection" requests.
|
|
|
|
// The "Smartsocket" listens on a port and can receive new "SocketConnection" requests.
|
|
|
|
let mySmartsocket = new smartsocket.Smartsocket({
|
|
|
|
let mySmartsocket = new smartsocket.Smartsocket({
|
|
|
|
port: 3000 // the port smartsocket will listen on
|
|
|
|
port: 3000, // the port smartsocket will listen on
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// optional:
|
|
|
|
// optional:
|
|
|
@ -43,7 +50,7 @@ mySmartsocket.setServer(someExpressServer);
|
|
|
|
// "SocketFunction"s know which "SocketRole"s are allowed to execute them
|
|
|
|
// "SocketFunction"s know which "SocketRole"s are allowed to execute them
|
|
|
|
let mySocketRole = new smartsocket.SocketRole({
|
|
|
|
let mySocketRole = new smartsocket.SocketRole({
|
|
|
|
name: 'someRoleName',
|
|
|
|
name: 'someRoleName',
|
|
|
|
passwordHash: 'someHashedString'
|
|
|
|
passwordHash: 'someHashedString',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// A "SocketFunction" executes a referenced function and passes in any data of the corresponding "SocketRequest".
|
|
|
|
// A "SocketFunction" executes a referenced function and passes in any data of the corresponding "SocketRequest".
|
|
|
@ -51,10 +58,10 @@ let mySocketRole = new smartsocket.SocketRole({
|
|
|
|
// Any "SocketRequest" carries a unique identifier. If the referenced function's promise resolved any passed on argument will be returned to the requesting party
|
|
|
|
// 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({
|
|
|
|
let testSocketFunction1 = new smartsocket.SocketFunction({
|
|
|
|
funcName: 'testSocketFunction1',
|
|
|
|
funcName: 'testSocketFunction1',
|
|
|
|
funcDef: data => {
|
|
|
|
funcDef: (data) => {
|
|
|
|
console.log('testSocketFunction1 executed successfully!');
|
|
|
|
console.log('testSocketFunction1 executed successfully!');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
allowedRoles: [mySocketRole] // all roles that have access to a specific function
|
|
|
|
allowedRoles: [mySocketRole], // all roles that have access to a specific function
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// A "Smartsocket" exposes a .clientCall() that gets
|
|
|
|
// A "Smartsocket" exposes a .clientCall() that gets
|
|
|
@ -62,7 +69,7 @@ let testSocketFunction1 = new smartsocket.SocketFunction({
|
|
|
|
// 2. the data to pass in
|
|
|
|
// 2. the data to pass in
|
|
|
|
// 3. And a target "SocketConnection" (there can be multiple connections at once)
|
|
|
|
// 3. And a target "SocketConnection" (there can be multiple connections at once)
|
|
|
|
// any unique id association is done internally
|
|
|
|
// any unique id association is done internally
|
|
|
|
mySmartsocket.clientCall('restart', data, someTargetConnection).then(responseData => {});
|
|
|
|
mySmartsocket.clientCall('restart', data, someTargetConnection).then((responseData) => {});
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### Client side
|
|
|
|
#### Client side
|
|
|
@ -77,7 +84,7 @@ let testSmartsocketClient = new smartsocket.SmartsocketClient({
|
|
|
|
url: 'http://localhost',
|
|
|
|
url: 'http://localhost',
|
|
|
|
password: 'testPassword',
|
|
|
|
password: 'testPassword',
|
|
|
|
alias: 'testClient1',
|
|
|
|
alias: 'testClient1',
|
|
|
|
role: 'testRole1'
|
|
|
|
role: 'testRole1',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// You can .connect() and .disconnect() from a "Smartsocket"
|
|
|
|
// You can .connect() and .disconnect() from a "Smartsocket"
|
|
|
@ -88,12 +95,12 @@ testSmartsocketClient.connect().then(() => {
|
|
|
|
// The client can also specify "SocketFunction"s. It can also specify "SocketRole"s in case a client connects to multiple servers at once
|
|
|
|
// 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({
|
|
|
|
let testSocketFunction2 = new smartsocket.SocketFunction({
|
|
|
|
funcName: 'testSocketFunction2',
|
|
|
|
funcName: 'testSocketFunction2',
|
|
|
|
funcDef: data => {}, // the function to execute, has to return promise
|
|
|
|
funcDef: (data) => {}, // the function to execute, has to return promise
|
|
|
|
allowedRoles: []
|
|
|
|
allowedRoles: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// A "SmartsocketClient" can call functions on the serverside using .serverCall() analog to the "Smartsocket"'s .clientCall method.
|
|
|
|
// A "SmartsocketClient" can call functions on the serverside using .serverCall() analog to the "Smartsocket"'s .clientCall method.
|
|
|
|
mySmartsocketClient.serverCall('function', functionCallData).then(functionResponseData => {
|
|
|
|
mySmartsocketClient.serverCall('function', functionCallData).then((functionResponseData) => {
|
|
|
|
// the functionResponseData comes from the server... awesome, right?
|
|
|
|
// the functionResponseData comes from the server... awesome, right?
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
```
|
|
|
@ -103,6 +110,11 @@ mySmartsocketClient.serverCall('function', functionCallData).then(functionRespon
|
|
|
|
> `data` is always a js object that you can design for your specific needs.
|
|
|
|
> `data` is always a js object that you can design for your specific needs.
|
|
|
|
> It supports buffers for large binary data network exchange.
|
|
|
|
> It supports buffers for large binary data network exchange.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Contribution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
|
|
|
|
|
|
|
|
|
|
|
For further information read the linked docs at the top of this readme.
|
|
|
|
For further information read the linked docs at the top of this readme.
|
|
|
|
|
|
|
|
|
|
|
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
|
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|