- From: Anton Vayvod via GitHub <sysbot+gh@w3.org>
- Date: Thu, 28 May 2015 13:13:32 +0000
- To: public-secondscreen@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): ```javascript <!-- controller.html --> <button id="castBtn" style="display: none;">Cast</button> <script> // it is also possible to use relative presentation URL e.g. "presentation.html" 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 navigator.presentation.getAvailability(presUrl).then(function(availabilityObj) { // availability.current will be updated by the UA as long as the availability // 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() succeeded). availability = availabilityObj; handleAvailabilityChange(); availability.onchange = function() { handleAvailabilityChange(); }; }, function(error) { // background discovery is not supported, let startSession() be called to do one-time discovery. castBtn.style.display = "inline"; }); </script> ``` -- GitHub Notif of comment by avayvod See https://github.com/w3c/presentation-api/issues/81#issuecomment-106305673
Received on Thursday, 28 May 2015 13:13:33 UTC