2016-08-06 21:27:53 +00:00
|
|
|
# smartsocket
|
2016-08-07 17:07:11 +00:00
|
|
|
easy and secure websocket communication, Typescript ready
|
2016-08-06 21:27:53 +00:00
|
|
|
|
|
|
|
## Status
|
|
|
|
[![build status](https://gitlab.com/pushrocks/smartsocket/badges/master/build.svg)](https://gitlab.com/pushrocks/smartsocket/commits/master)
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
We recommend the use of typescript.
|
2016-08-07 17:07:11 +00:00
|
|
|
Under the hood we use socket.io and shortid for managed data exchange.
|
2016-08-06 21:27:53 +00:00
|
|
|
|
2016-08-07 13:12:21 +00:00
|
|
|
### Serverside
|
2016-08-07 12:58:20 +00:00
|
|
|
```typescript
|
2016-08-07 13:14:53 +00:00
|
|
|
import * as smartsocket from "smartsocket";
|
|
|
|
|
2016-08-07 12:58:20 +00:00
|
|
|
let mySmartsocket = new smartsocket.Smartsocket({
|
|
|
|
port: 3000 // the port smartsocket will listen on
|
|
|
|
});
|
|
|
|
|
|
|
|
let mySocketRole = new smartsocket.SocketRole({
|
|
|
|
name: "someRoleName",
|
2016-08-07 13:12:21 +00:00
|
|
|
passwordHash: "someHashedString"
|
2016-08-07 12:58:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let mySocketFunction = new smartsocket.SocketFunction({
|
2016-08-07 13:12:21 +00:00
|
|
|
name:"newService",
|
|
|
|
func:(data) => {
|
|
|
|
|
|
|
|
}, the function to execute
|
2016-08-07 12:58:20 +00:00
|
|
|
roles:[mySocketRole] // all roles that have access to a specific function
|
|
|
|
});
|
|
|
|
|
|
|
|
mySmartsocket.registerRole(mySocketRole);
|
2016-08-07 13:12:21 +00:00
|
|
|
mySmartsocket.clientCall.select("client1","restart",data)
|
|
|
|
.then((responseData) => {
|
2016-08-07 12:58:20 +00:00
|
|
|
|
2016-08-07 13:12:21 +00:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Client side
|
|
|
|
```typescript
|
2016-08-07 13:14:53 +00:00
|
|
|
import * as smartsocket from "smartsocket";
|
|
|
|
|
2016-08-07 12:58:20 +00:00
|
|
|
let mySmartsocketClient = new smartsocket.SmartsocketClient({
|
|
|
|
url: "somedomain.com", // url, note: will only work over https, no http supported.
|
|
|
|
port: 3000
|
|
|
|
role:"dockerhost", // some role, in this example a dockerhost vm,
|
2016-08-07 13:12:21 +00:00
|
|
|
password:"somePassword",
|
|
|
|
alias:"client1"
|
2016-08-07 12:58:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let mySocketFunction2 = new smartsocket.SocketFunction({
|
2016-08-07 13:12:21 +00:00
|
|
|
name:"restart",
|
|
|
|
func:(data) => {}, the function to execute
|
2016-08-07 12:58:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
mySmartsocketClient.registerFunction(mySocketFunction2);
|
|
|
|
|
2016-08-07 13:12:21 +00:00
|
|
|
mySmartsocketClient.serverCall("newService",data)
|
|
|
|
.then((responseData) => {
|
|
|
|
|
|
|
|
});;
|
2016-08-07 17:07:11 +00:00
|
|
|
```
|
|
|
|
|
2016-08-07 17:15:05 +00:00
|
|
|
> **NOTE:**
|
|
|
|
you can easily chain dependent requests on eiter 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.
|