arch1t3ct/collective.js — pull request #2 by ashleybrener (2013-04-06 21:41:33+00:00)
Title: enable discovery with advertisement

discovery is a UDP multicast standard used by many protocols such as ws-discovery and UPnP.

this simple add-on allows collective to advertise its own identity and listen for new identities on the local server / LAN (if UDP multicast is supported).

the code addition provides an enableDiscovery function with option parameter "ttl"
example:

var collective = new Collective({ host: 'localhost', port: 8124 }, all_hosts, function (collective) {
collective.set('foo.bar', 7);
var foo_bar = collective.get('foo.bar'); // = 7;
});
collective.enableDiscovery(10000);

this means that collective will listen for new collective nodes and will advertise its own identity every 10sec.

if ttl is not specified, collective will be in listen mode only and will need to advertise itself manually by calling:

collective.advertise(true);