-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Bump mc-server-runner & document websocket API #3789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+84
−3
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e3fd5a
deps: upgrade mc-server-runner 1.14.0
EmilyxFox b1957d8
docs: websocket api documentation
EmilyxFox 7415f47
put docker port forwarding tip in tip block
EmilyxFox 38c0de5
specify allowed origins list is comma-separated
EmilyxFox add3c11
add javascript example of how to supply password as i think my
EmilyxFox bd9190b
clerify API path
EmilyxFox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| title: With websocket | ||
| --- | ||
|
|
||
| With `WEBSOCKET_CONSOLE` set to `true`, logs can be streamed, and commands sent, over a websocket connection. | ||
| The API is available on `/websocket`. | ||
|
|
||
| ## Password | ||
| 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`. | ||
| ??? Example "Examples" | ||
| ```js title="JavaScript example" | ||
| let socket = new WebSocket("http://localhost:80/websocket", ["mc-server-runner-ws-v1", "rcon-password"]); | ||
| ``` | ||
|
|
||
| ## Allowed origins | ||
| A list of comma-separated allowed origins should be supplied with `WEBSOCKET_ALLOWED_ORIGINS`. Origin checking can be disabled with `WEBSOCKET_DISABLE_ORIGIN_CHECK`. | ||
|
|
||
| ## Listen address | ||
| 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. | ||
|
|
||
| ## Log history | ||
| 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. | ||
|
|
||
| ??? tip "Tip: Remember to forward the websocket port on the host" | ||
|
|
||
| ```yaml title="compose.yaml" | ||
| services: | ||
| mc: | ||
| ports: | ||
| - '25565:25565' | ||
| - '80:80' | ||
| ``` | ||
|
|
||
| ## Environment variables | ||
| | Environment Variable | Usage | Default | | ||
| | ---------------------------------- | ---------------------------------------------------------- | ------------ | | ||
| | `WEBSOCKET_CONSOLE` | Allow remote shell over websocket | `false` | | ||
| | `WEBSOCKET_ADDRESS` | Bind address for websocket server | `0.0.0.0:80` | | ||
| | `WEBSOCKET_DISABLE_ORIGIN_CHECK` | Disable checking if origin is trusted | `false` | | ||
| | `WEBSOCKET_ALLOWED_ORIGINS` | Comma-separated list of trusted origins | ` ` | | ||
| | `WEBSOCKET_PASSWORD` | Password will be the same as RCON_PASSWORD if unset | ` ` | | ||
| | `WEBSOCKET_DISABLE_AUTHENTICATION` | Disable websocket authentication | `false` | | ||
| | `WEBSOCKET_LOG_BUFFER_SIZE` | Number of log lines to save and send to connecting clients | `50` | | ||
|
|
||
| ## API Schema | ||
| ```ts title="API Schema" | ||
| interface StdinMessage { | ||
| type: "stdin"; | ||
| data: string; | ||
| } | ||
|
|
||
| interface StdoutMessage { | ||
| type: "stdout"; | ||
| data: string; | ||
| } | ||
|
|
||
| interface StderrMessage { | ||
| type: "stderr"; | ||
| data: string; | ||
| } | ||
|
|
||
| interface LogHistoryMessage { | ||
| type: "logHistory"; | ||
| lines: string[]; | ||
| } | ||
|
|
||
| interface AuthFailureMessage { | ||
| type: "authFailure"; | ||
| reason: string; | ||
| } | ||
|
|
||
| // Messages sent from Client -> Server | ||
| export type ClientMessage = StdinMessage; | ||
|
|
||
| // Messages sent from Server -> Client | ||
| export type ServerMessage = | ||
| | StdoutMessage | ||
| | StderrMessage | ||
| | LogHistoryMessage | ||
| | AuthFailureMessage; | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I didn’t know it supports collapsed ones.