5
0
Fork 0
backend-signal/README.md

123 lines
2.4 KiB
Markdown
Raw Permalink Normal View History

2019-01-26 00:12:23 +08:00
# backend-signal
2019-02-02 12:41:04 +08:00
Beep backend handling WebRTC signaling.
2019-02-24 04:02:47 +08:00
**To run this service securely means to run it behind traefik forwarding auth to `backend-auth`**
2019-02-02 12:41:04 +08:00
## Quickstart
Docker:
```bash
export PORT=1837 # Or whatever port number you like
docker build -t backend-signal . && docker run -it backend-signal
```
Not hipster (requires node.js):
```bash
export PORT=1837 # Or whatever port number you like
npm install
node index.js
```
## API
Unless otherwise noted, bodies and responses are with ```Content-Type: application/json```.
| Contents |
| -------- |
| [Subscribe to SSE](#Subscribe-to-SSE) |
| [Get a user's devices](#Get-a-user's-devices) |
| [Post data to a user's device](#Post-data-to-a-user's-device) |
### Subscribe to SSE
```
2019-02-24 04:02:47 +08:00
GET /subscribe
2019-02-02 12:41:04 +08:00
```
Subscribe a user's device to the signaling service. Recommended usage:
```js
const es = new EventSource(`${host}/subscribe/${user}/device/${device}`);
es.onmessage = (e) => {
const data = e.data;
// Do whatever with data
};
```
2019-02-24 04:02:47 +08:00
#### Required headers
2019-02-02 12:41:04 +08:00
2019-02-24 04:02:47 +08:00
| Name | Description |
| ---- | ----------- |
| X-User-Claim | Stringified user claim, populated by `backend-auth` called by `traefik` |
2019-02-02 12:41:04 +08:00
#### Success Response (200 OK)
An [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) stream.
2019-02-24 04:02:47 +08:00
#### Errors
| Code | Description |
| ---- | ----------- |
| 401| Invalid user claims header. |
2019-02-02 12:41:04 +08:00
---
### Get a user's devices
```
GET /user/:user/devices
```
Get a list of device IDs associated with the specified user. One can then use the IDs to post data to individual devices.
#### URL Params
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| user | String | Target user's ID. | ✓ |
#### Success Response (200 OK)
List of device IDs. Can be an empty list.
```
[ <id>, <id2>, ... ]
```
---
### Post data to a user's device
```
POST /user/:user/device/:device
```
Post data to the specified device of the specified user.
#### URL Params
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| user | String | Target user's ID. | ✓ |
| device | String | Target device's ID. | ✓ |
#### Body
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| data | String | Data to be sent. | ✓ |
#### Success Response (200 OK)
Empty body.
#### Errors
| Code | Description |
| ---- | ----------- |
| 400 | No data to be sent was supplied. |
| 404 | The specified user/device's connection could not be found. |