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AAU,EAAK,GACvB,QAAI,GAAY,EAAQ,GAAM,IAII,mBAAnB,UAAU,EAC1B,IAAG,EACJ,CAEA,IAAmB,IAAf,EAAK,QAAoB,EAAK,SACjC,MAAM,IAAI,MAAM,wCAwBjB,OArBI,EAAK,WACR,EAAK,gBAAkB,EAAK,UAoBtB,IAAI,YAjBX,SAAiB,GAchB,OAbI,EAAK,UACH,EAAO,iBAAmB,EAAO,kBAAoB,EAAK,QAAQ,SACtE,EAAO,gBAAkB,GAG1B,EAAK,KAAO,EAAK,QAAQ,EAAO,iBAAiB,KACjD,EAAK,KAAO,EAAK,QAAQ,EAAO,iBAAiB,KACjD,EAAK,SAAa,EAAK,QAAQ,EAAO,iBAAiB,SAAkC,EAAK,QAAQ,EAAO,iBAAiB,SAA5D,EAAK,gBACvE,EAAK,SAAW,EAAK,KAErB,EAAO,mBAGD,UAAU,EAAK,UAAU,EAAQ,EACzC,GAE+B,EAChC,CAzHA,UAAU,GAAK,QAAQ,QACvB,UAAU,IAAM,QAAQ,QA0HxB,OAAO,QAAU,QACjB,OAAO,QAAQ,QAAU,QACzB,OAAO,QAAQ,WAAa,WAC5B,OAAO,QAAQ,MAAQ","file":"/npm/@taoqf/react-native-mqtt@3.0.4/lib/connect/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/@taoqf/react-native-mqtt@3.0.4/lib/connect/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","'use strict'\n\nvar MqttClient = require('../client')\nvar Store = require('../store')\nvar url = require('url')\nvar xtend = require('xtend')\n\nprocess.nextTick = setImmediate\n\nvar protocols = {}\n\nprotocols.ws = require('./ws')\nprotocols.wss = require('./ws')\n\n/**\n * Parse the auth attribute and merge username and password in the options object.\n *\n * @param {Object} [opts] option object\n */\nfunction parseAuthOptions(opts) {\n\tvar matches\n\tif (opts.auth) {\n\t\tmatches = opts.auth.match(/^(.+):(.+)$/)\n\t\tif (matches) {\n\t\t\topts.username = matches[1]\n\t\t\topts.password = matches[2]\n\t\t} else {\n\t\t\topts.username = opts.auth\n\t\t}\n\t}\n}\n\n/**\n * connect - connect to an MQTT broker.\n *\n * @param {String} [brokerUrl] - url of the broker, optional\n * @param {Object} opts - see MqttClient#constructor\n */\nfunction connect(brokerUrl, opts) {\n\tif ((typeof brokerUrl === 'object') && !opts) {\n\t\topts = brokerUrl\n\t\tbrokerUrl = null\n\t}\n\n\topts = opts || {}\n\n\tif (brokerUrl) {\n\t\tvar parsed = url.parse(brokerUrl, true)\n\t\tif (parsed.port != null) {\n\t\t\tparsed.port = Number(parsed.port)\n\t\t}\n\n\t\topts = xtend(parsed, opts)\n\n\t\tif (opts.protocol === null) {\n\t\t\tthrow new Error('Missing protocol')\n\t\t}\n\t\topts.protocol = opts.protocol.replace(/:$/, '')\n\t}\n\n\t// merge in the auth options if supplied\n\tparseAuthOptions(opts)\n\n\t// support clientId passed in the query string of the url\n\tif (opts.query && typeof opts.query.clientId === 'string') {\n\t\topts.clientId = opts.query.clientId\n\t}\n\n\tif (opts.cert && opts.key) {\n\t\tif (opts.protocol) {\n\t\t\tif (['mqtts', 'wss', 'wxs', 'alis'].indexOf(opts.protocol) === -1) {\n\t\t\t\tswitch (opts.protocol) {\n\t\t\t\t\tcase 'mqtt':\n\t\t\t\t\t\topts.protocol = 'wss'\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'ws':\n\t\t\t\t\t\topts.protocol = 'wss'\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'wx':\n\t\t\t\t\tcase 'ali':\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error('Unknown protocol for secure connection: \"' + opts.protocol + '\"!')\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// don't know what protocol he want to use, mqtts or wss\n\t\t\tthrow new Error('Missing secure protocol key')\n\t\t}\n\t}\n\n\tif (!protocols[opts.protocol]) {\n\t\tvar isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1\n\t\topts.protocol = [\n\t\t\t'mqtt',\n\t\t\t'mqtts',\n\t\t\t'ws',\n\t\t\t'wss'\n\t\t].filter(function (key, index) {\n\t\t\tif (isSecure && index % 2 === 0) {\n\t\t\t\t// Skip insecure protocols when requesting a secure one.\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn (typeof protocols[key] === 'function')\n\t\t})[0]\n\t}\n\n\tif (opts.clean === false && !opts.clientId) {\n\t\tthrow new Error('Missing clientId for unclean clients')\n\t}\n\n\tif (opts.protocol) {\n\t\topts.defaultProtocol = opts.protocol\n\t}\n\n\tfunction wrapper(client) {\n\t\tif (opts.servers) {\n\t\t\tif (!client._reconnectCount || client._reconnectCount === opts.servers.length) {\n\t\t\t\tclient._reconnectCount = 0\n\t\t\t}\n\n\t\t\topts.host = opts.servers[client._reconnectCount].host\n\t\t\topts.port = opts.servers[client._reconnectCount].port\n\t\t\topts.protocol = (!opts.servers[client._reconnectCount].protocol ? opts.defaultProtocol : opts.servers[client._reconnectCount].protocol)\n\t\t\topts.hostname = opts.host\n\n\t\t\tclient._reconnectCount++\n\t\t}\n\n\t\treturn protocols[opts.protocol](client, opts)\n\t}\n\n\treturn new MqttClient(wrapper, opts)\n}\n\nmodule.exports = connect\nmodule.exports.connect = connect\nmodule.exports.MqttClient = MqttClient\nmodule.exports.Store = Store\n"]}