|
| 1 | +# Streamdelay |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Streamdelay enables streams to have ["broadcast delay"](https://en.wikipedia.org/wiki/Broadcast_delay) for content redaction/filtering. Stream upload is delayed by a customizable duration, allowing a pixelization and audio blocking filter to be applied ahead of unacceptable content being broadcast. |
| 6 | + |
| 7 | +Streamdelay accepts an input stream using the [SRT protocol](https://www.haivision.com/products/srt-secure-reliable-transport/) (supported by OBS and ffmpeg), and can output to either an SRT or RTMP endpoint (such as twitch.tv or restream.io). |
| 8 | + |
| 9 | +A UI is currently not provided. The `streamdelay` package is designed to run as a local service, controlled via its built-in API server. This is meant to be integrated into a larger stream management dashboard, such as [`streamwall`](https://github.com/chromakode/streamwall). |
| 10 | + |
| 11 | +## Setup |
| 12 | + |
| 13 | +### Binaries |
| 14 | + |
| 15 | +Binaries may be available via the [releases page](https://github.com/chromakode/streamdelay/releases). You will need to [install the GStreamer runtime](https://gstreamer.freedesktop.org/download/) for your platform. |
| 16 | + |
| 17 | +### Source |
| 18 | + |
| 19 | +1. Ensure you have the buildchain for your platform installed necessary to [build binary node modules using node-gyp](https://github.com/nodejs/node-gyp#installation). |
| 20 | +1. Install [GStreamer](https://gstreamer.freedesktop.org/download/). You will need both the runtime and development headers installed. |
| 21 | +1. Run `npm install`. This will install dependencies and build the `node-gstreamer-superficial` library. |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Starting Streamdelay |
| 26 | + |
| 27 | +1. Copy `example.config.json` to `config.json` and customize to suit your needs. |
| 28 | +1. Configure your streaming software to output to the SRT endpoint specified in `"srtInUri"`. |
| 29 | +1. Run (binary) `streamdelay --config=config.json` or (development) `npm start -- --config=config.json`. |
| 30 | +1. Start streaming. |
| 31 | + |
| 32 | +## HTTP API |
| 33 | + |
| 34 | +Streamdelay runs an HTTP server on the hostname and port you configure. |
| 35 | + |
| 36 | +### Authentication |
| 37 | + |
| 38 | +Requests must either contain: |
| 39 | + |
| 40 | +- a `Streamdelay-API-Key` header equal to the `apiKey` value configured |
| 41 | +- a `?key=API_KEY` query param equal to the `apiKey` value configured |
| 42 | + |
| 43 | +All responses are `Content-Type: application/json`. |
| 44 | + |
| 45 | +### Get current state |
| 46 | + |
| 47 | +``` |
| 48 | +GET /state |
| 49 | +``` |
| 50 | + |
| 51 | +returns: |
| 52 | + |
| 53 | +``` |
| 54 | +{ |
| 55 | + censored: bool, |
| 56 | + status: {... full state object ...} |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +The `status` object can be matched using [`xstate`'s `State.from` constructor](https://xstate.js.org/api/classes/state.html#from): |
| 61 | + |
| 62 | +```js |
| 63 | +// Check if the stream is waiting for a connection |
| 64 | +State.from(status).matches('stream.running.waiting') |
| 65 | + |
| 66 | +// Check if the stream is connected and rolling |
| 67 | +State.from(status).matches('stream.running.started') |
| 68 | + |
| 69 | +// Check if we're in the process of deactivating the censorship mode |
| 70 | +State.from(status).matches('censorship.censored.deactivating') |
| 71 | +``` |
| 72 | + |
| 73 | +### Set state |
| 74 | + |
| 75 | +Set the stream state to censored (redacted) or not. When transitioning from censored to uncensored state, Streamdelay will wait the configured `delaySeconds` before turning off the censored state. This helps prevent early release of the censored mode before the delayed content has been broadcast. |
| 76 | + |
| 77 | +``` |
| 78 | +PATCH /state |
| 79 | +``` |
| 80 | + |
| 81 | +body: |
| 82 | + |
| 83 | +`{censored: false}` or `{censored: true}` |
| 84 | + |
| 85 | +returns: same as `/status` |
| 86 | + |
| 87 | +## Websocket API |
| 88 | + |
| 89 | +``` |
| 90 | +GET /ws?key=API_KEY |
| 91 | +Upgrade: websocket |
| 92 | +``` |
| 93 | + |
| 94 | +Upon initial connection, the current state will be sent in JSON format. It will be sent again whenever the state changes. |
| 95 | + |
| 96 | +Sending a JSON message has the same behavior as `PATCH /state`. |
0 commit comments