You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/09/18 16:47:24 UTC
[5/6] js commit: [android] Have exec() process multiple messages at a
time.
[android] Have exec() process multiple messages at a time.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/34239a8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/34239a8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/34239a8c
Branch: refs/heads/master
Commit: 34239a8c1539370f5d81037c047a6deebe03cf2a
Parents: 74ae56f
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Sep 11 13:27:31 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Sep 18 10:46:48 2012 -0400
----------------------------------------------------------------------
lib/android/exec.js | 11 ++++++-----
lib/android/plugin/android/polling.js | 13 +++----------
2 files changed, 9 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34239a8c/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index 95c9652..3b62fbd 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -98,9 +98,6 @@ function androidExec(success, fail, service, action, args) {
}
function hookOnlineApis() {
- function onOnLineEvent(e) {
- while (polling.pollOnce());
- }
function proxyEvent(e) {
cordova.fireWindowEvent(e.type);
}
@@ -108,8 +105,8 @@ function hookOnlineApis() {
// It currently fires them only on document though, so we bridge them
// to window here (while first listening for exec()-releated online/offline
// events).
- window.addEventListener('online', onOnLineEvent, false);
- window.addEventListener('offline', onOnLineEvent, false);
+ window.addEventListener('online', polling.pollOnce, false);
+ window.addEventListener('offline', polling.pollOnce, false);
cordova.addWindowEventHandler('online');
cordova.addWindowEventHandler('offline');
document.addEventListener('online', proxyEvent, false);
@@ -191,6 +188,10 @@ function processMessage(message) {
// This is called from the NativeToJsMessageQueue.java.
androidExec.processMessages = function(messages) {
while (messages) {
+ if (messages == '*') {
+ window.setTimeout(polling.pollOnce, 0);
+ break;
+ }
var spaceIdx = messages.indexOf(' ');
var msgLen = +messages.slice(0, spaceIdx);
var message = messages.substr(spaceIdx + 1, msgLen);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34239a8c/lib/android/plugin/android/polling.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/polling.js b/lib/android/plugin/android/polling.js
index 89b5f0f..4942b8c 100644
--- a/lib/android/plugin/android/polling.js
+++ b/lib/android/plugin/android/polling.js
@@ -27,22 +27,15 @@ var cordova = require('cordova'),
function pollOnce() {
var exec = require('cordova/exec'),
msg = nativeApiProvider.get().retrieveJsMessages();
- if (msg) {
- exec.processMessages(msg);
- return true;
- }
- return false;
+ exec.processMessages(msg);
}
function doPoll() {
if (!enabled) {
return;
}
- var nextDelay = POLL_INTERVAL;
- if (pollOnce()) {
- nextDelay = 0;
- }
- setTimeout(doPoll, nextDelay);
+ pollOnce();
+ setTimeout(doPoll, POLL_INTERVAL);
}
module.exports = {