Skip to content

Add structured message format for WebSocket traffic#32

Merged
creesch merged 5 commits intomainfrom
22-create-json-format-for-websocket-traffic-allowing-for-more-targeted-traffic
Dec 21, 2024
Merged

Add structured message format for WebSocket traffic#32
creesch merged 5 commits intomainfrom
22-create-json-format-for-websocket-traffic-allowing-for-more-targeted-traffic

Conversation

@creesch
Copy link
Copy Markdown
Collaborator

@creesch creesch commented Dec 21, 2024

Fixes #22
Fixes #6

Java side:

  • WebsocketJsonMessage class for the message format.
  • MinecraftServerIdentifier class to properly identify the "server" name and a unique identifier.

Front-end:

  • New message_types.mjs module containing the front-end implementation of the new structured messages.
  • Reworked chat.mjs to handle the new structured message format.
    • This includes handling the new timestamps. This includes using them for error messages.
  • Added: utility function to create timestamps.
  • Sneaky refactor of the CSS to be more consistently use rem.
  • Removed functionality for stored messages from the front-end code. It didn't make sense to me to try and migrate these somehow and the next PR from me will very likely be tackling Store chat messages per server within the minecraft config directory instead of using front-end. #3

Example message

{
    "timestamp": 1734794189937,
    "server": {
        "name": "Tildes MC Survival",
        "identifier": "4d311f91-6a27-31a3-b76d-3efe21dda823"
    },
    "type": "chatMessage",
    "minecraftVersion": "1.21.1",
    "payload": {
        "translate": "%s",
        "with": [
            {
                "text": "\u003c",
                "extra": [
                    {
                        "text": "creesch",
                        "color": "#0099CC"
                    },
                    {
                        "text": "\u003e ",
                        "extra": [
                            "Testing something with timestamp"
                        ]
                    }
                ]
            }
        ]
    }
}

Screenshot:

image

@creesch
Copy link
Copy Markdown
Collaborator Author

creesch commented Dec 21, 2024

@danthedaniel, leaving the PR open for a bit for you to look at it if you want.

Copy link
Copy Markdown
Member

@danthedaniel danthedaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just some nitpick comments.

@creesch creesch merged commit 196cc5e into main Dec 21, 2024
Copy link
Copy Markdown
Member

@danthedaniel danthedaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing to me 🎉

@creesch creesch deleted the 22-create-json-format-for-websocket-traffic-allowing-for-more-targeted-traffic branch May 4, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create JSON format for websocket traffic allowing for more targeted traffic. timestamps

2 participants