Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve track enabled state during cloning #2061

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

luisrivas
Copy link
Collaborator

@luisrivas luisrivas commented Nov 5, 2024

Pull Request Details

Description

Ensures track.enabled state is correctly maintained when cloning MediaStreamTracks. Addresses a Safari 18 bug where cloned tracks are incorrectly enabled during cloning. See https://commits.webkit.org/285916@main for more details.

Cloning a track on Safari 18 Cloning a track on Chrome 130
Screenshot from Safari 18 Screenshot from Chrome 130

Bug report

Burndown

Before review

  • Updated CHANGELOG.md if necessary
  • Added unit tests if necessary
  • Updated affected documentation
  • Verified locally with npm test
  • Manually sanity tested running locally
  • Included screenshot as PR comment (if needed)
  • Ready for review

Ensures track.enabled state is correctly maintained when cloning MediaStreamTracks.
Addresses a Safari 18 bug where cloned tracks are incorrectly enabled during cloning.
See https://commits.webkit.org/285916@main for more details.
Copy link
Collaborator

@charliesantos charliesantos left a comment

Choose a reason for hiding this comment

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

Implementation looks good. Please complete the PR checklist next.

Prevents "Cannot read properties of undefined" error when cloning data tracks
by only setting the enabled state for audio/video tracks.
Copy link
Collaborator

@charliesantos charliesantos left a comment

Choose a reason for hiding this comment

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

Can you add changelog and unit test?

@luisrivas
Copy link
Collaborator Author

Can you add changelog and unit test?

Sure thing! I just added both.

Comment on lines +10 to +22
it(`should maintain track enabled state (${enabledState}) during publication`, () => {
const mediaStreamTrack = new FakeMediaStreamTrack('audio');
mediaStreamTrack.enabled = enabledState;

const trackSender = new MediaTrackSender(mediaStreamTrack);
assert.strictEqual(trackSender.track.enabled, enabledState);

const publication = new LocalTrackPublicationSignaling(trackSender, 'track1', 'standard');

assert.strictEqual(publication.trackTransceiver.track.enabled, enabledState);
assert.strictEqual(publication.isEnabled, enabledState);
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to properly test the Safari bug, we should also mock the behavior of the 'clone' function to always set the enabled state to 'true'. That way, we are sure that we're testing it properly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I just added a test mocking the clone method to mimic the Safari 18 bug.

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