Add method to query rtcStats on room#663
Conversation
|
| const res = FfiClient.instance.request<GetSessionStatsRequest>({ | ||
| message: { | ||
| case: 'getSessionStats', | ||
| value: { | ||
| roomHandle: this.ffiHandle.handle, | ||
| }, | ||
| }, | ||
| }); | ||
| const cb = await FfiClient.instance.waitFor<GetSessionStatsCallback>( | ||
| (ev: FfiEvent) => | ||
| ev.message.case === 'getSessionStats' && ev.message.value.asyncId === res.requestAsyncId, |
There was a problem hiding this comment.
🔴 Wrong async ID field name causes getRtcStats to hang forever
The getRtcStats method accesses res.requestAsyncId to match the callback event, but every other async FFI method in the codebase (simulateScenario at room.ts:387, connect at room.ts:293, disconnect at room.ts:356, and all methods in participant.ts) uses res.asyncId. The response object returned by FfiClient.instance.request() will have an asyncId field (matching the FFI response protobuf), not requestAsyncId. At runtime, res.requestAsyncId evaluates to undefined, so the predicate in waitFor never matches any incoming event. This causes the method to hang indefinitely until the room disconnects and the AbortSignal fires, at which point it rejects with an abort error instead of returning stats.
Additionally, the type parameter is GetSessionStatsRequest instead of a Response type (every other call site uses the corresponding *Response type, e.g., SimulateScenarioResponse, ConnectResponse).
Prompt for agents
In packages/livekit-rtc/src/room.ts, the getRtcStats method has two issues on lines 202 and 212:
1. Line 202: The type parameter for FfiClient.instance.request should be the response type (likely GetSessionStatsResponse), not GetSessionStatsRequest. Every other call site in room.ts and participant.ts uses the *Response type (e.g. SimulateScenarioResponse, ConnectResponse, DisconnectResponse).
2. Line 212: res.requestAsyncId should be res.asyncId. Every other async Ffi method in the codebase uses res.asyncId to correlate the callback. Using requestAsyncId results in undefined at runtime, causing the waitFor predicate to never match.
You will need to check if GetSessionStatsResponse is exported from @livekit/rtc-ffi-bindings and import it, then change the type parameter on request<> and change requestAsyncId to asyncId.
Was this helpful? React with 👍 or 👎 to provide feedback.
No description provided.