Skip to content

Commit

Permalink
[android] Delete callback server.
Browse files Browse the repository at this point in the history
Also folds polling into exec.js
  • Loading branch information
agrieve committed Sep 28, 2012
1 parent 968764b commit 01a2683
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 165 deletions.
35 changes: 20 additions & 15 deletions lib/android/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -126,19 +134,16 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
return;
}
if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
polling.stop();
} else if (nativeToJsBridgeMode == nativeToJsModes.HANGING_GET) {
callback.stop();
pollEnabled = false;
}

nativeToJsBridgeMode = mode;
// Tell the native side to switch modes.
nativeApiProvider.get().setNativeToJsBridgeMode(mode);

if (mode == nativeToJsModes.POLLING) {
polling.start();
} else if (mode == nativeToJsModes.HANGING_GET) {
callback.start();
pollEnabled = true;
setTimeout(pollingTimerFunc, 1);
}
};

Expand Down Expand Up @@ -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(' ');
Expand Down
10 changes: 0 additions & 10 deletions lib/android/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand Down
89 changes: 0 additions & 89 deletions lib/android/plugin/android/callback.js

This file was deleted.

51 changes: 0 additions & 51 deletions lib/android/plugin/android/polling.js

This file was deleted.

0 comments on commit 01a2683

Please sign in to comment.