@@ -9,6 +9,10 @@ | |||
this.emit("ready"); | |||
}.bind(this); | |||
this._sock.onclose = function(evt) { | |||
this.emit("close"); | |||
}.bind(this); | |||
this._sock.onmessage = function(evt) { | |||
var obj = JSON.parse(evt.data); | |||
@@ -31,6 +31,11 @@ | |||
console.log("Received myEvent from server!"); | |||
console.log(data); | |||
}); | |||
sock.on("close", function() { | |||
document.getElementById("message").innerHTML = | |||
"Connection closed!"; | |||
}); | |||
}); | |||
}); | |||
</script> |
@@ -41,6 +41,10 @@ var util = require("util"); | |||
function Socket(websock) { | |||
this._websock = websock; | |||
websock.on("close", function() { | |||
this.emit("close"); | |||
}.bind(this)); | |||
websock.on("message", function(msg) { | |||
var obj; | |||
try { | |||
@@ -79,6 +83,12 @@ var util = require("util"); | |||
wss.on("connection", function(websock) { | |||
var sock = new Socket(websock); | |||
this.socks.push(sock); | |||
var i = this.socks.length - 1; | |||
sock.on("close", function() { | |||
this.socks.splice(i, 1); | |||
}.bind(this)); | |||
this.emit("connection", sock); | |||
}.bind(this)); |
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "socksugar", | |||
"version": "0.1.2", | |||
"version": "0.2.0", | |||
"description": "Websockets with sugar on top.", | |||
"main": "index.js", | |||
"scripts": { |