I finally got websockets with socket.io working. The following shows how.
My main.js file:
var pageWorkers = require("sdk/page-worker");
var self = require("sdk/self");
pageWorkers.Page({
contentScriptFile: self.data.url("worker.js"),
contentURL: self.data.url("worker.html"),
contentScriptFileWhen: "ready",
onMessage: function(message) {
console.log(message);
}
});
and the worker.html file:
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://domain:port/socket.io/socket.io.js"></script>
<script>
var socket = io.connect("http://domain:port");
socket.on('connect', function(){
socket.on('event', function(data){});
socket.on('error', function(data){console.log("error: " + error)});
socket.on('disconnect', function(){});
});
</script>
</head>
<body>
</body>
</html>