                 print("ZeroConf: netServiceBrowser:didRemoveService:\(netService)")
             #endif
             services.removeValue(forKey: netService.name)
-            
+
             let service = ZeroConf.jsonifyService(netService)
-            
+
             let message: NSDictionary = NSDictionary(objects: ["removed", 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 netServiceDidStop(_ netService: NetService) {
             nsb = nil
             services.removeAll()
             commandDelegate = nil
-            
+
             let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
             commandDelegate?.send(pluginResult, callbackId: callbackId)
         }
-        
-    }
-    
+
+    }
+
     fileprivate static func jsonifyService(_ netService: NetService) -> NSDictionary {
-        
+
         var ipv4Addresses: [String] = []
         var ipv6Addresses: [String] = []
         for address in netService.addresses! {

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

            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) {
