MediaStreams are not compliant with EventTarget behaviour
Categories
(Core :: WebRTC: Audio/Video, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox90 | --- | fixed |
People
(Reporter: michel.neumann, Assigned: smaug)
References
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
Steps to reproduce:
For a project using WebRTC, we are currently emitting "addtrack" and "removetrack" events explicitly on MediaStream instances to get notified for track changes to trigger rtp sender updates and re-negotiation on the peer connection managing that stream.
According to the MDN documentation and W3C, MediaStreams are derivatives of EventTargets, and therefore support the Pub/Sub pattern with "addEventListener" and "dispatchEvent". In the current Firefox, the event listeners are not executed as expected.
Please see the attached code examples.
Actual results:
In both examples, a media stream is created. Event listeners are added to the stream and several custom events are dispatched on the media stream. In the first example, none of the expected callbacks were executed. In the second example, only the "onaddtrack" callback is executed.
Expected results:
In the first example, two callbacks should be executed and printed to the console. In the second example, four callbacks should be executed and printed to the console. This example runs as expected in Chrome 89 and Safari 14, but not in Firefox 87, Dev Edition and Firefox Android 87.
| Reporter | ||
Comment 1•4 years ago
|
||
Comment 2•4 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::WebRTC: Audio/Video' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Comment 4•4 years ago
|
||
It would be great, if someone from Mozilla could have a look at this issue!
Comment 5•4 years ago
|
||
Confirmed. I see the same thing https://jsfiddle.net/jib1/1v0Lgw2y/
Firefox: Expected 4 executions, got 1
Chrome & Safari: Expected 4 executions, got 4
This is odd, since dispatchEvent should be inherited.
MediaStream is implemented by DOMMediaStream which inherits from DOMEventTargetHelper which has that method, which is ultimately the same one called internally.
Olli, is there some trick to this?
| Assignee | ||
Comment 6•4 years ago
|
||
Hmm, it works for other event targets, like XMLHttpRequest.
MediaStream constructor doesn't seem to pass window to DOMEventTargetHelper
https://searchfox.org/mozilla-central/rev/e3c34d34cc7dce56df377f05183ad379ac1de123/dom/media/DOMMediaStream.cpp#120-121
vs
https://searchfox.org/mozilla-central/rev/5359952d8b0be3e706e8c943c2bef2674723b8a9/dom/xhr/XMLHttpRequestEventTarget.h#21
Because of that difference, do we end up returning false from
https://searchfox.org/mozilla-central/rev/5359952d8b0be3e706e8c943c2bef2674723b8a9/dom/events/DOMEventTargetHelper.cpp#235 which would explain why trusted events get handled but untrusted don't.
| Assignee | ||
Comment 7•4 years ago
|
||
Updated•4 years ago
|
| Assignee | ||
Comment 8•4 years ago
|
||
I think MediaStreamTrack is also broken.
Comment 10•4 years ago
|
||
| bugherder | ||
| Reporter | ||
Comment 11•4 years ago
|
||
Thanks for looking into this!
Description
•