                 }
             }
         }
-        
+
         if ipv6Addresses.count > 1 {
             ipv6Addresses = Array(Set(ipv6Addresses))
         }
-        
+
         var txtRecord: [String: String] = [:]
         if let txtRecordData = netService.txtRecordData() {
             let dict = NetService.dictionary(fromTXTRecord: txtRecordData)

            netService.delegate = self
            netService.resolve(withTimeout: 5000)
            services[netService.name] = netService // keep strong reference to catch didResolveAddress
            
            let service = ZeroConf.jsonifyService(netService)
            
            let message: NSDictionary = NSDictionary(objects: ["added", service], forKeys: ["action" as NSCopying, "service" as NSCopying])
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: message as! [AnyHashable: Any])
            pluginResult?.setKeepCallbackAs(true)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }
        
        @objc func netServiceDidResolveAddress(_ netService: NetService) {
            #if DEBUG
                print("ZeroConf: netService:didResolveAddress:\(netService)")
            #endif
            
            let service = ZeroConf.jsonifyService(netService)
            
            let message: NSDictionary = NSDictionary(objects: ["resolved", service], forKeys: ["action" as NSCopying, "service" as NSCopying])
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: message as! [AnyHashable: Any])
            pluginResult?.setKeepCallbackAs(true)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }
        
        @objc func netService(_ netService: NetService, didNotResolve errorDict: [String : NSNumber]) {
            #if DEBUG
                print("ZeroConf: netService:didNotResolve:\(netService) \(errorDict)")
            #endif
            
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
            pluginResult?.setKeepCallbackAs(true)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }
        
        @objc func netServiceBrowser(_ netServiceBrowser: NetServiceBrowser,
                                     didRemove netService: NetService,
                                     moreComing moreServicesComing: Bool) {

import Foundation

@objc(ZeroConf) public class ZeroConf : CDVPlugin  {

    fileprivate var publishers: [String: Publisher]!
    fileprivate var browsers: [String: Browser]!

    override public func pluginInitialize() {
        publishers  = [:]
        browsers = [:]
    }

    override public func onAppTerminate() {
        for (_, publisher) in publishers {
            publisher.destroy()
        }
        publishers.removeAll()

        for (_, browser) in browsers {
            browser.destroy();
        }
        browsers.removeAll()
    }

    public func getHostname(_ command: CDVInvokedUrlCommand) {

        let hostname = Hostname.get() as String

        #if DEBUG
            print("ZeroConf: hostname \(hostname)")
        #endif
