- From: Jan-Ivar Bruaroey via GitHub <sysbot+gh@w3.org>
- Date: Mon, 13 Nov 2023 21:21:39 +0000
- To: public-webrtc-logs@w3.org
> * It adds a side-effect to the `onsourceswitch` setter, which is an anti-pattern. What side-effect? [Cancelable event](https://dom.spec.whatwg.org/#dom-event-cancelable) is an established pattern, and this works just as well: ```js controller.addEventListener("sourceswitch", event => { video.srcObject = event.stream; event.preventDefault(); }); ``` > * It requires more code from the app - even if the app doesn't want to use this feature. (Foreshadowing.) Please explain. > * It might be error-prone for the app, which might fail to call `preventDefault()` on some branches. This seems to discount legitimate reasons for not calling it. E.g an app just wanting to be notified of switching. I think it's much simpler to explain that: 1. There's a [cancelable](https://dom.spec.whatwg.org/#dom-event-cancelable) `sourceswitch` event that fires on source switching 2. Apps can prevent the default switch and grab the fired stream instead To compare, please explain in one sentence what `setSurfaceSwitchingCallback` does. It glues two things together, forcing extra work on an app just to be notified. I therefore find it the more complicated API to understand — e.g. someone trying to reverse-engineer its meaning from reading JS — as well as being more limited in what functionality it offers. It also violates [§ 7.3. Don’t invent your own event listener-like infrastructure](https://w3ctag.github.io/design-principles/#dont-invent-event-like). > Can you give a concrete example of an application that _needs_ to make the decision to source-inject or not on a dynamic basis? Can you give a concrete example of why an application _must_ make this decision to source-inject or not upfront? @youennf mentioned migration in https://github.com/w3c/mediacapture-screen-share/issues/255#issuecomment-1740477003 _"The web application could decide to stick with the old tracks and stop the new tracks instead if it is thought more adequate. ... This would allow easy migration in the simple cases (just do nothing for video, check for new audio)"_ which is the [example I gave](https://github.com/w3c/mediacapture-screen-share/issues/255#issuecomment-1808730088). He also said: _"We could have a simple CaptureController `onswitch` event, given it would not have any side effect."_ My API accomplishes both of those. -- GitHub Notification of comment by jan-ivar Please view or discuss this issue at https://github.com/w3c/mediacapture-screen-share/issues/255#issuecomment-1809146807 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 13 November 2023 21:21:41 UTC