Skip to content

Add WebSocket messages for beatmap data and user activity#38071

Open
tsunyoku wants to merge 23 commits into
ppy:masterfrom
tsunyoku:add-basic-websocket-data
Open

Add WebSocket messages for beatmap data and user activity#38071
tsunyoku wants to merge 23 commits into
ppy:masterfrom
tsunyoku:add-basic-websocket-data

Conversation

@tsunyoku

@tsunyoku tsunyoku commented Jun 13, 2026

Copy link
Copy Markdown
Member

Warning

To any onlookers, this API is still rapidly changing. Please expect further breaking changes and do not use this PR to flood requests for what data should be available.

RFC.

Example player state message

{
    "beatmap": {
        "beatmap_id": 974423,
        "beatmapset_id": 239330,
        "beatmap_hash": "583aa402376a240ae57f0326c62f2452",
        "metadata": {
            "artist": "Rameses B",
            "artist_unicode": "Rameses B",
            "title": "We Love",
            "title_unicode": "We Love",
            "author": "Milan-",
            "source": "",
            "tags": "dnb drum and bass liquid uplifting melodic chopping chill",
            "user_tags": []
        },
        "difficulty": {
            "approach_rate": 8.23,
            "circle_size": 3,
            "overall_difficulty": 8.03,
            "drain_rate": 4
        },
        "difficulty_name": "Normal",
        "ruleset_id": 0,
        "bpm": 306,
        "star_rating": 3.06,
        "max_combo": 240,
        "status": "Ranked"
    },
    "ruleset_id": 0,
    "mods": [
        {
            "acronym": "DT",
            "settings": {
                "speed_change": 1.76
            }
        }
    ],
    "type": "PlayerStateWebSocketMessage"
}

Example user activity message

{"status":"InSoloGame","data":{"beatmap_id":259,"ruleset_id":0},"type":"UserActivityWebSocketMessage"}

Comment thread osu.Desktop/IPC/Messages/PlayerStateMessage.cs Outdated
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using Newtonsoft.Json;

@bdach bdach Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One thing I'm not super sure about is continuing to use Newtonsoft.Json. I know I used it for the PoC message, but I really did not think much about things that should be thought about going forward with a proper implementation of this as it was a singular, low-frequency, small-size message.

The primary reason to go with System.Text.Json instead would be performance. I have not measured myself, but most everyone on the Internet appears to indicate that System.Text.Json is significantly faster at the expense of supporting less bells and whistles.

Another semi-related thing to consider is that maybe the overhead of performing the serialisation itself should be dumped off to a thread to minimise delays on the update thread. Binding to things like OsuGame.Beatmap means that the serialisation code runs on every change, and in particular on the thread that triggered the bindable change, which may degrade performance of something like song select noticeably, what with between the frequency of changes there.

I'm not super sure what to suggest at this stage yet, as I'd have to allocate time to investigate these things myself. Maybe @ppy/team-client wants to chip in here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm all for avoiding using Newtonsoft for new usages, unless there's good reason to do so. I trust microsoft's implementation more as far as security goes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd also prefer STJ, just didn't know that was an option here.

Comment thread osu.Desktop/IPC/Messages/BeatmapMessage.cs Outdated
Comment thread osu.Desktop/IPC/Messages/PlayerStateMessage.cs Outdated
Comment thread osu.Desktop/IPC/OsuWebSocketProvider.cs Outdated
Comment thread osu.Desktop/IPC/OsuWebSocketProvider.cs Outdated
Comment thread osu.Desktop/IPC/OsuWebSocketProvider.cs Outdated
Comment thread osu.Desktop/IPC/OsuWebSocketProvider.cs
@bdach bdach added the subjective PRs with subjective changes which have not been discussed prior. Need team consensus to proceed. label Jun 15, 2026
@peppy peppy self-requested a review June 16, 2026 07:31
Comment thread osu.Desktop/IPC/Messages/PlayerStateMessage.cs Outdated
Comment thread osu.Game/IPC/Messages/OsuWebSocketMessage.cs
Comment thread osu.Desktop/IPC/OsuWebSocketProvider.cs
Comment thread osu.Game/IPC/WebSocketDataSource.cs Outdated

@bdach bdach left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Source read pass before I attempt to run and evaluate further based on the results of running.

Comment thread osu.Game/OsuGame.cs Outdated
Comment thread osu.Game/Online/API/APIMod.cs Outdated
Comment thread osu.Game/IPC/DataSources/UserActivityWebSocketDataSource.cs
Comment thread osu.Game/IPC/Models/WebSocketBeatmap.cs

@bdach bdach left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

General details of this are mostly fine by me at this point. Review pass below is mostly haggling over minor design / code quality concerns.

At some point this should go through a performance check but I'm not sure when to invest that time. Maybe I'd like one more @ppy/team-client review to go over the general shape of this, and maybe some of the nits mentioned in this fixed, and then I'd do a final "does this work and how fast" check.

Comment thread osu.Game/IPC/DataSources/BeatmapStateWebSocketDataSource.cs
Comment thread osu.Game/OsuGame.cs Outdated
Comment thread osu.Game/IPC/Models/WebSocketEditingBeatmapUserActivityData.cs Outdated
Comment thread osu.Game/IPC/Models/WebSocketInGameUserActivityData.cs Outdated
Comment thread osu.Game/IPC/Models/WebSocketInLobbyUserActivityData.cs
Comment thread osu.Game/IPC/Models/WebSocketWatchingReplayUserActivityData.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL subjective PRs with subjective changes which have not been discussed prior. Need team consensus to proceed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants