You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Shazron Abdullah (JIRA)" <ji...@apache.org> on 2015/12/04 02:51:10 UTC
[jira] [Reopened] (CB-10106) iOS bridges need to take into account
bridge changes
[ https://issues.apache.org/jira/browse/CB-10106?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Shazron Abdullah reopened CB-10106:
-----------------------------------
I'm building a better bridge implementation through a proxy. Gist of it is:
{code}
function exec() {
var cexec = require('cordova/exec');
return (proxy !== cexec)? cexec : iOSExec;
}
function proxy() {
exec().apply(null, arguments);
};
proxy.nativeFetchMessages = function() {
return exec().nativeFetchMessages.apply(null, arguments);
};
proxy.nativeEvalAndFetch = function() {
return exec().nativeEvalAndFetch.apply(null, arguments);
};
proxy.nativeCallback = function() {
return exec().nativeCallback.apply(null, arguments);
};
module.exports = proxy;
// Also
failSafeTimerId = setTimeout(function() {
if (commandQueue.length) {
if (!handleBridgeChange()) {
pokeNative();
}
}
}, 50); // Making this > 0 improves performance (marginally) in the normal case (where it doesn't fire).
// Also
function handleBridgeChange() {
if (proxy !== exec()) {
var commandString = commandQueue.shift();
while(commandString) {
var command = JSON.parse(commandString);
var callbackId = command[0];
var service = command[1];
var action = command[2];
var actionArgs = command[3];
var callbacks = cordova.callbacks[callbackId] || {};
exec()(callbacks.success, callbacks.fail, service, action, actionArgs);
commandString = commandQueue.shift();
};
return true;
}
return false;
}
{code}
> iOS bridges need to take into account bridge changes
> ----------------------------------------------------
>
> Key: CB-10106
> URL: https://issues.apache.org/jira/browse/CB-10106
> Project: Apache Cordova
> Issue Type: Bug
> Components: iOS, Plugin WKWebViewEngine
> Reporter: Shazron Abdullah
> Assignee: Shazron Abdullah
> Labels: cordova-ios-4.0.x
>
> New bridges (and the existing bridge) needs to take into account bridge changes.
> Each bridge should have this at the end of their .js:
> {code}
> // unregister the old bridge
> cordova.define.remove('cordova/exec');
> // redefine bridge to our new bridge
> cordova.define("cordova/exec", function(require, exports, module) {
> module.exports = iOSExec;
> });
> {code}
> But, this would only re-define cordova.exec and the return value of `require('cordova/exec')`. However, if the bridge was not loaded first, existing local references in plugins to `require('cordova/exec')` will not be updated.
> Therefore, each bridge itself must detect that it is not the current bridge, and forward commands to the new bridge. Thus:
> {code}
> var iOSExec = function() {
> if (iOSExec !== cordova.exec) {
> cordova.exec.apply(null, arguments);
> return;
> }
> // ... rest of the implementation here...
> }
> {code}
> Although I see this being a problem of the default bridge, not any external bridges.
> There might be an edge case where a command is already in the commandQueue (default bridge) when the bridge is swapped, that needs to be handled.
> I realize this seems hacky, but if there's a better way to handle this case I'm all ears.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org