Created
February 13, 2012 22:41
-
-
Save jkp/1821143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var connect = require('connect'); | |
| var http = require('http'); | |
| var phantom = require('phantom'); | |
| var websocket = require("websocket-server"); | |
| var httpServer = connect.createServer(connect.static(__dirname + "/..")); | |
| httpServer.listen(8000); | |
| var wsServer = websocket.createServer(); | |
| wsServer.addListener("connection", function(connection){ | |
| connection.addListener("message", function(message){ | |
| console.log(message); | |
| var delimiter = message.indexOf(':'); | |
| var id = message.substring(0, delimiter); | |
| connection.send(id + '+{"foo":1, "bar":2}'); | |
| }); | |
| }); | |
| wsServer.listen(5563); | |
| phantom.create(function(browser) { | |
| console.log('Phantom: browser created.'); | |
| browser.createPage(function(page) { | |
| console.log('Phantom: page created.'); | |
| page.set('settings.localToRemoteUrlAccessEnabled', true); | |
| page.set("onConsoleMessage", function (msg) { | |
| console.log("Page log: " + msg); | |
| browser.exit(); | |
| httpServer.close(); | |
| wsServer.close(); | |
| }); | |
| page.set("onResourceRequested", function (request) { | |
| console.log("Phantom: request - " + request.url); | |
| }); | |
| page.open('http://localhost:8000/test/test.html', function (status) { | |
| console.log('Phantom: loading finished.'); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment