update docs
This commit is contained in:
		
							
								
								
									
										98
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										98
									
								
								README.md
									
									
									
									
									
								
							| @@ -2,100 +2,28 @@ | |||||||
| easy and secure websocket communication, TypeScript ready | easy and secure websocket communication, TypeScript ready | ||||||
|  |  | ||||||
| ## Availabililty | ## Availabililty | ||||||
| [](https://www.npmjs.com/package/smartsocket) | [](https://www.npmjs.com/package/smartsocket) | ||||||
| [](https://gitlab.com/pushrocks/smartsocket) | [](https://GitLab.com/pushrocks/smartsocket) | ||||||
| [](https://github.com/pushrocks/smartsocket) | [](https://github.com/pushrocks/smartsocket) | ||||||
| [](https://pushrocks.gitlab.io/smartsocket/docs) | [](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) | ||||||
| [](https://gitlab.com/pushrocks/smartsocket/commits/master) | [](https://GitLab.com/pushrocks/smartsocket/commits/master) | ||||||
|  | [](https://www.npmjs.com/package/smartsocket) | ||||||
| [](https://david-dm.org/pushrocks/smartsocket) | [](https://david-dm.org/pushrocks/smartsocket) | ||||||
| [](https://www.bithound.io/github/pushrocks/smartsocket/master/dependencies/npm) | [](https://www.bithound.io/github/pushrocks/smartsocket/master/dependencies/npm) | ||||||
| [](https://www.bithound.io/github/pushrocks/smartsocket) | [](https://www.bithound.io/github/pushrocks/smartsocket) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
|  | [](http://standardjs.com/) | ||||||
|  |  | ||||||
| ## Usage | ## 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 | For further information read the linked docs at the top of this README. | ||||||
| ```typescript |  | ||||||
| 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. | > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | ||||||
| let mySmartsocket = new smartsocket.Smartsocket({ | | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | ||||||
|     port: 3000 // the port smartsocket will listen on |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| // A "SocketRole" can be referenced by "SocketFunction"s. | [](https://push.rocks) | ||||||
| // 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" |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| // 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) => { |  | ||||||
|         console.log('testSocketFunction1 executed successfully!') |  | ||||||
|     }, |  | ||||||
|     allowedRoles:[mySocketRole] // all roles that have access to a specific function |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| // 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"; |  | ||||||
|  |  | ||||||
| // 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" |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| // 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:[] |  | ||||||
| }); |  | ||||||
|  |  | ||||||
|  |  | ||||||
| // 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.   |  | ||||||
|   | |||||||
| @@ -1,15 +0,0 @@ | |||||||
| { |  | ||||||
|     "structure": { |  | ||||||
|         "readme": "index.md" |  | ||||||
|     }, |  | ||||||
|     "plugins": [ |  | ||||||
|         "tonic", |  | ||||||
|         "edit-link" |  | ||||||
|     ], |  | ||||||
|     "pluginsConfig": { |  | ||||||
|         "edit-link": { |  | ||||||
|             "base": "https://gitlab.com/pushrocks/npmts/edit/master/docs/", |  | ||||||
|             "label": "Edit on GitLab" |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,47 +1,63 @@ | |||||||
| # smartsocket | # smartsocket | ||||||
| easy and secure websocket communication, Typescript ready | easy and secure websocket communication, TypeScript ready | ||||||
|  |  | ||||||
| ## Availabililty | ## Availabililty | ||||||
| [](https://www.npmjs.com/package/smartsocket) | [](https://www.npmjs.com/package/smartsocket) | ||||||
| [](https://gitlab.com/pushrocks/smartsocket) | [](https://GitLab.com/pushrocks/smartsocket) | ||||||
| [](https://github.com/pushrocks/smartsocket) | [](https://github.com/pushrocks/smartsocket) | ||||||
| [](https://pushrocks.gitlab.io/smartsocket/docs) | [](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) | ||||||
| [](https://gitlab.com/pushrocks/smartsocket/commits/master) | [](https://GitLab.com/pushrocks/smartsocket/commits/master) | ||||||
|  | [](https://www.npmjs.com/package/smartsocket) | ||||||
| [](https://david-dm.org/pushrocks/smartsocket) | [](https://david-dm.org/pushrocks/smartsocket) | ||||||
| [](https://www.bithound.io/github/pushrocks/smartsocket/master/dependencies/npm) | [](https://www.bithound.io/github/pushrocks/smartsocket/master/dependencies/npm) | ||||||
| [](https://www.bithound.io/github/pushrocks/smartsocket) | [](https://www.bithound.io/github/pushrocks/smartsocket) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
|  | [](http://standardjs.com/) | ||||||
|  |  | ||||||
| ## Usage | ## 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. | Under the hood we use socket.io and shortid for managed data exchange. | ||||||
|  |  | ||||||
| ### Serverside | ### Serverside | ||||||
| ```typescript | ```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({ | let mySmartsocket = new smartsocket.Smartsocket({ | ||||||
|     port: 3000 // the port smartsocket will listen on |     port: 3000 // the port smartsocket will listen on | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | // 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({ | 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". | ||||||
|  | // 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({ | let testSocketFunction1 = new smartsocket.SocketFunction({ | ||||||
|     funcName:"testSocketFunction1", |     funcName:"testSocketFunction1", | ||||||
|     funcDef:(data) => { |     funcDef:(data) => { | ||||||
|          |         console.log('testSocketFunction1 executed successfully!') | ||||||
|     }, // the function to execute |     }, | ||||||
|     allowedRoles:[mySocketRole] // all roles that have access to a specific function |     allowedRoles:[mySocketRole] // all roles that have access to a specific function | ||||||
| }); | }); | ||||||
|  |  | ||||||
| mySmartsocket.clientCall("","restart",data,someTargetConnection) | // 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) => { |     .then((responseData) => { | ||||||
|  |  | ||||||
|     }); |     }); | ||||||
| @@ -51,6 +67,8 @@ mySmartsocket.clientCall("","restart",data,someTargetConnection) | |||||||
| ```typescript | ```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({ | let testSmartsocketClient = new smartsocket.SmartsocketClient({ | ||||||
|     port: testConfig.port, |     port: testConfig.port, | ||||||
|     url: "http://localhost", |     url: "http://localhost", | ||||||
| @@ -58,24 +76,22 @@ let testSmartsocketClient = new smartsocket.SmartsocketClient({ | |||||||
|     alias: "testClient1", |     alias: "testClient1", | ||||||
|     role: "testRole1" |     role: "testRole1" | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | // You can .connect() and .disconnect() from a "Smartsocket" | ||||||
| testSmartsocketClient.connect() | testSmartsocketClient.connect() | ||||||
|     .then(() => { |     .then(() => { | ||||||
|         done(); |         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({ | 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:[] | ||||||
| }); | }); | ||||||
|  |  | ||||||
| let functionCalldata = { |  | ||||||
|     funcName: "", |  | ||||||
|     funcData: { |  | ||||||
|         someKey:"someValue" |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | // A "SmartsocketClient" can call functions on the serverside using .serverCall() analog to the "Smartsocket"'s .clientCall method. | ||||||
| mySmartsocketClient.serverCall("function",functionCallData) | mySmartsocketClient.serverCall("function",functionCallData) | ||||||
|     .then((functionResponseData) => { // the functionResponseData comes from the server... awesome, right? |     .then((functionResponseData) => { // the functionResponseData comes from the server... awesome, right? | ||||||
|          |          | ||||||
| @@ -86,3 +102,10 @@ mySmartsocketClient.serverCall("function",functionCallData) | |||||||
| you can easily chain dependent requests on either the server or client side with promises.   | 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.   | `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.   | ||||||
|  |  | ||||||
|  | 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.html) | ||||||
|  |  | ||||||
|  | [](https://push.rocks) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user