When subscribing to a realtime video stream, there is currently no reliable, low-latency way to detect when a remote stream has ended or stopped sending frames.
This makes it difficult to correctly clean up resources (video elements, UI state, subscriptions) in realtime applications.
My use case is specifically for when the subscriber client doesn't have direct access to the producer client to see when the video transform stream has ended (e.g. when producer and subscriber are on different devices). While it possible to introduce an additional sync mechanism for the stream end state, it seems overkill when the subscriber should already have that state internally.
Current Behavior
Using the realtime session viewing feature:
const subscriber = await client.realtime.subscribe({
token,
onRemoteStream: (stream) => {
video.srcObject = stream;
},
});
- MediaStreamTrack.onended does not fire when the remote stream stops
- HTMLVideoElement.ended does not fire (expected for live streams)
- No documented subscriber or client event fires when the stream silently stops
- No access to the underlying RTCPeerConnection or its state events
In practice, when the remote side ends a session, the stream simply stops delivering frames without emitting any observable event at the SDK level.
Requested (any of the following would help):
- Emit a subscriber lifecycle event (e.g. ended / closed)
- Provide a dedicated stream-ended callback
- Expose the underlying RTCPeerConnection on the subscriber
This would greatly improve reliability and developer ergonomics for realtime use cases.
Current workaround
At this time I'm doing basic frame-level detection using HTMLVideoElement.requestVideoFrameCallback() (just checking when the last frame arrived), which works but is fragile and doesn't really provide realtime guarantees.
Thanks for considering this!
When subscribing to a realtime video stream, there is currently no reliable, low-latency way to detect when a remote stream has ended or stopped sending frames.
This makes it difficult to correctly clean up resources (video elements, UI state, subscriptions) in realtime applications.
My use case is specifically for when the subscriber client doesn't have direct access to the producer client to see when the video transform stream has ended (e.g. when producer and subscriber are on different devices). While it possible to introduce an additional sync mechanism for the stream end state, it seems overkill when the subscriber should already have that state internally.
Current Behavior
Using the realtime session viewing feature:
In practice, when the remote side ends a session, the stream simply stops delivering frames without emitting any observable event at the SDK level.
Requested (any of the following would help):
This would greatly improve reliability and developer ergonomics for realtime use cases.
Current workaround
At this time I'm doing basic frame-level detection using HTMLVideoElement.requestVideoFrameCallback() (just checking when the last frame arrived), which works but is fragile and doesn't really provide realtime guarantees.
Thanks for considering this!