Re: [mediacapture-main] It is unclear which of PermissionStatus change event or MediaStreamTrack ended event should fire first in case Permission is revoked (#862)

What the [permissions spec](https://w3c.github.io/permissions/#ref-for-dfn-permission-revocation-algorithm-1) says now is: _"When the permission [lifetime](https://w3c.github.io/permissions/#dfn-lifetime) expires for an origin:_

 1. _Set the permission back to its default [permission state](https://w3c.github.io/permissions/#dfn-permission-state) (e.g., by setting it back to "[prompt](https://w3c.github.io/permissions/#dfn-prompt)")._
 2. _For each browsing context associated with the origin (if any), [queue a global task](https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task) on the [permissions task source](https://w3c.github.io/permissions/#dfn-permissions-task-source) ... to run the [permission revocation algorithm](https://w3c.github.io/permissions/#dfn-permission-revocation-algorithm)."_ ... which in our case _"is the result of calling the [device permission revocation algorithm](https://w3c.github.io/mediacapture-main/#dfn-device-permission-revocation-algorithm)"_, which _"For each track ..., [[ends](https://w3c.github.io/mediacapture-main/#ends-nostop)] the track."_, which means _"queue a task that ... [fire an event](https://dom.spec.whatwg.org/#concept-event-fire) named [ended](https://w3c.github.io/mediacapture-main/#event-mediastreamtrack-ended)"_

A simple interpretation of this numbering (1,2) might suggest that that was also the intended order of events. However, if we take the queued tasks into consideration, it gets more complicated.

Step 2 here queues a task A per global to queue a task B per track to fire `ended`, which takes 2+ tasks.

Step 1 [appears to invoke](https://w3c.github.io/permissions/#dfn-permissionstatus-update-steps): _"Whenever the [user agent](https://infra.spec.whatwg.org/#user-agent) is aware that the state of a [PermissionStatus](https://w3c.github.io/permissions/#dom-permissionstatus) instance status has changed, it ... runs the PermissionStatus update steps:_ [ignoring  here] ... [Queue a task](https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task) on the [permissions task source](https://w3c.github.io/permissions/#dfn-permissions-task-source) to [fire an event](https://dom.spec.whatwg.org/#concept-event-fire) named change at status."_

IOW, Step 1 here queues a task C per global to fire `change`.

So `change` happens before `ended`.

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/862#issuecomment-1726264023 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 19 September 2023 18:21:33 UTC