Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions node-phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports={
callback(hasErrors,phantom);
},100);
}

var server=http.createServer(function(request,response){
response.writeHead(200,{"Content-Type": "text/html"});
response.end('<html><head><script src="/socket.io/socket.io.js" type="text/javascript"></script><script type="text/javascript">\n\
Expand All @@ -55,9 +55,14 @@ module.exports={
window.socket = socket;\n\
};\n\
</script></head><body></body></html>');
}).listen(function(){
}).listen(function(){
var io=socketio.listen(server,{'log level':1});


// Force XHR polling
io.set('transports', [
'xhr-polling'
]);

var port=server.address().port;
spawnPhantom(port,function(err,phantom){
if(err){
Expand All @@ -72,11 +77,11 @@ module.exports={
args.splice(1,0,cmdid);
// console.log('requesting:'+args);
socket.emit('cmd',JSON.stringify(args));

cmds[cmdid]={cb:callback};
cmdid++;
}

io.sockets.on('connection',function(socket){
socket.on('res',function(response){
// console.log(response);
Expand Down Expand Up @@ -208,17 +213,17 @@ module.exports={
},
_phantom: phantom
};

callback(null,proxy);
});

// An exit event listener that is registered AFTER the phantomjs process
// is successfully created.
var prematureExitHandler=function(code,signal){
console.warn('phantom crash: code '+code);
server.close();
};

phantom.on('exit',prematureExitHandler);
});
});
Expand Down