A port of the jquery plugin ( http://bloga.jp/ws/jq/ ) to provide some extra functionality on top of the raw WebSocket object.
Simply include the source. You will be able to construct a moosockets instance as follows:
var ms= new MooSocket({ url : "ws://localhost:8081", onopen : function () { console.log('connected'); }, onmessage : function (data) { console.log('received data'); }, onclose : function (event) { console.log('disconnected'); } });
You should provide implementations of each of these callback functions as appropriate to your needs.
To send data to the server do the following:
ms.wssend(JSON.encode({"a":1,"b":[]});
If you wish to use logging (handy for diagnostics) then set the 'loggingEnabled' option to 'true'. (You can also override the default logging behaviour by also passing a function as the 'logger' option.)
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus