Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Zeroconf

Improve this doc

This plugin allows you to browse and publish Zeroconf/Bonjour/mDNS services.

Repo: https://github.com/becvert/cordova-plugin-zeroconf

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-zeroconf
    $ npm install --save @ionic-native/zeroconf@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Zeroconf } from '@ionic-native/zeroconf';

constructor(private zeroconf: Zeroconf) { }

...

// watch for services of a specified type
this.zeroconf.watch('_http._tcp.', 'local.').subscribe(result => {
  if (result.action == 'added') {
    console.log('service added', result.service);
  } else {
    console.log('service removed', result.service);
  }
});

// publish a zeroconf service of your own
this.zeroconf.register('_http._tcp.', 'local.', 'Becvert\'s iPad', 80, {
  'foo': 'bar'
}).then(result => {
  console.log('Service registered', result.service);
});


// unregister your service
this.zeroconf.unregister('_http._tcp.', 'local.', 'Becvert\'s iPad');

Instance Members

getHostname()

Returns this device’s hostname.

Returns: Promise<string>

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

Publishes a new service.

Param Type Details
type string

Service type name, e.g. "_http._tcp".

domain string

Domain scope of the service, typically "local.".

name string

Unqualified service instance name.

port number

Local port on which the service runs.

txtRecord any

Arbitrary key/value pairs describing the service.

Returns: Promise<ZeroconfResult> Returns a Promise that resolves with the registered service.

unregister(type, domain, name)

Unregisters a service.

Param Type Details
type string

Service type name, e.g. "_http._tcp".

domain string

Domain scope of the service, typically "local.".

name string

Unqualified service instance name.

Returns: Promise<void>

stop()

Unregisters all published services.

Returns: Promise<void>

watch(type, domain)

Starts watching for services of the specified type.

Param Type Details
type string

Service type name, e.g. "_http._tcp".

domain string

Domain scope of the service, typically "local.".

Returns: Observable<ZeroconfResult> Returns an Observable that notifies of each service added or removed.

unwatch(type, domain)

Stops watching for services of the specified type.

Param Type Details
type string

Service type name, e.g. "_http._tcp".

domain string

Domain scope of the service, typically "local.".

Returns: Promise<void>

close()

Closes the service browser and stops watching.

Returns: Promise<void>

reInit()

Re-initializes the plugin to clean service & browser state.

Returns: Promise<void>

registerAddressFamily

Family of addresses to register: ipv4, ipv6 or any.

watchAddressFamily

Family of addresses to watch for: ipv4, ipv6 or any.

API

Native

General