Re: Network Information API

On Thursday, December 19, 2013 at 1:18 PM, Mats Wichmann wrote:

> As I re-read that last bit it felt like I'm asking a question while
> suggesting some answer is more favored but that's just clumsy wording
> which I don't quite see how to improve, I really just mean to ask the
> question: if the conditions aren't technically perfect to standardize,
> as a W3C project, where do we stand on this kind of dilemma?

I guess where we are now. Trying to figure out if we do anything at all by throwing use cases, data, and citations at each other :)   

I think we’ve gotten to a good place through this process, though. I’d be happy to draft up and alternative API design based on the discussions we’ve had.  

Something like:

interface NetInfo : EventTarget{
   readonly attribute ConnectionType connection;
   readonly attribute onconnectionchange;  
}

//We can add new types as needed in the future - disabled can be a stand in for “airplane” mode or similar user-controlled network disconnect.  
  
enum ConnectionType{ “wifi”, “cellular”, “disabled”}



partial interface Navigator{
    readonly attribute NetInfo netInfo;  
}


Then it’s composable with other APIs  - like battery status, to address Tobie’s use cases of being able to make smarter decisions about when to sync (FWIW, I think having better primitives that devs can work with would be better than deferring all this to the UA - at least initially till we see clear usage patterns):

window.onload = (e) => {
var battery = navigator.battery,
      netInfo = navigator.netInfo;
if(!battery.charging  && netInfo.connection === prefs.preferredSyncConnectionType){
   //do synchronization     
}
}


//Stop transferring data when discharging  
battery.addEventListener(“chargingchange”, (e) => {
   if(battery.charging && app.isSyncing){
    app.stopSync();  
   }
});


netInfo.addEventListener(“connectionchange”, (e) =>{
   if(NetInfo.connection === “cellular” && fetchQueue.state === “fetching"){
      fetchQueue.pauseAllDownloads().then(confirmProceedWithUser).then(fetchQueue.resume);  
  }
} );

Received on Thursday, 9 January 2014 05:01:02 UTC