udp-discovery
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "udp-discovery", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Provides zero-config discovery service using broadcast UDP.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
108
README.md
@@ -7,2 +7,60 @@ udp-discovery | ||
# Installation | ||
npm install udp-discovery | ||
# Example | ||
## Application sending advertisements | ||
```JavaScript | ||
var Discovery = require('udp-discovery').Discovery; | ||
var discover = new Discovery(); | ||
var name = 'test'; | ||
var interval = 500; | ||
var available = true; | ||
var serv = { | ||
port: 80, | ||
proto: 'tcp', | ||
addrFamily: 'IPv4', | ||
bonus: { | ||
name: 'Edmond', | ||
day: 2233, | ||
week: [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday' ] | ||
} | ||
}; | ||
discover.announce(name, serv, interval, available); | ||
discover.on('MessageBus', function(event, data) { | ||
console.log('event:',event); | ||
console.log('data:',data); | ||
}); | ||
``` | ||
## Application receiving advertisements | ||
```JavaScript | ||
var Discovery = require('udp-discovery').Discovery; | ||
var discover = new Discovery(); | ||
discover.on('available', function(name, data, reason) { | ||
console.log('available ',name); | ||
console.log('data',data); | ||
console.log('reason',reason); | ||
var obj = {a: 1, b: '2', c: true, d: {e: 333}}; | ||
discover.sendEvent('Hello', obj); | ||
console.log(name,':','available:',reason); | ||
console.log(data); | ||
}); | ||
discover.on('unavailable', function(name, data, reason) { | ||
console.log(name,':','unavailable:',reason); | ||
console.log(data); | ||
}); | ||
``` | ||
# Discovery constructor | ||
@@ -16,7 +74,7 @@ | ||
* {Number} `port` - The port to listen upon for service announcements. Default: | ||
* **Number** `port` - The port to listen upon for service announcements. Default: | ||
44201. | ||
* {String} `bindAddr` - The address to bind to. Default: listens to all | ||
* **String** `bindAddr` - The address to bind to. Default: listens to all | ||
interfaces. | ||
* {String} `dgramType` - Either 'udp4' or 'udp6'. Default: 'udp4'. | ||
* **String** `dgramType` - Either 'udp4' or 'udp6'. Default: 'udp4'. | ||
@@ -30,7 +88,7 @@ # Discovery methods | ||
* {String} `name` The name of the service being announced. It must be unique, or | ||
* **String** `name` The name of the service being announced. It must be unique, or | ||
it will collide with another. | ||
* {Number} `interval` The duration between announcements in milliseconds. | ||
* {Any} `userData` Any data that can be serialized into JSON. | ||
* {Boolean} `available` Optional parameter to set availability of the service. | ||
* **Number** `interval` The duration between announcements in milliseconds. | ||
* **Any** `userData` Any data that can be serialized into JSON. | ||
* **Boolean** `available` Optional parameter to set availability of the service. | ||
If not specified, the default is 'true', meaning available. | ||
@@ -42,4 +100,4 @@ | ||
## pause(name) | ||
- {String} `name` The name of the service. | ||
- Returns true if successful, false otherwise. | ||
- **String** `name` The name of the service. | ||
- *Returns* true if successful, false otherwise. | ||
@@ -49,5 +107,5 @@ Halts announcements. | ||
## resume(name, \[,interval\]) | ||
- {String} `name` The name of the service. | ||
- {Number} `interval` Optional interval between announcements in ms. | ||
- Returns true if successful, false otherwise. | ||
- **String** `name` name of the service. | ||
- **Number** [`interval`] optional interval between announcements in ms. | ||
- *Returns* true if successful, false otherwise. | ||
@@ -57,6 +115,6 @@ Resumes the announcements at the time interval. | ||
## getData(name) | ||
- {String} `name `- The name of the service. | ||
- returns: {Object} The serviceObject from announce. | ||
- **String** `name` name of the service. | ||
- *Returns* **Object** serviceObject from announce. | ||
Returns the service object, which can be modified. For example, if you need to | ||
*Returns* the service object, which can be modified. For example, if you need to | ||
alter the `userData`, you can. You cannot, however, alter the name (it's a | ||
@@ -68,7 +126,7 @@ constant property). | ||
* {String} `name` The name of the service being announced. It must be unique, or | ||
* **String** `name` The name of the service being announced. It must be unique, or | ||
it will collide with another. | ||
* {Any} `userData` Any data that can be serialized into JSON. | ||
* {Number} [`interval`] Optional duration between announcements in milliseconds. | ||
* {Boolean} [`available`] Optional parameter to set availability of the service. | ||
* **Any** `userData` Any data that can be serialized into JSON. | ||
* **Number** [`interval`] Optional duration between announcements in milliseconds. | ||
* **Boolean** [`available`] Optional parameter to set availability of the service. | ||
If not specified, the default is 'true', meaning available. | ||
@@ -81,5 +139,5 @@ | ||
- {String} name - The name of the service. | ||
- {Object} data - User-defined object describing the service. | ||
- {String} reason - Why this event was sent: 'new', 'availabilityChange', | ||
- **String** `name` name of the service. | ||
- **Object** `data` user-defined object describing the service. | ||
- **String** `reason` why this event was sent: 'new', 'availabilityChange', | ||
'timedOut'. | ||
@@ -95,5 +153,5 @@ | ||
- {String} name - The name of the service. | ||
- {Object} data - User-defined object describing the service. | ||
- {String} reason - Why this event was sent: 'new', 'availabilityChange', | ||
- **String** `name` name of the service. | ||
- **Object** `data` user-defined object describing the service. | ||
- **String** `reason` why this event was sent: 'new', 'availabilityChange', | ||
'timedOut'. | ||
@@ -100,0 +158,0 @@ |
34464
179