WebAPI/BatteryAPI: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| style="color:red; font-weight: bold; background-color:yellow; padding:0px; margin: 20px; border: red;" cellpadding="0" cellspacing="0" border="1"
|This wiki page is out of date.<br>
The work on Battery API has been moved to the official W3C specification in the DAP Working Group: http://www.w3.org/TR/battery-status/
|}
== Device API specification ==
== Device API specification ==


The DAP WG (W3C) has specification sharing this proposal goal [1]. For the moment, the Battery API proposal might or might not look like the DAP specification.
The DAP WG (W3C) has specification sharing this proposal goal [1]. The specification recently moved to match our proposal. So, most of it should look like the proposed API below.


[1] http://www.w3.org/TR/2011/WD-battery-status-20110915/
[1] http://www.w3.org/TR/2011/WD-battery-status-20110915/
Line 11: Line 15:
== Demo ==
== Demo ==


You can find a demo at this URL:<br>
You can find a demo at these URLs:<br>
http://oldworld.fr/mozilla/battery.html
* http://oldworld.fr/mozilla/battery.html
* http://oldworld.fr/mozilla/battery-test.html
* [http://robnyman.github.com/battery/ Demo by Robert Nyman]


== Proposed API ==
== Proposed API ==
Line 21: Line 27:
     readonly attribute boolean  charging;
     readonly attribute boolean  charging;
     readonly attribute float    level;
     readonly attribute float    level;
    readonly attribute DOMString status;
 
            attribute Function? onchargingchange;
            attribute Function? onlevelchange;
   }
   }


window.navigator.mozBattery will return ''null'' if the device has no battery.
The charging attribute will return true if the device is currently charging and false otherwise. True if there is no battery or if this information is not available.<br>
 
The level attribute will return the current battery level of the device from 0.0 to 1.0. 1.0 if there is no battery or if this information is not available.<br>
The charging attribute will return true if the device is currently charging and false otherwise.<br>
The level attribute will return the current battery level of the device from 0.0 to 100.0.<br>
The status attribute will return whether "critical", "low" or "ok" depending on the battery level.<br>


The following events can be sent to the mozBattery object:
The following events can be sent to the mozBattery object:
   ''chargingchange'': when the charging state changes;
   ''chargingchange'': when the charging state changes;
   ''levelchange'': when the level value changes of at least 1.0;
   ''levelchange'': when the level value changes of at least 0.01;
  ''statuschange'': when the status changes.


== Considered changes ==
== Considered changes ==
Line 41: Line 45:
** In that case, we could allow authors to set the low and critical values threshold;
** In that case, we could allow authors to set the low and critical values threshold;
** In that case, not having a battery should be handled differently;
** In that case, not having a battery should be handled differently;
[[Category:Web APIs]]

Latest revision as of 23:48, 1 October 2014

This wiki page is out of date.

The work on Battery API has been moved to the official W3C specification in the DAP Working Group: http://www.w3.org/TR/battery-status/

Device API specification

The DAP WG (W3C) has specification sharing this proposal goal [1]. The specification recently moved to match our proposal. So, most of it should look like the proposed API below.

[1] http://www.w3.org/TR/2011/WD-battery-status-20110915/

Status

The proposed specification has a working implementation in bug 678694. From this implementation, we will request feedbacks for changes.

Demo

You can find a demo at these URLs:

Proposed API

There is an object in window.navigator named mozBattery with the following interface:

 interface BatteryManager : EventTarget
 {
   readonly attribute boolean   charging;
   readonly attribute float     level;
 
            attribute Function? onchargingchange;
            attribute Function? onlevelchange;
 }

The charging attribute will return true if the device is currently charging and false otherwise. True if there is no battery or if this information is not available.
The level attribute will return the current battery level of the device from 0.0 to 1.0. 1.0 if there is no battery or if this information is not available.

The following events can be sent to the mozBattery object:

 chargingchange: when the charging state changes;
 levelchange: when the level value changes of at least 0.01;

Considered changes

  • mozBattery object might move to window.navigator.device;
  • Instead of having a mozBattery object in navigator.* we could instantiate an object with new mozBatteryStatus();
    • In that case, we could allow authors to set the low and critical values threshold;
    • In that case, not having a battery should be handled differently;