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vC,OAAO,QAAU,CACf,QAAS,GACT,aAAc,KACd,eAAgB,SAAS,GACvB,KAAK,QAAQ,SAAQ,SAAS,GAC5B,EAAO,cAAc,EACvB,GACF,EACA,aAAc,eAAe,GAC3B,GAAI,EAAQ,IAAK,CACf,IACI,EAAU,EAAQ,IAAI,MADZ,yDAEd,IAAK,EACH,MAAM,IAAI,MACR,8BAA8B,EAAQ,0DAG1C,IAAI,EAAW,EAAQ,GACnB,EAAO,EAAQ,GACf,EAAO,EAAQ,GAEnB,EAAQ,KAAO,SAAS,GACxB,EAAQ,KAAO,EACf,EAAQ,SAAW,MAEH,OAAZ,GAAiC,SAAZ,IACvB,EAAQ,KAAM,GAEA,MAAZ,GAAgC,OAAZ,IACtB,EAAQ,SAAW,KAEvB,CAEA,IAAI,QAAkB,KAAK,aAAa,GAExC,IAAI,EAAS,IAAI,WAAW,EAAS,GAWrC,OAR0B,OAAtB,KAAK,eACP,QAAQ,IAAI,4BACZ,KAAK,aAAe,QAAQ,YAAY,eAAe,GACrD,KAAK,eAAe,MAGxB,KAAK,QAAQ,KAAK,GAEX,CACT,EACA,aAAc,SAAS,GACrB,IAAI,EAAY,KAAK,QAAQ,QAAQ,GAEjC,GAAa,GAAG,KAAK,QAAQ,OAAO,EAAW,GAE/C,KAAK,QAAQ,OAAS,IACxB,KAAK,aAAa,SAClB,KAAK,aAAe,MAGtB,KAAK,aAAa,EAAO,UAC3B,EAEA,cAAe,WACb,KAAK,eACP","file":"/npm/@luckfellow/react-native-mqtt@0.5.9/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@luckfellow/react-native-mqtt@0.5.9/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 { NativeEventEmitter, NativeModules } from \"react-native\";\r\n\r\nvar Mqtt = NativeModules.Mqtt;\r\n\r\nvar MqttClient = function(options, clientRef) {\r\n  this.options = options;\r\n  this.clientRef = clientRef;\r\n  this.eventHandler = {};\r\n\r\n  this.dispatchEvent = function(data) {\r\n    if (data && data.clientRef == this.clientRef && data.event) {\r\n      if (this.eventHandler[data.event]) {\r\n        this.eventHandler[data.event](data.message);\r\n      }\r\n    }\r\n  };\r\n};\r\n\r\nMqttClient.prototype.on = function(event, callback) {\r\n  console.log(\"setup event\", event);\r\n  this.eventHandler[event] = callback;\r\n};\r\n\r\nMqttClient.prototype.connect = function() {\r\n  Mqtt.connect(this.clientRef);\r\n};\r\n\r\nMqttClient.prototype.disconnect = function() {\r\n  Mqtt.disconnect(this.clientRef);\r\n};\r\n\r\nMqttClient.prototype.subscribe = function(topic, qos) {\r\n  Mqtt.subscribe(this.clientRef, topic, qos);\r\n};\r\n\r\nMqttClient.prototype.unsubscribe = function(topic) {\r\n  Mqtt.unsubscribe(this.clientRef, topic);\r\n};\r\n\r\nMqttClient.prototype.publish = async function(topic, payload, qos, retain) {\r\n  const msgID = await Mqtt.publish(this.clientRef, topic, payload, qos, retain);\r\n  return msgID;\r\n};\r\nMqttClient.prototype.publishUInt8 = async function(\r\n  topic,\r\n  payload,\r\n  qos,\r\n  retain\r\n) {\r\n  const msgID = await Mqtt.publishUInt8(\r\n    this.clientRef,\r\n    topic,\r\n    payload,\r\n    qos,\r\n    retain\r\n  );\r\n  return msgID;\r\n};\r\n\r\nMqttClient.prototype.reconnect = function() {\r\n  Mqtt.reconnect(this.clientRef);\r\n};\r\nMqttClient.prototype.isConnected = function() {\r\n  return Mqtt.isConnected(this.clientRef);\r\n};\r\n\r\nMqttClient.prototype.getTopics = function() {\r\n  return Mqtt.getTopics(this.clientRef);\r\n};\r\n\r\nMqttClient.prototype.isSubbed = function(topic) {\r\n  return Mqtt.isSubbed(this.clientRef, topic);\r\n};\r\n\r\nconst emitter = new NativeEventEmitter(Mqtt);\r\n\r\nmodule.exports = {\r\n  clients: [],\r\n  eventHandler: null,\r\n  dispatchEvents: function(data) {\r\n    this.clients.forEach(function(client) {\r\n      client.dispatchEvent(data);\r\n    });\r\n  },\r\n  createClient: async function(options) {\r\n    if (options.uri) {\r\n      var pattern = /^((mqtt[s]?|ws[s]?)?:(\\/\\/)([0-9a-zA-Z_\\.]*):?(\\d+))$/;\r\n      var matches = options.uri.match(pattern);\r\n      if (!matches) {\r\n        throw new Error(\r\n          `Uri passed to createClient ${options.uri} doesn't match a known protocol (mqtt:// or ws://).`\r\n        );\r\n      }\r\n      var protocol = matches[2];\r\n      var host = matches[4];\r\n      var port = matches[5];\r\n\r\n      options.port = parseInt(port);\r\n      options.host = host;\r\n      options.protocol = \"tcp\";\r\n\r\n      if (protocol == \"wss\" || protocol == \"mqtts\") {\r\n        options.tls = true;\r\n      }\r\n      if (protocol == \"ws\" || protocol == \"wss\") {\r\n        options.protocol = \"ws\";\r\n      }\r\n    }\r\n\r\n    let clientRef = await Mqtt.createClient(options);\r\n\r\n    var client = new MqttClient(options, clientRef);\r\n\r\n    /* Listen mqtt event */\r\n    if (this.eventHandler === null) {\r\n      console.log(\"add mqtt_events listener\");\r\n      this.eventHandler = emitter.addListener(\"mqtt_events\", data =>\r\n        this.dispatchEvents(data)\r\n      );\r\n    }\r\n    this.clients.push(client);\r\n\r\n    return client;\r\n  },\r\n  removeClient: function(client) {\r\n    var clientIdx = this.clients.indexOf(client);\r\n\r\n    if (clientIdx > -1) this.clients.splice(clientIdx, 1);\r\n\r\n    if (this.clients.length > 0) {\r\n      this.eventHandler.remove();\r\n      this.eventHandler = null;\r\n    }\r\n\r\n    Mqtt.removeClient(client.clientRef);\r\n  },\r\n\r\n  disconnectAll: function() {\r\n    Mqtt.disconnectAll();\r\n  }\r\n};\r\n"]}