Add a call back for socket disconnect so that we wait for socket to fully disconnect before trying to reconnect.

This commit is contained in:
Sergio Neves Barros
2013-10-15 18:02:46 +01:00
parent 1fd5822c93
commit 7601dc9e1c
2 changed files with 17 additions and 7 deletions
+9 -1
View File
@@ -35,6 +35,7 @@ var WebKitRemoteDebugger = function(onDisconnect) {
this.dataMethods = {};
this.host = 'localhost';
this.port = 27753;
this.socketDisconnectCb = null;
this.init(1, onDisconnect);
};
@@ -58,6 +59,10 @@ WebKitRemoteDebugger.prototype.connect = function(pageId, cb, pageChangeCb) {
this.socket.on('close', function() {
logger.info("Disconnecting from remote debugger");
this.socket = null;
if(this.socketDisconnectCb){
this.socketDisconnectCb();
this.socketDisconnectCb = null;
}
}.bind(this));
this.socket.on('error', function(exception) {
console.log('Debugger web socket error %s', exception);
@@ -68,9 +73,12 @@ WebKitRemoteDebugger.prototype.connect = function(pageId, cb, pageChangeCb) {
}.bind(this));
};
WebKitRemoteDebugger.prototype.disconnect = function() {
WebKitRemoteDebugger.prototype.disconnect = function(cb) {
if(this.isConnected()){
this.socket.close(1001);
this.socketDisconnectCb = cb;
} else {
cb();
}
};
+8 -6
View File
@@ -1956,6 +1956,7 @@ IOS.prototype.getWindowHandles = function(cb) {
};
IOS.prototype.setWindow = function(name, cb) {
var me = this;
if (_.contains(_.pluck(this.windowHandleCache, 'id'), name)) {
var pageIdKey = parseInt(name, 10);
var next = function() {
@@ -1977,12 +1978,13 @@ IOS.prototype.setWindow = function(name, cb) {
, value: name
});
} else if (_.contains(_.pluck(this.windowHandleCache, 'id'), name)) {
this.remote.disconnect();
this.curWindowHandle = name;
this.remote.connect(name, function(){
cb(null, {
status: status.codes.Success.code
, value: name
this.remote.disconnect(function(){
me.curWindowHandle = name;
me.remote.connect(name, function(){
cb(null, {
status: status.codes.Success.code
, value: name
});
});
});
} else {