smartsocket/README.md

62 lines
1.6 KiB
Markdown
Raw Normal View History

2016-08-06 21:27:53 +00:00
# smartsocket
easy and secure websocket communication
## 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 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
roles: [mySocketRole] // all roles that have access to a specific function
});
mySmartsocketClient.registerFunction(mySocketFunction2);
2016-08-07 13:12:21 +00:00
mySmartsocketClient.serverCall("newService",data)
.then((responseData) => {
});;
2016-08-07 12:58:20 +00:00
```