From d68aa09c11bc3d846e3754244d8af761736b210e Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Thu, 25 Sep 2014 21:01:40 -0700 Subject: [PATCH] WIP --- packages/autoupdate/autoupdate_cordova.js | 23 ++------------- packages/meteor-platform/package.js | 2 +- tools/client/meteor_cordova_loader.js | 36 ++++++----------------- 3 files changed, 13 insertions(+), 48 deletions(-) diff --git a/packages/autoupdate/autoupdate_cordova.js b/packages/autoupdate/autoupdate_cordova.js index a649236ed1..9ae7359fc6 100644 --- a/packages/autoupdate/autoupdate_cordova.js +++ b/packages/autoupdate/autoupdate_cordova.js @@ -38,23 +38,16 @@ var writeFile = function (directoryPath, fileName, content, cb) { var restartServer = function (location) { console.log(DEBUG_TAG + 'restartserver with location ' + location); var fail = function (err) { console.log(DEBUG_TAG + 'something failed: ' + err.message) }; - var httpd = cordova && cordova.plugins && cordova.plugins.CorHttpd; + var httpd = cordova && cordova.plugins && cordova.plugins.CordovaUpdate; if (! httpd) { fail(new Error('no httpd')); return; } - var startServer = function (cordovajsRoot, prevUrl) { - var port; - if (prevUrl) { - var parts = prevUrl.split(':'); - if (parts.length) - port = parseInt(parts[parts.length - 1], 10); - } + var startServer = function (cordovajsRoot) { httpd.startServer({ 'www_root' : location, - 'port' : port, 'cordovajs_root': cordovajsRoot }, function (url) { Package.reload.Reload._reload(); @@ -62,17 +55,7 @@ var restartServer = function (location) { }; httpd.getCordovajsRoot(function (cordovajsRoot) { - httpd.getURL(function (url) { - if (url.length > 0) { - // already have a server running, stop it - httpd.stopServer(function () { - startServer(cordovajsRoot, url); - }, fail); - } else { - // just start a server - startServer(cordovajsRoot); - } - }, fail); + startServer(cordovajsRoot); }, fail); }; diff --git a/packages/meteor-platform/package.js b/packages/meteor-platform/package.js index df944b8927..c9c6014317 100644 --- a/packages/meteor-platform/package.js +++ b/packages/meteor-platform/package.js @@ -68,5 +68,5 @@ Package.on_use(function(api) { Cordova.depends({ 'org.apache.cordova.device': '0.2.11', - 'com.rjfun.cordova.httpd': 'https://github.com/meteor/cordova-httpd/tarball/f68bcb43be30878823718bcd01bd6d97561eb337' + 'com.meteor.cordova-update': 'https://github.com/meteor/com.meteor.cordova-update/tarball/9eddfcc144e8eb523c2b8d317f8837346435b1a6' }); diff --git a/tools/client/meteor_cordova_loader.js b/tools/client/meteor_cordova_loader.js index f90278135e..0fae5e05bf 100644 --- a/tools/client/meteor_cordova_loader.js +++ b/tools/client/meteor_cordova_loader.js @@ -42,15 +42,10 @@ return p.slice(1); }; - var randomInt = function (min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; - }; - var loadTries = 0; var loadFromLocation = function (location) { var cordovaRoot = decodeURI(window.location.href).replace(/\/index.html$/, '/').replace(/^file:\/\/?/, ''); - var httpd = cordova && cordova.plugins && cordova.plugins.CorHttpd; - var port = randomInt(10000, 50000); + var httpd = cordova && cordova.plugins && cordova.plugins.CordovaUpdate; var retry = function () { loadTries++; @@ -62,27 +57,14 @@ } }; - httpd.getURL(function(url){ - if (url.length > 0) { - // if server is already running, stop it and retry - httpd.stopServer(retry, retry); - } else { - console.log(DEBUG_TAG + 'Starting the server on port ' + port); - httpd.startServer({ - 'www_root' : location, - 'port' : port, - 'cordovajs_root': cordovaRoot - }, function (url) { - // go to the new proxy url - window.location = url; - }, function (error) { - // failed to start a server, is port already in use? - retry(); - }); - } - - }, function () { - // failed to call to server: retry + httpd.startServing({ + 'www_root' : location, + 'cordovajs_root': cordovaRoot + }, function (url) { + // go to the new proxy url + window.location = url; + }, function (error) { + // failed to start a server, is port already in use? retry(); }); };