import { Injectable } from '@angular/core'; import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; import { Observable } from 'rxjs/Observable'; export interface ZeroconfService { domain: string; type: string; name: string; port: number; hostname: string; ipv4Addresses: string[]; ipv6Addresses: string[]; txtRecord: any; } export interface ZeroconfResult { action: 'registered' | 'added' | 'removed' | 'resolved'; service: ZeroconfService; } /** * @name Zeroconf * @description * This plugin allows you to browse and publish Zeroconf/Bonjour/mDNS services. * @usage * ```typescript * 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'); * ``` */ @Plugin({ pluginName: 'Zeroconf', plugin: 'cordova-plugin-zeroconf', pluginRef: 'cordova.plugins.zeroconf', repo: 'https://github.com/becvert/cordova-plugin-zeroconf', platforms: ['Android', 'iOS'] }) @Injectable() export class Zeroconf extends IonicNativePlugin { /** * Returns this device's hostname. * @return {Promise} */ @Cordova() getHostname(): Promise { return; } /** * Publishes a new service. * @param type {string} Service type name, e.g. "_http._tcp". * @param domain {string} Domain scope of the service, typically "local.". * @param name {string} Unqualified service instance name. * @param port {number} Local port on which the service runs. * @param txtRecord {any} Arbitrary key/value pairs describing the service. * @return {Promise} Returns a Promise that resolves with the registered service. */ @Cordova() register(type: string, domain: string, name: string, port: number, txtRecord: any): Promise { return; } /** * Unregisters a service. * @param type {string} Service type name, e.g. "_http._tcp". * @param domain {string} Domain scope of the service, typically "local.". * @param name {string} Unqualified service instance name. * @return {Promise} */ @Cordova() unregister(type: string, domain: string, name: string): Promise { return; } /** * Unregisters all published services. * @return {Promise} */ @Cordova() stop(): Promise { return; } /** * Starts watching for services of the specified type. * @param type {string} Service type name, e.g. "_http._tcp". * @param domain {string} Domain scope of the service, typically "local.". * @return {Observable} Returns an Observable that notifies of each service added or removed. */ @Cordova({ observable: true, clearFunction: 'unwatch', clearWithArgs: true }) watch(type: string, domain: string): Observable { return; } /** * Stops watching for services of the specified type. * @param type {string} Service type name, e.g. "_http._tcp". * @param domain {string} Domain scope of the service, typically "local.". * @return {Promise} */ @Cordova() unwatch(type: string, domain: string): Promise { return; } /** * Closes the service browser and stops watching. * @return {Promise} */ @Cordova() close(): Promise { return; } /** * Re-initializes the plugin to clean service & browser state. * @return {Promise} */ @Cordova() reInit(): Promise { return; } /** * Family of addresses to register: ipv4, ipv6 or any. */ registerAddressFamily: 'ipv4' | 'ipv6' | 'any'; /** * Family of addresses to watch for: ipv4, ipv6 or any. */ watchAddressFamily: 'ipv4' | 'ipv6' | 'any'; }