-
Notifications
You must be signed in to change notification settings - Fork 59
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
Should the enum SensorState have nosensor ? #104
Comments
I think "errored" state suffices as of now, till we work on the Discovery part (with remote sensors) in more detail in v2. So, idle -> errored, when there is no relevant hardware sensor. |
Given we're focusing on local sensors only at this point, the absence or presence of sensors should be know upfront. In this case, the constructor would throw (this is already specified in the spec). If there are concrete cases where sensors go MIA, then we can report this with an error event. Is this something that's already showing up during implementation, @riju? |
It might not be possible to implement the constructor in a non-blocking manner if we require implementations to throw a
Figuring out whether there's underlying sensor hardware requires crossing process boundary (at least in Blink, and I guess similarly in other modern engines) and sync IPC should be avoided. That said, @riju and @alexshalamov will experiment with Blink to see if this implementation feedback should motivate spec changes and will update this issue accordingly. |
Correct, in chrome it would be impossible to do the "sensor present" check upon construction in a non-blocking way, and we should not make any blocking calls for this anyway. Pre-checking sensor upon startup seems too much overhead. So I think "errored" state kind of makes sense. Maybe there should be enums for "errors" though.. "relevant sensor(s) not available" is a pretty common case and it would probably make sense for the developers to test that quickly. |
OK, I somehow assumed that a startup pre-check would be standard and cheap. I'll revamp [[Construct Sensor Object]] accordingly and see what incidences, if any, this has on requesting user permission. I was planning on using the |
I guess the first start() invocation will trigger user permission when necessary. |
Oh, that's interesting. I had imagined user permission would be triggered during construction (and would fire an "error" event should permission not be granted). Might make sense to tie it to The other option is for construction to trigger a sensor presence check and fire an error if it's missing. |
We're converging on:
interface Sensor : EventTarget {
readonly attribute SensorReading? reading;
void start();
void stop();
attribute EventHandler onchange;
attribute EventHandler onactivate;
attribute EventHandler onerror;
}; In order to come to the above conclusions, we experimented with the following code examples: Promise basedThe key issue here is you still need to register an error handler here to catch errors after the start promise gets resolved, but you must either remove duplicate error messages, or only setup the handler after promise completion. let g = new Gyroscope({frequency: 60});
function loop() {
console.log(g.reading);
requestAnimationFrame(loop)
}
g.start().then(_ => requestAnimationFrame(loop), err => {
if (err.name == "NotReadableError")
alert("you don't have a gyro!");
else if (err.name == "NotAllowedError")
alert("Give me the gyro!");
}); With
|
This fixes a number of pending issues listed below, for which there was consensus, but editing was still pending. This introduces a dependency on the infra standard [[INFRA]], to define precisely the low-level data structures used by slots and concepts. This also specifies slots more clearly. Additionally, this rewrite sprinkles inline issues in areas of the specs which require more work. * Handle GC issues by getting rid of the SensorReading interface. Closes w3c#153. Closes w3c#101. * Check sensor existence before requesting permission. Closes w3c#145. * Remove side effects from constructors. Closes w3c#138. * Move default sensor check to start() and add "unconnected" state. Closes w3c#128 and closes w3c#104. * Throttle update frequency to 60Hz by relying on requestAnimationFrame. Closes w3c#100.
This fixes a number of pending issues listed below, for which there was consensus, but editing was still pending. This introduces a dependency on the infra standard [[INFRA]], to define precisely the low-level data structures used by slots and concepts. This also specifies slots more clearly. Additionally, this rewrite sprinkles inline issues in areas of the specs which require more work. * Handle GC issues by getting rid of the SensorReading interface. Closes #153. Closes #101. * Check sensor existence before requesting permission. Closes #145. * Remove side effects from constructors. Closes #138. * Move default sensor check to start() and add "unconnected" state. Closes #128 and closes #104. * Throttle update frequency to 60Hz by relying on requestAnimationFrame. Closes #100.
@timvolodine asked : should there be something corresponding to 'there is no relevant hardware
sensor'?
See #104 (comment) for resolutions.
The text was updated successfully, but these errors were encountered: