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

this.emit("ready"); this.emit("ready");
}.bind(this); }.bind(this);


this._sock.onclose = function(evt) {
this.emit("close");
}.bind(this);

this._sock.onmessage = function(evt) { this._sock.onmessage = function(evt) {
var obj = JSON.parse(evt.data); var obj = JSON.parse(evt.data);



+ 5
- 0
examples/index.html View File

console.log("Received myEvent from server!"); console.log("Received myEvent from server!");
console.log(data); console.log(data);
}); });

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

+ 10
- 0
index.js View File

function Socket(websock) { function Socket(websock) {
this._websock = websock; this._websock = websock;


websock.on("close", function() {
this.emit("close");
}.bind(this));

websock.on("message", function(msg) { websock.on("message", function(msg) {
var obj; var obj;
try { try {
wss.on("connection", function(websock) { wss.on("connection", function(websock) {
var sock = new Socket(websock); var sock = new Socket(websock);
this.socks.push(sock); 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); this.emit("connection", sock);
}.bind(this)); }.bind(this));

+ 1
- 1
package.json View File

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

Loading…
Cancel
Save