Skip to content

Commit b1957d8

Browse files
committed
docs: websocket api documentation
1 parent 0e3fd5a commit b1957d8

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Sending commands
2+
title: With Docker
33
---
44

55
[RCON](http://wiki.vg/RCON) is enabled by default, so you can `exec` into the container to
@@ -66,4 +66,4 @@ and then Control-p Control-q to **detach**.
6666

6767
!!! info "RCON is required for fully interactive, color console"
6868

69-
RCON must be enabled, which is the default, in order to use a fully interactive console with auto-completion and colorized log output.
69+
RCON must be enabled, which is the default, in order to use a fully interactive console with auto-completion and colorized log output.

docs/sending-commands/websocket.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: With websocket
3+
---
4+
5+
With `WEBSOCKET_CONSOLE` set to `true`, logs can be streamed, and commands sent, over a websocket connection.
6+
7+
## Password
8+
A password must be supplied using the `Sec-WebSocket-Protocol` header. This is done by putting `mc-server-runner-ws-v1` in the first slot, and the password in the second. The password can be set with `RCON_PASSWORD` or `WEBSOCKET_PASSWORD`. The latter overwrites the former. Authentication can be disabled with `WEBSOCKET_DISABLE_AUTHENTICATION`.
9+
10+
## Allowed origins
11+
A list of allowed origins should be supplied with `WEBSOCKET_ALLOWED_ORIGINS`. Origin checking can be disabled with `WEBSOCKET_DISABLE_ORIGIN_CHECK`.
12+
13+
## Listen address
14+
The listen address and port can be set with `WEBSOCKET_ADDRESS` (defaults to `0.0.0.0:80`), but it's recommended to listen on all interfaces when running in Docker.
15+
16+
## Log history
17+
When a connection is established, the last 50 (by default, configurable with `WEBSOCKET_LOG_BUFFER_SIZE`) log lines are sent with a `logHistory` type message.
18+
19+
## Docker port forwarding
20+
Remember to forward the websocket port to the host:
21+
```yaml title="compose.yaml"
22+
services:
23+
mc:
24+
ports:
25+
- '25565:25565'
26+
- '80:80'
27+
```
28+
29+
## Environment variables
30+
| Environment Variable | Usage | Default |
31+
| ---------------------------------- | ---------------------------------------------------------- | ------------ |
32+
| `WEBSOCKET_CONSOLE` | Allow remote shell over websocket | `false` |
33+
| `WEBSOCKET_ADDRESS` | Bind address for websocket server | `0.0.0.0:80` |
34+
| `WEBSOCKET_DISABLE_ORIGIN_CHECK` | Disable checking if origin is trusted | `false` |
35+
| `WEBSOCKET_ALLOWED_ORIGINS` | Comma-separated list of trusted origins | ` ` |
36+
| `WEBSOCKET_PASSWORD` | Password will be the same as RCON_PASSWORD if unset | ` ` |
37+
| `WEBSOCKET_DISABLE_AUTHENTICATION` | Disable websocket authentication | `false` |
38+
| `WEBSOCKET_LOG_BUFFER_SIZE` | Number of log lines to save and send to connecting clients | `50` |
39+
40+
## API Schema
41+
```ts title="API Schema"
42+
interface StdinMessage {
43+
type: "stdin";
44+
data: string;
45+
}
46+
47+
interface StdoutMessage {
48+
type: "stdout";
49+
data: string;
50+
}
51+
52+
interface StderrMessage {
53+
type: "stderr";
54+
data: string;
55+
}
56+
57+
interface LogHistoryMessage {
58+
type: "logHistory";
59+
lines: string[];
60+
}
61+
62+
interface AuthFailureMessage {
63+
type: "authFailure";
64+
reason: string;
65+
}
66+
67+
// Messages sent from Client -> Server
68+
export type ClientMessage = StdinMessage;
69+
70+
// Messages sent from Server -> Client
71+
export type ServerMessage =
72+
| StdoutMessage
73+
| StderrMessage
74+
| LogHistoryMessage
75+
| AuthFailureMessage;
76+
```

0 commit comments

Comments
 (0)