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

        }
        return nil
    }
    
}

            self.txtRecord = txtRecord
            self.callbackId = callbackId
        }

        func register() {

            // Netservice
            let service = NetService(domain: domain, type: type , name: name, port: Int32(port))
            nsp = service
            service.delegate = self

            if let record = txtRecord {
                if record.count > 0 {
                    service.setTXTRecord(NetService.data(fromTXTRecord: record))
                }
            }

            commandDelegate?.run(inBackground: {
                service.publish()
            })

        }

        func unregister() {

            if let service = nsp {
                service.stop()
            }

        }

        func destroy() {

            if let service = nsp {
                service.stop()
            }

        }

        @objc func netServiceDidPublish(_ netService: NetService) {
            #if DEBUG
                print("ZeroConf: netService:didPublish:\(netService)")
            #endif

            let service = ZeroConf.jsonifyService(netService)

            let message: NSDictionary = NSDictionary(objects: ["registered", service], forKeys: ["action" as NSCopying, "service" as NSCopying])
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: message as! [AnyHashable: Any])
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }

        @objc func netService(_ netService: NetService, didNotPublish errorDict: [String : NSNumber]) {
            #if DEBUG
                print("ZeroConf: netService:didNotPublish:\(netService) \(errorDict)")
            #endif

            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }

        @objc func netServiceDidStop(_ netService: NetService) {
            nsp = nil
            commandDelegate = nil

            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }

    }

    internal class Browser: NSObject, NetServiceDelegate, NetServiceBrowserDelegate {

        var nsb: NetServiceBrowser?
        var domain: String
        var type: String
        var callbackId: String
        var services: [String: NetService] = [:]
        var commandDelegate: CDVCommandDelegate?

        init (withDomain domain: String, withType type: String, withCallbackId callbackId: String) {
            self.domain = domain
            self.type = type
            self.callbackId = callbackId
        }

        func watch() {

             // Net service browser
            let browser = NetServiceBrowser()
            nsb = browser
            browser.delegate = self

            commandDelegate?.run(inBackground: {
                browser.searchForServices(ofType: self.type, inDomain: self.domain)
            })

            let pluginResult = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
            pluginResult?.setKeepCallbackAs(true)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }

        func unwatch() {

            if let service = nsb {
                service.stop()
            }

        }

        func destroy() {

            if let service = nsb {
                service.stop()
            }

        }

        @objc func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {
            #if DEBUG
                print("ZeroConf: netServiceBrowser:didNotSearch:\(netService) \(errorDict)")
            #endif

            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
            commandDelegate?.send(pluginResult, callbackId: callbackId)
        }

        @objc func netServiceBrowser(_ netServiceBrowser: NetServiceBrowser,
                                     didFind netService: NetService,
                                     moreComing moreServicesComing: Bool) {
