Guard remote video refs from unnecessary playback resets#18
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| const attachStreamToElement = useCallback( | ||
| (element: HTMLVideoElement | null, stream: MediaStream | null | undefined) => { | ||
| if (!element) { | ||
| return; | ||
| } | ||
|
|
||
| const stream = localStreamRef.current; | ||
| if (stream && element.srcObject !== stream) { | ||
| const currentStream = element.srcObject as MediaStream | null; | ||
| let streamAttached = false; | ||
|
|
||
| if (stream && currentStream !== stream) { | ||
| element.srcObject = stream; | ||
| streamAttached = true; | ||
| } | ||
|
|
||
| element.muted = true; | ||
| if (element.srcObject) { | ||
| if ((streamAttached || element.paused) && element.srcObject) { | ||
| element.play().catch(() => undefined); |
There was a problem hiding this comment.
[P1] Clear video element when stream disappears
The new attachStreamToElement helper only sets element.srcObject when the incoming stream is truthy. When a remote participant’s stream becomes null or undefined, the function skips assignment and never removes the previous stream, so the element keeps rendering and playing the stale video/audio. The prior implementation assigned element.srcObject = participant.stream regardless of value, which detached the stream when absent. This regression leaves orphaned media playing whenever a participant leaves or a camera stops.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68d1bde2aba4832ab047dabf3b066457