Higher-level API built on matthewmueller/io for separating out socket logic and identifying clients, so messages can be passed between them.
$ component install matthewmueller/device
var device = require('device')('http://socketserver.com');
var batter = device('batter').type('mobile');
var pitcher = device('pitcher').type('mobile');
var field = device('field').type('desktop');
batter.ready(function() {
batter.on('throw', hitHomerun);
});
pitcher.ready(function() {
pitcher.emit('throw');
});
field.ready(fn);
Initialize the devices with the given url
. This is the url that gets passed into matthewmueller/io
and ultimately into learnboost/engine.io
.
Initialize a device
with a given name
. This name should uniquely identify the device from the rest of the devices in the room. type
can be "mobile", "desktop", or "tablet";
Initializes the socket and calls fn
when done. This library uses socket pooling in order for each connected client to call at most one ready
function.
Ready can be called multiple times with multiple functions fn
.
iphone.ready(doThis);
iphone.ready(doThat);
There are some assumptions made about the configuration of the socket server. Head over to matthewmueller/ws.mat.io to see the server-side component.
You'll need to edit the test.html
to point to your socket server's address. Then do:
make
serve &
open http://localhost:3000
MIT