A Zeroconf implementation in JavaScript for Chrome Apps. Publish services on the local network or discover existing services using multicast DNS.
Due to Chrome Socket UDP API doesn't has option reuse address, this implementation use Unicast DNS for discovering services, and Publish function have to wait for new API.
You can install by git clone this repo and copy javascript file "zeroconf.js" in folder "src" to your app folder:
git clone https://github.com/cuongurus/Zeroconf-for-Chrome.git
This lib required these permissions:
"sockets": {
"udp": { "bind": "*", "send": "*" }
}
You can also install with chominit tool by cd to your app folder and run:
chominit -z
This tool will automatically download "zeroconf.js" file to your app folder and add required permissions.
Import to your window page using script tag for complete install:
<script src="zeroconf.js"></script>.
// Initializing
var finder = new Browser( function(err){
if(err) console.warn(err);
// Browse for all _http._tcp services
finder.find (function(err, result){
if(err) console.warn(err)
if(result) console.log('Found service: ' + JSON.stringify(result, null, 4))
},'_http._tcp')
var finder = new Browser(error)
Creat a Browser object. The error event is emitted whenever any error occurs.
Browser for all services with given service_type
Type | Property | Description | ||||||
---|---|---|---|---|---|---|---|---|
Function | callback | called when a service has been found. The callback parameter should be a function that looks like this: function (string error, Service result){...};
|
||||||
String | service_type | Example: '_http._tcp'. List of known service_types here Let it null for browse all. |
Service look like this
{
name: string,
type: string,
fqdn: string,
host: string,
port: string,
ipv4: [],
ipv6: [],
txt: object
}
On development.