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

automation: Adapt to Generic Sensor changes to stash provided readings #147

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rakuco
Copy link
Member

@rakuco rakuco commented Mar 12, 2024

Closes: none (but related to w3c/sensors#487)

The following tasks have been completed:

  • Modified Web platform tests (link to pull request) (existing tests already rely on this behavior)

Implementation commitment:


Just like with w3c/sensors#487, the idea is to make it possible for
users to write, for example

await test_driver.create_virtual_sensor(...);
await test_driver.update_virtual_sensor(...);
window.addEventListener('deviceorientation', ...);

and receive the readings above even if the connection to the virtual sensor
was made only after the addEventListener() call. Previously, users would
need to carefully order the calls to addEventListener(),
update_virtual_sensor() and possibly even need to add a dummy event listener
first to get everything to work correctly.

Unfortunately, just as with w3c/sensor#487 this requires quite a few
changes, even more so in this specification, which is quite vague when it
comes to connecting to sensors and the lifetimes of such connections.

Some of that behavior is now specified for the virtual sensors case, so that
each Document has a [[virtualSensorMapping]] that maps virtual sensor
types to "orientation event platform sensor-likes", a concept borrowed from
Generic Sensor's automation section.

Similarly to that section, the idea is that:

  • Whenever the user agent needs to connect to the underlying hardware
    because addEventListener() was called, it first attempts to find a virtual
    sensor, get/create an orientation event platform sensor-like, adds it to
    [[virtualSensorMapping]] and to the virtual sensor's connected platform
    sensors set and retrieves any existing readings from the virtual sensor.
  • When a Document is being unloaded, all platform sensor-likes in
    [[virtualSensorMapping]] are removed from their virtual sensors'
    connected platform sensors set.
  • Similarly, when a virtual sensor is removed, any platform sensor-likes in
    its connected platform set have their associated "device sensor" set to
    null.

In the rest of the spec, we switch from attempting to derive a virtual
sensor from the top-level traversable directly to trying to find a suitable
platform sensor-like entry in [[virtualSensorMapping]] and checking its
associated virtual sensor when one is set.

Related to: w3c/sensors#478.


Preview | Diff

@rakuco rakuco requested a review from reillyeon March 12, 2024 16:57
@rakuco
Copy link
Member Author

rakuco commented Mar 12, 2024

@reillyeon PTAL. The Generic Sensor side of this change looks OK to me, but, as usual, trying to apply the same ideas to this specification leads to a lot of hand-waving and hoping that things make sense.

Just like with w3c/sensors#487, the idea is to make it possible for
users to write, for example

```js
await test_driver.create_virtual_sensor(...);
await test_driver.update_virtual_sensor(...);
window.addEventListener('deviceorientation', ...);
```

and receive the readings above even if the connection to the virtual sensor
was made only after the addEventListener() call. Previously, users would
need to carefully order the calls to addEventListener(),
update_virtual_sensor() and possibly even need to add a dummy event listener
first to get everything to work correctly.

Unfortunately, just as with w3c/sensors#487 this requires quite a few
changes, even more so in this specification, which is quite vague when it
comes to connecting to sensors and the lifetimes of such connections.

Some of that behavior is now specified for the virtual sensors case, so that
each Document has a `[[virtualSensorMapping]]` that maps virtual sensor
types to "orientation event platform sensor-likes", a concept borrowed from
Generic Sensor's automation section.

Similarly to that section, the idea is that:
- Whenever the user agent needs to connect to the underlying hardware
  because addEventListener() was called, it first attempts to find a virtual
  sensor, get/create an orientation event platform sensor-like, adds it to
  `[[virtualSensorMapping]]` and to the virtual sensor's connected platform
  sensors set and retrieves any existing readings from the virtual sensor.
- When a Document is being unloaded, all platform sensor-likes in
  `[[virtualSensorMapping]]` are removed from their virtual sensors'
  connected platform sensors set.
- Similarly, when a virtual sensor is removed, any platform sensor-likes in
  its connected platform set have their associated "device sensor" set to
  null.

In the rest of the spec, we switch from attempting to derive a virtual
sensor from the top-level traversable directly to trying to find a suitable
platform sensor-like entry in `[[virtualSensorMapping]]` and checking its
associated virtual sensor when one is set.

Related to: w3c/sensors#478.
@reillyeon
Copy link
Member

Can you update the PR description to include the new pull request template and link to the Chromium issue where the behavior you are specing here was implemented and make sure there are WebKit and Gecko issues for implementing the sensor automation interface as well?

@reillyeon
Copy link
Member

@rakuco have you had a chance to file issues with the other implementers of the DeviceOrientation Events API asking about implementing this automation interface?

@rakuco
Copy link
Member Author

rakuco commented Apr 8, 2024

@rakuco have you had a chance to file issues with the other implementers of the DeviceOrientation Events API asking about implementing this automation interface?

Oops, thanks for the reminder. I'll get back to this issue this week.

@rakuco
Copy link
Member Author

rakuco commented Apr 12, 2024

@reillyeon done. I've updated the PR message to include the contents of .github/PULL_REQUEST_TEMPLATE.md at the top and filed bugs for Gecko and WebKit (dunno if this is enough to tick the corresponding checkboxes).

Do note that this should be reviewed together with w3c/sensors#478.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
rakuco and others added 2 commits April 15, 2024 09:44
Co-authored-by: Reilly Grant <reillyeon@users.noreply.github.com>
Co-authored-by: Reilly Grant <reillyeon@users.noreply.github.com>
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.

None yet

2 participants