How to get duration after room_finished event
# ask-ai
b
How to get duration after room_finished event
t
Thanks for reaching out, G. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to get the room duration after a
room_finished
webhook event. LiveKit does not include a separate "duration" field in the
room_finished
payload. The event contains
started_at
and
ended_at
timestamps (Unix timestamps in nanoseconds). Compute duration by subtracting and converting nanoseconds to seconds. Example payload:
Copy code
{
  "event": "room_finished",
  "room": {
    "sid": "RM_123",
    "name": "my-room",
    "started_at": 1732135319356232400,
    "ended_at": 1732135407895558000
  }
}
Calculation (pseudo-code):
Copy code
duration_seconds = (ended_at - started_at) / 1e9
Notes: • The timestamps are in nanoseconds, so divide by 1e9 to get seconds. • If you need milliseconds, divide by 1e6 instead. • If your language/framework uses integer types, ensure you convert to a float or use integer arithmetic carefully to avoid truncation. If you’d like, tell me which language or runtime you’re using (Node, Python, Go, Ruby, etc.) and I’ll provide a short code snippet you can drop into your webhook handler. Sources: Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | server-sdk-go | livekit/livekit_composite | DeepWiki | server-sdk-ruby | livekit/livekit_composite | DeepWiki | server-sdk-js | livekit/livekit_composite | DeepWiki