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IAAI,WAAW,EAAS,GAWrC,OAR0B,OAAtB,KAAK,eAER,KAAK,aAAe,mBAAmB,YACtC,eACC,GAAS,KAAK,eAAe,MAEhC,KAAK,QAAQ,KAAK,GAEX,CACR,EACA,aAAc,SAAU,GACvB,IAAI,EAAY,KAAK,QAAQ,QAAQ,GAIjC,GAAa,GAChB,KAAK,QAAQ,OAAO,EAAW,GAE5B,KAAK,QAAQ,OAAS,IACzB,KAAK,aAAa,SAClB,KAAK,aAAe,KAEtB","file":"/npm/zh-react-native-mqtt@0.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/zh-react-native-mqtt@0.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import {\n\tDeviceEventEmitter,\n\tNativeModules\n} from 'react-native';\n\nvar Mqtt = NativeModules.Mqtt;\n\nvar MqttClient = function (options, clientRef) {\n\tthis.options = options;\n\tthis.clientRef = clientRef;\n\tthis.eventHandler = {};\n\n\tthis.dispatchEvent = function (data) {\n\n\t\tif (data && data.clientRef == this.clientRef && data.event) {\n\n\t\t\tif (this.eventHandler[data.event]) {\n\t\t\t\tthis.eventHandler[data.event](data.message);\n\t\t\t}\n\t\t}\n\t}\n}\n\nMqttClient.prototype.on = function (event, callback) {\n\t// console.log('setup event', event);\n\tthis.eventHandler[event] = callback;\n}\n\nMqttClient.prototype.connect = function () {\n\tMqtt.connect(this.clientRef);\n}\n\nMqttClient.prototype.disconnect = function () {\n\tMqtt.disconnect(this.clientRef);\n}\n\nMqttClient.prototype.subscribe = function (topic, qos) {\n\tMqtt.subscribe(this.clientRef, topic, qos);\n}\n\nMqttClient.prototype.publish = function (topic, payload, qos, retain) {\n\tMqtt.publish(this.clientRef, topic, payload, qos, retain);\n}\n\nmodule.exports = {\n\tclients: [],\n\teventHandler: null,\n\tdispatchEvents: function (data) {\n\t\tthis.clients.forEach(function (client) {\n\t\t\tclient.dispatchEvent(data);\n\t\t});\n\t},\n\tcreateClient: async function (options) {\n\t\tif (options.uri) {\n\t\t\tvar pattern = /^((tcp?|mqtt[s]?|ws[s]?)?:(\\/\\/)([a-zA-Z_\\.]*):?(\\d+))$/;\n\t\t\tvar matches = options.uri.match(pattern);\n\t\t\tvar protocol = matches[2];\n\t\t\tvar host = matches[4];\n\t\t\tvar port = matches[5];\n\t\t\tconsole.log(matches)\n\t\t\toptions.port = parseInt(port);\n\t\t\toptions.host = host;\n\t\t\toptions.protocol = protocol;\n\n\n\t\t\tif (protocol == 'mqtt' || protocol == 'mqtts') {\n\t\t\t\toptions.protocol = 'mqtt';\n\t\t\t}\n\t\t\tif (protocol == 'ws' || protocol == 'wss') {\n\t\t\t\toptions.protocol = 'ws';\n\t\t\t}\n\n\t\t}\n\n\t\tlet clientRef = await Mqtt.createClient(options);\n\n\t\tvar client = new MqttClient(options, clientRef);\n\n\t\t/* Listen mqtt event */\n\t\tif (this.eventHandler === null) {\n\t\t\t// console.log('add mqtt_events listener')\n\t\t\tthis.eventHandler = DeviceEventEmitter.addListener(\n\t\t\t\t\"mqtt_events\",\n\t\t\t\t(data) => this.dispatchEvents(data));\n\t\t}\n\t\tthis.clients.push(client);\n\n\t\treturn client;\n\t},\n\tremoveClient: function (client) {\n\t\tvar clientIdx = this.clients.indexOf(client);\n\n\t\t/* TODO: destroy client in native module */\n\n\t\tif (clientIdx > -1)\n\t\t\tthis.clients.splice(clientIdx, 1);\n\n\t\tif (this.clients.length > 0) {\n\t\t\tthis.eventHandler.remove();\n\t\t\tthis.eventHandler = null;\n\t\t}\n\t}\n\n};\n"]}