mqtt 5.6.2 → 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mqtt.js CHANGED
@@ -12634,7 +12634,7 @@ var mqtt = (() => {
12634
12634
  // package-json:../../package.json
12635
12635
  var require_package = __commonJS({
12636
12636
  "package-json:../../package.json"(exports5, module) {
12637
- module.exports = { version: "5.6.2" };
12637
+ module.exports = { version: "5.7.1" };
12638
12638
  }
12639
12639
  });
12640
12640
 
@@ -12743,7 +12743,7 @@ var mqtt = (() => {
12743
12743
  const type = packet.cmd;
12744
12744
  let response = null;
12745
12745
  const cb = client.outgoing[messageId] ? client.outgoing[messageId].cb : null;
12746
- let err;
12746
+ let err = null;
12747
12747
  if (!cb) {
12748
12748
  client.log("_handleAck :: Server sent an ack in error. Ignoring.");
12749
12749
  return;
@@ -12787,7 +12787,10 @@ var mqtt = (() => {
12787
12787
  client.messageIdProvider.deallocate(messageId);
12788
12788
  const granted = packet.granted;
12789
12789
  for (let grantedI = 0; grantedI < granted.length; grantedI++) {
12790
- if ((granted[grantedI] & 128) !== 0) {
12790
+ const subackRC = granted[grantedI];
12791
+ if ((subackRC & 128) !== 0) {
12792
+ err = new Error(`Subscribe error: ${exports5.ReasonCodes[subackRC]}`);
12793
+ err.code = subackRC;
12791
12794
  const topics = client.messageIdToTopic[messageId];
12792
12795
  if (topics) {
12793
12796
  topics.forEach((topic) => {
@@ -12798,7 +12801,7 @@ var mqtt = (() => {
12798
12801
  }
12799
12802
  delete client.messageIdToTopic[messageId];
12800
12803
  client["_invokeStoreProcessingQueue"]();
12801
- cb(null, packet);
12804
+ cb(err, packet);
12802
12805
  break;
12803
12806
  }
12804
12807
  case "unsuback": {
@@ -21395,6 +21398,7 @@ var mqtt = (() => {
21395
21398
  }
21396
21399
  }
21397
21400
  function connect(brokerUrl, opts) {
21401
+ var _a, _b, _c;
21398
21402
  debug("connecting to an MQTT broker...");
21399
21403
  if (typeof brokerUrl === "object" && !opts) {
21400
21404
  opts = brokerUrl;
@@ -21402,21 +21406,27 @@ var mqtt = (() => {
21402
21406
  }
21403
21407
  opts = opts || {};
21404
21408
  if (brokerUrl && typeof brokerUrl === "string") {
21405
- const parsed = url_1.default.parse(brokerUrl, true);
21406
- if (parsed.port != null) {
21407
- parsed.port = Number(parsed.port);
21408
- }
21409
- opts = Object.assign({
21410
- port: parsed.port,
21411
- host: parsed.hostname,
21412
- protocol: parsed.protocol,
21413
- query: parsed.query,
21414
- auth: parsed.auth
21415
- }, opts);
21416
- if (opts.protocol === null) {
21409
+ const parsedUrl = url_1.default.parse(brokerUrl, true);
21410
+ const parsedOptions = {};
21411
+ if (parsedUrl.port != null) {
21412
+ parsedOptions.port = Number(parsedUrl.port);
21413
+ }
21414
+ parsedOptions.host = parsedUrl.hostname;
21415
+ parsedOptions.query = parsedUrl.query;
21416
+ parsedOptions.auth = parsedUrl.auth;
21417
+ parsedOptions.protocol = parsedUrl.protocol;
21418
+ parsedOptions.path = parsedUrl.path;
21419
+ parsedOptions.protocol = (_a = parsedOptions.protocol) === null || _a === void 0 ? void 0 : _a.replace(/:$/, "");
21420
+ opts = Object.assign(Object.assign({}, parsedOptions), opts);
21421
+ if (!opts.protocol) {
21417
21422
  throw new Error("Missing protocol");
21418
21423
  }
21419
- opts.protocol = opts.protocol.replace(/:$/, "");
21424
+ }
21425
+ opts.unixSocket = opts.unixSocket || ((_b = opts.protocol) === null || _b === void 0 ? void 0 : _b.includes("+unix"));
21426
+ if (opts.unixSocket) {
21427
+ opts.protocol = opts.protocol.replace("+unix", "");
21428
+ } else if (!((_c = opts.protocol) === null || _c === void 0 ? void 0 : _c.startsWith("ws"))) {
21429
+ delete opts.path;
21420
21430
  }
21421
21431
  parseAuthOptions(opts);
21422
21432
  if (opts.query && typeof opts.query.clientId === "string") {