Re: Rethinking availability monitoring

Hi Anton,

> On 25 Apr 2015, at 22:03, Anton Vayvod <avayvod@google.com> wrote:
> 
> Having discussed this with Mounir recently, the right approach would be to return an object via Promise that has a bool and an event handler. This way the UA doesn't have to do weird tricks like detect if anything is subscribed to the event to start/stop discovery, there's no compromise between the attribute being initialized or firing the event immediately after a listener is attached and even gives more flexibility if the page wants to filter the events - pass the parameters to the Promise returning method.
> 
> partial interface NavigatorPresentation {
>   Promise<AvailabilityListener> listenForAvailability(/*DOMString presentationUrl, params*/);
> }
> 
> interface AvailabilityListener : EventTarget {
>   readonly attribute boolean available;
>   attribute EventHandler onavailablechange;
> }
> 
> One may need some way to discard the listener to signal the UA that the page is not interested in the screens anymore.
> 
> WDYT?

Thanks, this looks good to me, perhaps with some bikeshedding about naming :-)

We've used a similar design in other specs, for example:

* Battery Status API (http://www.w3.org/TR/battery-status/)
* Permissions API (https://w3c.github.io/permissions/)

... so this has proven to work and is implementable.

Thanks,

-Anssi (WG chair)

Received on Monday, 27 April 2015 15:31:45 UTC