Browse Source

some api changes

master
mort 8 years ago
parent
commit
2997cf5d19
4 changed files with 20 additions and 1 deletions
  1. 4
    0
      client.js
  2. 5
    0
      examples/index.html
  3. 10
    0
      index.js
  4. 1
    1
      package.json

+ 4
- 0
client.js View File

@@ -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);


+ 5
- 0
examples/index.html View File

@@ -31,6 +31,11 @@
console.log("Received myEvent from server!");
console.log(data);
});

sock.on("close", function() {
document.getElementById("message").innerHTML =
"Connection closed!";
});
});
});
</script>

+ 10
- 0
index.js View File

@@ -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
- 1
package.json View File

@@ -1,6 +1,6 @@
{
"name": "socksugar",
"version": "0.1.2",
"version": "0.2.0",
"description": "Websockets with sugar on top.",
"main": "index.js",
"scripts": {

Loading…
Cancel
Save