- From: Shalamov, Alexander <alexander.shalamov@intel.com>
- Date: Mon, 28 Nov 2016 17:48:23 +0200
- To: Felipe Nascimento de Moura <felipenmoura@gmail.com>
- Cc: Marcos Caceres <marcos@marcosc.com>, public-device-apis@w3.org
- Message-ID: <CALO8C-wV0L4Mx5_FjQsno3OxHksr9UTq7VPoN4yUK6mEbbq4Og@mail.gmail.com>
Hi Felipe, Thank you for feedback, the issue that you and Marcos have raised can be split into two problems: 1) Namespacing It provides some benefits, yet it may break discovery API, as there can be multiple sensors of the same type. Please take a look at https://github.com/w3c/sensors/issues/127 and see rationale for dropping namespaces for now. 2) Discovery Tobie made an issue (https://github.com/w3c/sensors/issues/7) that should cover sensor discovery use-cases. With discovery API, developers would be able to call something like "Promise<Sensor[]> Sensor.enumerate(SensorType type?);" to get list of supported sensors then, you can write your darkRoom sensor in a following way: function createDarkRoomSensor() { Promise.all([ Sensor.enumerate("light"), Sensor.enumerate("proximity") ]).then(function([lightSensors, proximitySensors]){ // select what sensors to use or [0] to get first one // create fusion from proximity and ambient light let myDarkRoomSensor = …; return myDarkRoomSensor; }); }); // If you like namespaces. navigator.sensors = { darkRoom: createDarkRoomSensor, light: () => { return Sensor.enumerate("light").then(lights => lights[0]); } } Kind regards, Alexander Shalamov On Fri, Nov 25, 2016 at 3:48 PM, Felipe Nascimento de Moura < felipenmoura@gmail.com> wrote: > Hi. > > Reading this e-mail: http://lists.w3.org/Archives/Public/public-device- > apis/2016Nov/0024.html > I could add now, yet a new different pattern to the list I showed in the > first e-mail: > > ``` > let sensor = new Magnetometer(); // new instance of a global Constructor > sensor.start(); > > sensor.onchange = function(event) { ... }; > ``` > > I think this is the moment for us to think about a `core` for sensors, > like `navigator.sensors....` :) > > > On Thu, Nov 24, 2016 at 1:06 PM, Felipe Nascimento de Moura < > felipenmoura@gmail.com> wrote: > >> > 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.anInexistin >> gSensor().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! >> > > > > -- > [ ]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 Tuesday, 29 November 2016 08:07:38 UTC