Skip to content

Room stats API#138

Open
alan-george-lk wants to merge 8 commits into
mainfrom
feature/stats
Open

Room stats API#138
alan-george-lk wants to merge 8 commits into
mainfrom
feature/stats

Conversation

@alan-george-lk
Copy link
Copy Markdown
Collaborator

@alan-george-lk alan-george-lk commented May 20, 2026

This PR exposes a getStats() public API method to room.h to match Rust.

API design decisions

TL/DR: matches Rust SDK as 1:1 as possible.

I opted for the signature getStats() to match Rust: https://github.com/livekit/rust-sdks/blob/1848e77a32ca2f302a58323a7a21858165d81aad/livekit/src/room/mod.rs#L831

std::future -> async equivalent
Result -> EngineResult equivalent

The struct SessionStats also matches Rust: https://github.com/livekit/rust-sdks/blob/1848e77a32ca2f302a58323a7a21858165d81aad/livekit/src/rtc_engine/rtc_session.rs#L112

Stores vectors of publisher_stats and subscriber_stats to match Rust.

Error handling

  • The current version of this design has an error struct return type with a message and code. This code enum is "implied" from what went wrong, i.e. not returned from Rust FFI directly
  • The Rust FFI only returns a string
  • I am a bit conflicted about this Result<> design with the error code, as it adds 2 public types (struct/enum) and a whole header, for a code that doesn't actually exist other than in this SDK
  • The alternative is a Result<SessionStats, std::string> which would pass along the error string on failure with no additional types beyond the actual data struct

Testing

  • Added integration test that does some basic room operations and then obtains the stats

@alan-george-lk alan-george-lk changed the title Expose room session stats Room stats API May 22, 2026
@alan-george-lk alan-george-lk marked this pull request as ready for review May 26, 2026 21:53
Copy link
Copy Markdown
Collaborator

@stephen-derosa stephen-derosa left a comment

Choose a reason for hiding this comment

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

nice LGTM!

Comment thread src/room.cpp
return connection_state_;
}

std::future<Result<SessionStats, GetSessionStatsError>> Room::getStats() const {
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.

should we name getStatsAsync() so its clear this is async/matches the ffi call?

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.

2 participants