lib/terminus/client/phantom.js in terminus-0.4.0 vs lib/terminus/client/phantom.js in terminus-0.5.0
- old
+ new
@@ -1,6 +1,28 @@
-var page = new WebPage(),
- host = phantom.args[0],
- port = phantom.args[1];
+var page = new WebPage(),
+ width = phantom.args[0],
+ height = phantom.args[1],
+ host = phantom.args[2],
+ port = phantom.args[3],
+ socket = phantom.args[4];
+var Commands = {
+ save_screenshot: function(path, options, callback) {
+ page.render(path);
+ callback(true);
+ }
+};
+
+var ws = new WebSocket('ws://' + host + ':' + socket + '/');
+ws.onmessage = function(message) {
+ var args = JSON.parse(message.data),
+ method = args.shift();
+
+ args.push(function(result) {
+ ws.send(JSON.stringify([result]));
+ });
+ Commands[method].apply(Commands, args);
+};
+
+page.viewportSize = {width: parseInt(width, 10), height: parseInt(height, 10)};
page.open('http://' + host + ':' + port + '/');