W3C home > Mailing lists > Public > public-secondscreen@w3.org > May 2015

Re: [presentation-api] Rethinking availability monitoring

From: Anton Vayvod via GitHub <sysbot+gh@w3.org>
Date: Thu, 28 May 2015 13:13:32 +0000
To: public-secondscreen@w3.org
Message-ID: <issue_comment.created-106305673-1432818811-sysbot+gh@w3.org>
Hi, IIRC we actually started looking at the second proposal and 
dismissed it in favor of the first one (the second one doesn't solve 
the problem with the event firing without actual state change, etc). 
For power saving platforms/implementations (e.g. mobile phones), we 
agreed that listenForAvailability() would reject the Promise and let 
the page know this way that it the discovery will run on demand when 
startSession() is called (so the page would show the Present button in
 'try-me' state). This would match the Android behavior towards WiFi 
Direct discovery and discovery on Samsung devices as I understood.

The example code would be then (based on in progress change at [my 
GitHub repo](https://avayvod.github.io/availability.html):


<!-- controller.html -->
<button id="castBtn" style="display: none;">Cast</button>
  // it is also possible to use relative presentation URL e.g. 
  var presUrl = "http://example.com/presentation.html";
  // the cast button is visible if at least one presentation display 
is available
  var castBtn = document.getElementById("castBtn");
  // the availability listener object.
  var availability = null;
  // show or hide cast button depending on display availability
  var handleAvailabilityChange = function() {
    castBtn.style.display = availability.current ? "inline" : "none";
  // availablechange event is fired when the presentation display 
availability changes
    // availability.current will be updated by the UA as long as the 
    // object is alive. It is advised for the web developers to 
discard of the object
    // as soon as it's not needed (e.g. when startSession() 
    availability = availabilityObj;
    availability.onchange = function() { handleAvailabilityChange(); 
  }, function(error) {
    // background discovery is not supported, let startSession() be 
called to do one-time discovery.
    castBtn.style.display = "inline";

GitHub Notif of comment by avayvod
Received on Thursday, 28 May 2015 13:13:33 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 28 May 2015 13:13:34 UTC