Giter VIP home page Giter VIP logo

dns-sd.js's Introduction

dns-sd.js

A JavaScript implementation of mDNS/DNS-SD for Firefox OS

Usage

Clone repository. Then run npm install for fulfilling dependencies before you attempt to build the library.

Building

npm run build

This will regenerate a distributable version of the library in dist/dns-sd.js.

It also copies the distributable version to the lib directory in each of the two example apps, placed in the example folder.

Including

You can include the distributable file in your Firefox OS app, using a script tag:

<script src="dns-sd.js"></script>

Or if you want to use browserify and node.js to build your app, maybe you can install this module from git with npm:

npm install --save ssh+https://github.com/justindarc/dns-sd.js.git

and then you can require the module as usual in node.js land:

var DNSSD = require('dns-sd');

TODO: test to see if this works.

In practice

This library requires that your app has access to UDP sockets, so you need to specify this in the permissions field in your manifest.webapp file:

{
  "udp-socket": {}
}

More often than not, you will also want to use TCP sockets for connecting to the discovered services, so you need to specify the TCP socket permission too if your app wants to establish TCP connections too. The permissions would look like this:

{
  "tcp-socket": {},
  "udp-socket": {}
}

Registering a service

DNSSD.registerService('_your_service_name._tcp.local', port_number, {});

Service names must end in .local.

Discovering services

DNSSD.addEventListener('discovered', function(evt) {
  // A service broadcast event was received
  // i.e. we "discovered" something new
});

DNSSD.startDiscovery();

where evt is a discoveredEvent which contains some bits of interesting information:

  • address โ€“ the address of the host which is exposing services
  • services โ€“ an array with the names of the services in the host

Examples

Each example app is in its own folder, and it is a completely functional app that you can open in WebIDE and deploy to your device.

Browser (example/browser)

This example will start service discovery on the DNSSD object, then display the discovered services per host on the screen.

Chat (example/chat)

Since this is about connecting various devices over the air, you will need two or more devices running the same app in order to actually see what it is about.

dns-sd.js's People

Contributors

sole avatar justindarc avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.