js/dripdrop.js in dripdrop-0.3.1 vs js/dripdrop.js in dripdrop-0.4.0

- old
+ new

@@ -7,11 +7,11 @@ }; this.head = (opts && opts.head !== undefined) ? opts.head : {empty:''}; this.jsonEncoded = function() { - return $.JSON.encode({name: this.name, head: this.head, body: this.body}); + return JSON.stringify({name: this.name, head: this.head, body: this.body}); }; }; /* A DripDrop friendly WebSocket Object. This automatically converts messages to DD.Message objects. @@ -20,31 +20,35 @@ this.WebSocket = function(url) { this.socket = new WebSocket(url); this.onOpen = function(callback) { this.socket.onopen = callback; + return this; }; this.onRecv = function(callback) { this.socket.onmessage = function(wsMessage) { var json = $.parseJSON(wsMessage.data) var message = new DD.Message(json.name, {head: json.head, body: json.body}); callback(message); - return this; } + return this; }; this.onClose = function(callback) { this.socket.onclose = callback; + return this; }; this.onError = function(callback) { this.socket.onerror = callback; + return this; }; this.sendMessage = function(message) { this.socket.send(message.jsonEncoded()); + return this; }; }; this.HTTPResponse = function() {