GithubHelp home page GithubHelp logo

tripflex / cordova-plugin-zeroconf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from becvert/cordova-plugin-zeroconf

1.0 2.0 0.0 15 MB

Cordova ZeroConf Plugin

License: MIT License

Java 55.96% Objective-C 0.87% Swift 39.58% JavaScript 3.59%

cordova-plugin-zeroconf's Introduction

Cordova ZeroConf Plugin

This plugin allows you to browse and publish ZeroConf/Bonjour/mDNS services from applications developed using PhoneGap/Cordova 3.0 or newer.

This is not a background service. When the cordova view is destroyed/terminated, publish and watch operations are stopped.

CHANGELOG

Installation

In your application project directory:

cordova plugin add cordova-plugin-zeroconf

Usage

var zeroconf = cordova.plugins.zeroconf;

For Android, you may want set the following options to speed discovery up:

zeroconf.registerAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)
zeroconf.watchAddressFamily = 'ipv4'; // or 'ipv6' ('any' by default)

getHostname(success, failure)

Returns this device's hostname.

zeroconf.getHostname(function success(hostname){
    console.log(hostname); // ipad-of-becvert.local.
});

register(type, domain, name, port, txtRecord, success, failure)

Publishes a new service.

zeroconf.register('_http._tcp.', 'local.', 'Becvert\'s iPad', 80, {
    'foo' : 'bar'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
});

unregister(type, domain, name, success, failure)

Unregisters a service.

zeroconf.unregister('_http._tcp.', 'local.', 'Becvert\'s iPad');

stop(success, failure)

Unregisters all published services.

zeroconf.stop();

watch(type, domain, success, failure)

Starts watching for services of the specified type.

zeroconf.watch('_http._tcp.', 'local.', function(result) {
    var action = result.action;
    var service = result.service;
    if (action == 'added') {
        console.log('service added', service);
    } else if (action == 'resolved') {
        console.log('service resolved', service);
        /* service : {
        'domain' : 'local.',
        'type' : '_http._tcp.',
        'name': 'Becvert\'s iPad',
        'port' : 80,
        'hostname' : 'ipad-of-becvert.local',
        'ipv4Addresses' : [ '192.168.1.125' ], 
        'ipv6Addresses' : [ '2001:0:5ef5:79fb:10cb:1dbf:3f57:feb0' ],
        'txtRecord' : {
            'foo' : 'bar'
        } */
    } else {
        console.log('service removed', service);
    }
});

unwatch(type, domain, success, failure)

Stops watching for services of the specified type.

zeroconf.unwatch('_http._tcp.', 'local.')

close(success, failure)

Closes the service browser and stops watching.

zeroconf.close()

reInit(success, failure)

Re-initializes the entire plugin, which resets the browsers and services. Use this if the WiFi network has changed while the app is running.

zeroconf.reInit()

Credits

Android

It depends on andriydruk/RxDNSSD

iOS

Implements Apple's Bonjour

Licence

The MIT License

cordova-plugin-zeroconf's People

Contributors

becvert avatar emcniece avatar tripflex avatar

Stargazers

 avatar

Watchers

 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.