Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-10106

iOS bridges need to take into account bridge changes

    XMLWordPrintableJSON

Details

    Description

      New bridges (and the existing bridge) needs to take into account bridge changes.

      Each bridge should have this at the end of their .js:

      // 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;
      });
      

      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:

      var iOSExec = function() {
            if (iOSExec !== cordova.exec) {
                cordova.exec.apply(null, arguments);
                return;
            }
      
      // ... rest of the implementation here...
      }
      

      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.

      Attachments

        Issue Links

          Activity

            People

              shazron Shazron Abdullah
              shazron Shazron Abdullah
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: