Create a socket server in the browser
Once the extension is installed it will expose the BrowserSocket() constructor, which works very similar to the WebSocket constructor.
var bs = new BrowserSocket(handler);
The handler function should return a new function instance.
var bsConnection;
function handler() {
return new function() {
bsConnection = this;
bsConnection.onmessage = function(msg) {
// Run code when a message is received
}
bsConnection.onopen = function() {
// Run code on socket opening
}
bsConnection.onclose = function(e) {
// Run code on socket closing
}
}
}
To send messages to the BrowserSocket you use the send method.
bs.send("message to send");
The client has to be a WebSocket supporting browser in order to connect and communicate with the BrowserSocket.
var ws = new WebSocket("ws://127.0.0.1:12345/bs/1234567/");
The communication is done using the standard WebSocket API.
If you want a compelling usecase to see why this extension is completely revolutionary, take a look at my article on using it for remote debugging.
Install it in either Firefox 3.6 or 4, you can grab the latest build on the download page.
Once installed run my jsconsole fork in Firefox and create a BrowserSocket instance by using :createServer command. This will generate a socket that you can connect to and give you the address to use.
To connect to the BrowserSocket make sure your device is on the same network and it supports WebSockets. Load the remote debug bookmarklet, enter the socket address and your off.
javascript:(function(doc)%20{var%20script%20=%doc.createElement('script');script.src%20=%20'http://labs.thecssninja.com/jsconsole/client.js';doc.body.appendChild(script);})(this.document);
In the mean time check out browsersocket.org.
Plugin was created by two very smart people Toni Ruottu and Konrad Markus.