Skip to content

Commit

Permalink
Addressing CR notes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov committed Apr 8, 2016
1 parent 7fa161c commit 719e5f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
48 changes: 26 additions & 22 deletions lib/LocalServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ LocalServer.startServer = function(ports, externalServerUrl, useTunnel) {
localServer.createSocketListener();

if (useTunnel) {
return Q.promise(function(resolve) {
localServer.createTunnel().then(function(){
resolve(localServer);
});
});
return localServer.createTunnel();
}

return localServer;
});
};

LocalServer.getFirstAvailablePort = function(startPort, endPort) {
// returns array range [startPort..endPort]
var ports = Array.apply(null, Array(endPort - startPort + 1)).map(function(element, index) {
return startPort + index;
});
Expand Down Expand Up @@ -91,7 +88,7 @@ LocalServer.prototype.createTunnel = function() {
self.tunneledUrl = tunnel.url;
logger.info('cordova-paramedic: using tunneled url ' + self.tunneledUrl);

resolve();
resolve(self);
});

// this trace is useful to debug test run timeout issue
Expand Down Expand Up @@ -124,25 +121,32 @@ LocalServer.prototype.createSocketListener = function() {
});
};

LocalServer.prototype.getConnectionUrl = function() {
return this.tunneledUrl ||
(this.externalServerUrl ? this.externalServerUrl + ":" + this.port : undefined);
};

LocalServer.prototype.getStandartUrlForPlatform = function(platformId) {
// Connection url could be platform specific so we pass platform as param here
LocalServer.prototype.getConnectionUrl = function(platformId) {
// --useTunnel option
if (this.tunneledUrl) {
return this.tunneledUrl;
}
// --externalServerUrl option / we know ip or dns name
if (this.externalServerUrl) {
return this.externalServerUrl + ":" + this.port;
}
// build connection uri for localhost based on platform
var connectionUrl;

switch(platformId) {
case "android" : connectionUrl = "http://10.0.2.2:";
break;
case "ios" :
case "browser" :
case "windows" :
/* falls through */
default: connectionUrl = "http://127.0.0.1:";
}

return connectionUrl + this.port;
case "android" :
connectionUrl = "http://10.0.2.2";
break;
case "ios" :
case "browser" :
case "windows" :
/* falls through */
default:
connectionUrl = "http://127.0.0.1";
}

return connectionUrl + ":" + this.port;
};

LocalServer.prototype.isDeviceConnected = function() {
Expand Down
3 changes: 1 addition & 2 deletions lib/paramedic.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ ParamedicRunner.prototype.run = function() {
self.injectReporters();
self.subcribeForEvents();

var connectionUrl = server.getConnectionUrl() ||
server.getStandartUrlForPlatform(self.config.getPlatformId());
var connectionUrl = server.getConnectionUrl(self.config.getPlatformId());
self.writeMedicConnectionUrl(connectionUrl);

return self.runTests();
Expand Down
6 changes: 4 additions & 2 deletions paramedic-plugin/paramedic.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Paramedic.prototype.initialize = function() {
this.socket = io.connect(connectionUri);

this.socket.on('connect', function () {
console.log("Paramedic has been susccessfully connected to server");
console.log('Paramedic has been susccessfully connected to server');
if (typeof device != 'undefined') me.socket.emit('deviceInfo', device);
});

Expand Down Expand Up @@ -85,7 +85,9 @@ function loadParamedicServerUrl() {

return cfg.logurl || PARAMEDIC_SERVER_DEFAULT_URL;

} catch (ex) {}
} catch (ex) {
console.log('Unable to load paramedic server url: ' + ex);
}

return PARAMEDIC_SERVER_DEFAULT_URL;
}
Expand Down

0 comments on commit 719e5f8

Please sign in to comment.