incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject js commit: [android] Delete callback server.
Date Fri, 28 Sep 2012 18:38:02 GMT
Updated Branches:
  refs/heads/master 968764b2f -> 01a2683ad


[android] Delete callback server.

Also folds polling into exec.js


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/01a2683a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/01a2683a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/01a2683a

Branch: refs/heads/master
Commit: 01a2683adffd6198f6d28344b1d2c87ba98023b7
Parents: 968764b
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Sep 28 14:35:00 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Sep 28 14:35:00 2012 -0400

----------------------------------------------------------------------
 lib/android/exec.js                    |   35 ++++++-----
 lib/android/platform.js                |   10 ---
 lib/android/plugin/android/callback.js |   89 ---------------------------
 lib/android/plugin/android/polling.js  |   51 ---------------
 4 files changed, 20 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/01a2683a/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index fd6cd3f..e3fbf4f 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -34,8 +34,6 @@
  * @param {String[]} [args]     Zero or more arguments to pass to the method
  */
 var cordova = require('cordova'),
-    callback = require('cordova/plugin/android/callback'),
-    polling = require('cordova/plugin/android/polling'),
     nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
     jsToNativeModes = {
         PROMPT: 0,
@@ -48,9 +46,6 @@ var cordova = require('cordova'),
     nativeToJsModes = {
         // Polls for messages using the JS->Native bridge.
         POLLING: 0,
-        // Does an XHR to a local server, which will send back messages. This is
-        // broken on ICS when a proxy server is configured.
-        HANGING_GET: 1,
         // For LOAD_URL to be viable, it would need to have a work-around for
         // the bug where the soft-keyboard gets dismissed when a message is sent.
         LOAD_URL: 2,
@@ -64,7 +59,8 @@ var cordova = require('cordova'),
         PRIVATE_API: 4
     },
     jsToNativeBridgeMode,  // Set lazily.
-    nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT;
+    nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT
+    pollEnabled = false;
 
 function androidExec(success, fail, service, action, args) {
     // Set default bridge modes if they have not already been set.
@@ -91,6 +87,18 @@ function androidExec(success, fail, service, action, args) {
     }
 }
 
+function pollOnce() {
+    var msg = nativeApiProvider.get().retrieveJsMessages();
+    androidExec.processMessages(msg);
+}
+
+function pollingTimerFunc() {
+    if (pollEnabled) {
+      pollOnce();
+      setTimeout(pollingTimerFunc, 50);
+    }
+}
+
 function hookOnlineApis() {
     function proxyEvent(e) {
         cordova.fireWindowEvent(e.type);
@@ -99,8 +107,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', polling.pollOnce, false);
-    window.addEventListener('offline', polling.pollOnce, false);
+    window.addEventListener('online', pollOnce, false);
+    window.addEventListener('offline', pollOnce, false);
     cordova.addWindowEventHandler('online');
     cordova.addWindowEventHandler('offline');
     document.addEventListener('online', proxyEvent, false);
@@ -126,9 +134,7 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
         return;
     }
     if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
-        polling.stop();
-    } else if (nativeToJsBridgeMode == nativeToJsModes.HANGING_GET) {
-        callback.stop();
+        pollEnabled = false;
     }
 
     nativeToJsBridgeMode = mode;
@@ -136,9 +142,8 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
     nativeApiProvider.get().setNativeToJsBridgeMode(mode);
 
     if (mode == nativeToJsModes.POLLING) {
-        polling.start();
-    } else if (mode == nativeToJsModes.HANGING_GET) {
-        callback.start();
+        pollEnabled = true;
+        setTimeout(pollingTimerFunc, 1);
     }
 };
 
@@ -183,7 +188,7 @@ function processMessage(message) {
 androidExec.processMessages = function(messages) {
     while (messages) {
         if (messages == '*') {
-            window.setTimeout(polling.pollOnce, 0);
+            window.setTimeout(pollOnce, 0);
             break;
         }
         var spaceIdx = messages.indexOf(' ');

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/01a2683a/lib/android/platform.js
----------------------------------------------------------------------
diff --git a/lib/android/platform.js b/lib/android/platform.js
index b2cde22..22e5064 100644
--- a/lib/android/platform.js
+++ b/lib/android/platform.js
@@ -86,16 +86,6 @@ module.exports = {
         }, [channel.onCordovaReady]);
     },
     objects: {
-        cordova: {
-            children: {
-                JSCallback:{
-                    path:"cordova/plugin/android/callback"
-                },
-                JSCallbackPolling:{
-                    path:"cordova/plugin/android/polling"
-                }
-            }
-        },
         navigator: {
             children: {
                 app:{

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/01a2683a/lib/android/plugin/android/callback.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/callback.js b/lib/android/plugin/android/callback.js
deleted file mode 100644
index a87a645..0000000
--- a/lib/android/plugin/android/callback.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var port = null,
-    token = null,
-    xmlhttp;
-
-function startXhr() {
-    // cordova/exec depends on this module, so we can't require cordova/exec on the module
level.
-    var exec = require('cordova/exec'),
-    xmlhttp = new XMLHttpRequest();
-
-    // Callback function when XMLHttpRequest is ready
-    xmlhttp.onreadystatechange=function(){
-        if (!xmlhttp) {
-            return;
-        }
-        if (xmlhttp.readyState === 4){
-            // If callback has JavaScript statement to execute
-            if (xmlhttp.status === 200) {
-
-                // Need to url decode the response
-                var msg = decodeURIComponent(xmlhttp.responseText);
-                setTimeout(startXhr, 1);
-                exec.processMessages(msg);
-            }
-
-            // If callback ping (used to keep XHR request from timing out)
-            else if (xmlhttp.status === 404) {
-                setTimeout(startXhr, 10);
-            }
-
-            // 0 == Page is unloading.
-            // 400 == Bad request.
-            // 403 == invalid token.
-            // 503 == server stopped.
-            else {
-                console.log("JSCallback Error: Request failed with status " + xmlhttp.status);
-                exec.setNativeToJsBridgeMode(exec.nativeToJsModes.POLLING);
-            }
-        }
-    };
-
-    if (port === null) {
-        port = prompt("getPort", "gap_callbackServer:");
-    }
-    if (token === null) {
-        token = prompt("getToken", "gap_callbackServer:");
-    }
-    xmlhttp.open("GET", "http://127.0.0.1:"+port+"/"+token , true);
-    xmlhttp.send();
-}
-
-module.exports = {
-    start: function() {
-        startXhr();
-    },
-
-    stop: function() {
-        if (xmlhttp) {
-            var tmp = xmlhttp;
-            xmlhttp = null;
-            tmp.abort();
-        }
-    },
-
-    isAvailable: function() {
-        return ("true" != prompt("usePolling", "gap_callbackServer:"));
-    }
-};
-

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/01a2683a/lib/android/plugin/android/polling.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/polling.js b/lib/android/plugin/android/polling.js
deleted file mode 100644
index 4942b8c..0000000
--- a/lib/android/plugin/android/polling.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var cordova = require('cordova'),
-    nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
-    POLL_INTERVAL = 50,
-    enabled = false;
-
-function pollOnce() {
-    var exec = require('cordova/exec'),
-        msg = nativeApiProvider.get().retrieveJsMessages();
-    exec.processMessages(msg);
-}
-
-function doPoll() {
-    if (!enabled) {
-        return;
-    }
-    pollOnce();
-    setTimeout(doPoll, POLL_INTERVAL);
-}
-
-module.exports = {
-    start: function() {
-        enabled = true;
-        setTimeout(doPoll, 1);
-    },
-    stop: function() {
-        enabled = false;
-    },
-    pollOnce: pollOnce
-};
-


Mime
View raw message