- From: Felipe Nascimento de Moura <felipenmoura@gmail.com>
- Date: Thu, 24 Nov 2016 13:06:06 -0200
- To: Marcos Caceres <marcos@marcosc.com>
- Cc: public-device-apis@w3.org
- Message-ID: <CAJVBkV=SkSnfET5SBHv6GWV+ff3Q7agn9KAYXOM=DyYLLpOq8Q@mail.gmail.com>
> https://github.com/w3c/sensors ... some are already supported in Chrome
;)
nice, I have already done some tests with the currently supported ones, but
even though, I think an aggregator for all the sensors is very important.
Even for hacking and discoverability.
navigator.sensors.tirePressure().then( ... )
Actually, navigator.sensors could even have a "getter" for any method that
does not exist to return a rejected promise, instead of a "undefined is not
a function" error.
This way, calling
`navigator.sensors.anInexistingSensor().then(...).catch(...)` would reject
until the sensors was created or supported.
Thinking it further, we could even have a `navigator.sensors.create` with a
pattern for developers to create their own sensors based in other
information...let's say:
```
navigator.sensors.create("darkRoom", function(mySensor){
Promise.all([
navigator.sensors.light(),
navigator.sensors.proximity()
]).then(function([lightSensor, proximitySensor]){
// combine lightSensor and proximity to identify when the room is dark
// and the device is not inside a pocket, for example
// you can dispatch events here on mySensor
});
});
// then, afterwards
navigator.sensors.darkRoom().then(darkRoomSensor=>{
darkRoomSensor.addEventListener(...);
});
```
Did I go too far? :p
On Thu, Nov 24, 2016 at 3:04 AM, Marcos Caceres <marcos@marcosc.com> wrote:
> On November 24, 2016 at 3:41:07 PM, Felipe Nascimento de Moura
> (felipenmoura@gmail.com) wrote:
> > I think I should be able to type "navigator.sensors" in my console and
> see
> > even an autocomplete with the possibilities.
>
> https://github.com/w3c/sensors ... some are already supported in Chrome
> ;)
>
--
[ ]s
*--*
*Felipe N. Moura*
Web Developer, Google Developer Expert
<https://developers.google.com/experts/people/felipe-moura>, Founder of
BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>.
Website: http://felipenmoura.com / http://nasc.io/
Twitter: @felipenmoura <http://twitter.com/felipenmoura>
Facebook: http://fb.com/felipenmoura
LinkedIn: http://goo.gl/qGmq
---------------------------------
*Changing the world* is the least I expect from myself!
Received on Thursday, 24 November 2016 15:07:19 UTC