Hi all,

I just landed RequestSync API, an API for b2g only that allows apps to
schedule tasks.
Here the webIDL:

https://hg.mozilla.org/integration/mozilla-inbound/file/f60d4ad64070/dom/webidl/RequestSyncScheduler.webidl

A simple example is this:

    navigator.sync.register('foobar', { minInterval: 2,
                                         oneShot: true,
                                         data: 42,
                                         wifiOnly: false,
                                         wakeUpPage: location.href }).then(
    function() {
      ok(true, "navigator.sync.register() oneShot done");
      ...
    }, genericError);

  navigator.mozSetMessageHandler('request-sync', function(e) {
      ok(true, "One event has been received!");
      is (e.task, "foobar");
      ...
  });

The params are:
1. minInterval - in seconds. It can happen that this operation will be
scheduled with a bigger interval.
2. oneShot - true/false, similar to setInterval/setTimeout.
3. data: whatever you want to pass to the message handler.
4. wifiOnly: if true, the task will not scheduled if wifi is not active
5. wakeUpPage: the page that will receive the system message.


We also have a 'setting' API accessible only if the app has the
'requestsync-manager' permission.
This is the webIDL:

https://hg.mozilla.org/integration/mozilla-inbound/file/f60d4ad64070/dom/webidl/RequestSyncManager.webidl

With this API the settings app can overwrite the policy and the minInterval
of any task of any app:

  navigator.syncManager.registrations().then(
    function(results) {
      ...
      results[0].setPolicy("wifiOnly", 123 /* minInterval */);
    });

More documentation (not up-to-date yet):
https://etherpad.mozilla.org/syncAPI

b
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to