0.0.2 • Published 11 years ago
ws.io v0.0.2
ws.io
A simple wrap to node.js ws module and then we can use it in a manner like socket.io. It's really easy to use socket.io but it doesn't support Blob yet. So I write a simple wrap to ws module for this purpose. This is also a part of works from a contest by ithelp.ithome.com.tw.
Features:
- trnasfer Blob/ArrayBuffer by put it in an object and emit it just as socket.io
- broadcast to all but not me
- emit to specified peer by to(socket.id)
- join/leave/in room
- in-memory store
Limits:
- can only send one Blob/ArrayBuffer within one emit
- the Blob/ArrayBuffer object must be a property of the emitting object in the first level, no deeper
- no configuration support
- no 3rd party data store support
- cannot scale
- client support is now through a static url: /ws.io/ws.io.js
usage
a simple echo server
"<script>"+
"var socket = io.connect('ws://localhost:8443');"+
"socket.on('echo', function(data) {"+
" alert(data);"+
"});"+
"</script>"+
"<body>"+
"<button id='echo'>echo</button>"+
"</body>"+
"</html>"+
"<script>"+
"var button = document.getElementById('echo');"+
"button.onclick = function() {"+
" socket.emit('echo', 'hello echo server.');"+
"}"+
"</script>");
}
io.sockets.on('connection', function (socket) { socket.on('echo', function(data) { socket.emit('echo', data); }); });
will add a blob transfering example soon.