MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / connect

Function connect

map-chat/javascript/browserMqtt.js:1116–1197  ·  view source on GitHub ↗

* connect - connect to an MQTT broker. * * @param {String} [brokerUrl] - url of the broker, optional * @param {Object} opts - see MqttClient#constructor

(brokerUrl, opts)

Source from the content-addressed store, hash-verified

1114 * @param {Object} opts - see MqttClient#constructor
1115 */
1116function connect (brokerUrl, opts) {
1117
1118 if (('object' === typeof brokerUrl) && !opts) {
1119 opts = brokerUrl;
1120 brokerUrl = null;
1121 }
1122
1123 opts = opts || {};
1124
1125 if (brokerUrl) {
1126 opts = xtend(url.parse(brokerUrl, true), opts);
1127 opts.protocol = opts.protocol.replace(/\:$/, '');
1128 }
1129
1130 // merge in the auth options if supplied
1131 parseAuthOptions(opts);
1132
1133 // support clientId passed in the query string of the url
1134 if (opts.query && 'string' === typeof opts.query.clientId) {
1135 opts.clientId = opts.query.clientId;
1136 }
1137
1138 if (opts.cert && opts.key) {
1139 if (opts.protocol) {
1140 if (-1 === ['mqtts', 'wss'].indexOf(opts.protocol)) {
1141 /*
1142 * jshint and eslint
1143 * complains that break from default cannot be reached after throw
1144 * it is a foced exit from a control structure
1145 * maybe add a check after switch to see if it went through default
1146 * and then throw the error
1147 */
1148 /*jshint -W027*/
1149 /*eslint no-unreachable:1*/
1150 switch (opts.protocol) {
1151 case 'mqtt':
1152 opts.protocol = 'mqtts';
1153 break;
1154 case 'ws':
1155 opts.protocol = 'wss';
1156 break;
1157 default:
1158 throw new Error('Unknown protocol for secure conenction: "' + opts.protocol + '"!');
1159 break;
1160 }
1161 /*eslint no-unreachable:0*/
1162 /*jshint +W027*/
1163 }
1164 } else {
1165 // don't know what protocol he want to use, mqtts or wss
1166 throw new Error('Missing secure protocol key');
1167 }
1168 }
1169
1170 if (!protocols[opts.protocol]) {
1171 opts.protocol = protocolList.filter(function (key) {
1172 return 'function' === typeof protocols[key];
1173 })[0];

Callers 1

generateFunction · 0.85

Calls 7

parseAuthOptionsFunction · 0.85
calcLengthLengthFunction · 0.85
writeLengthFunction · 0.85
writeStringOrBufferFunction · 0.85
writeNumberFunction · 0.85
writeStringFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected