mqtt 5.16.1 → 5.17.0

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
@@ -11711,7 +11711,7 @@ var mqtt = (() => {
11711
11711
  // package-json:../../package.json
11712
11712
  var require_package = __commonJS({
11713
11713
  "package-json:../../package.json"(exports8, module) {
11714
- module.exports = { version: "5.16.1" };
11714
+ module.exports = { version: "5.17.0" };
11715
11715
  }
11716
11716
  });
11717
11717
 
@@ -11820,6 +11820,7 @@ var mqtt = (() => {
11820
11820
  const gotTopic = topicAliasRecv.getTopicByAlias(alias);
11821
11821
  if (gotTopic) {
11822
11822
  topic = gotTopic;
11823
+ packet.topic = topic;
11823
11824
  client.log("handlePublish :: topic complemented by alias. topic: %s - alias: %d", topic, alias);
11824
11825
  } else {
11825
11826
  client.log("handlePublish :: unregistered topic alias. alias: %d", alias);
@@ -12077,16 +12078,15 @@ var mqtt = (() => {
12077
12078
  delete client.outgoing[messageId];
12078
12079
  client.messageIdProvider.deallocate(messageId);
12079
12080
  const granted = packet.granted;
12081
+ const topics = client.messageIdToTopic[messageId];
12080
12082
  for (let grantedI = 0; grantedI < granted.length; grantedI++) {
12081
12083
  const subackRC = granted[grantedI];
12082
12084
  if ((subackRC & 128) !== 0) {
12083
12085
  err = new Error(`Subscribe error: ${exports8.ReasonCodes[subackRC]}`);
12084
12086
  err.code = subackRC;
12085
- const topics = client.messageIdToTopic[messageId];
12086
- if (topics) {
12087
- topics.forEach((topic) => {
12088
- delete client["_resubscribeTopics"][topic];
12089
- });
12087
+ const topic = topics?.[grantedI];
12088
+ if (topic !== void 0) {
12089
+ delete client["_resubscribeTopics"][topic];
12090
12090
  }
12091
12091
  }
12092
12092
  }
@@ -12099,7 +12099,11 @@ var mqtt = (() => {
12099
12099
  delete client.outgoing[messageId];
12100
12100
  client.messageIdProvider.deallocate(messageId);
12101
12101
  client["_invokeStoreProcessingQueue"]();
12102
- cb(null, packet);
12102
+ const unsubackRC = (packet.granted ?? []).find((rc) => (rc & 128) !== 0);
12103
+ if (unsubackRC !== void 0) {
12104
+ err = new shared_1.ErrorWithReasonCode(`Unsubscribe error: ${exports8.ReasonCodes[unsubackRC]}`, unsubackRC);
12105
+ }
12106
+ cb(err, packet);
12103
12107
  break;
12104
12108
  }
12105
12109
  default:
@@ -15183,6 +15187,57 @@ var mqtt = (() => {
15183
15187
  });
15184
15188
  var MAX_RECEIVE_MAXIMUM = 65535;
15185
15189
  var RECEIVE_MAXIMUM_EXCEEDED = 147;
15190
+ var MALFORMED_PACKET = 129;
15191
+ var encodedSize = (packet, opts) => {
15192
+ let size = 0;
15193
+ const counter = {
15194
+ write(chunk) {
15195
+ size += typeof chunk === "string" ? Buffer2.byteLength(chunk) : chunk.length;
15196
+ return true;
15197
+ },
15198
+ destroy() {
15199
+ }
15200
+ };
15201
+ mqtt_packet_1.default.writeToStream(packet, counter, opts);
15202
+ return size;
15203
+ };
15204
+ var byteSize = (value) => {
15205
+ if (value == null) {
15206
+ return 0;
15207
+ }
15208
+ return typeof value === "string" || ArrayBuffer.isView(value) ? Buffer2.byteLength(value) : Infinity;
15209
+ };
15210
+ var userPropertySize = (key, value) => typeof value === "string" ? 5 + Buffer2.byteLength(key) + Buffer2.byteLength(value) : Infinity;
15211
+ var publishSizeUpperBound = (packet) => {
15212
+ const header = 1 + 4;
15213
+ const variable = 2 + 2 + 4 + 3;
15214
+ let size = header + variable + byteSize(packet.topic) + byteSize(packet.payload);
15215
+ const props = packet.properties;
15216
+ if (!props) {
15217
+ return size;
15218
+ }
15219
+ for (const name2 in props) {
15220
+ const value = props[name2];
15221
+ if (value == null)
15222
+ continue;
15223
+ if (typeof value === "number" || typeof value === "boolean") {
15224
+ size += 5;
15225
+ } else if (name2 === "userProperties") {
15226
+ for (const key in value) {
15227
+ const v = value[key];
15228
+ if (!Array.isArray(v)) {
15229
+ size += userPropertySize(key, v);
15230
+ } else {
15231
+ for (const item of v)
15232
+ size += userPropertySize(key, item);
15233
+ }
15234
+ }
15235
+ } else {
15236
+ size += 3 + byteSize(value);
15237
+ }
15238
+ }
15239
+ return size;
15240
+ };
15186
15241
  var defaultConnectOptions = {
15187
15242
  keepalive: 60,
15188
15243
  reschedulePings: true,
@@ -15366,7 +15421,20 @@ var mqtt = (() => {
15366
15421
  callback();
15367
15422
  }
15368
15423
  _nextId() {
15369
- return this.messageIdProvider.allocate();
15424
+ const skipped = [];
15425
+ let id = null;
15426
+ for (let attempt = 0; attempt < 65535; attempt++) {
15427
+ const candidate = this.messageIdProvider.allocate();
15428
+ if (candidate === null || !this.outgoing[candidate]) {
15429
+ id = candidate;
15430
+ break;
15431
+ }
15432
+ skipped.push(candidate);
15433
+ }
15434
+ for (const skippedId of skipped) {
15435
+ this.messageIdProvider.deallocate(skippedId);
15436
+ }
15437
+ return id;
15370
15438
  }
15371
15439
  getLastMessageId() {
15372
15440
  return this.messageIdProvider.getLastAllocated();
@@ -15460,7 +15528,13 @@ var mqtt = (() => {
15460
15528
  done();
15461
15529
  }
15462
15530
  };
15531
+ let parseFailed = false;
15463
15532
  writable._write = (buf, enc, done) => {
15533
+ if (parseFailed) {
15534
+ this.log("writable stream :: dropping chunk after a parser error");
15535
+ done();
15536
+ return;
15537
+ }
15464
15538
  completeParse = done;
15465
15539
  this.log("writable stream :: parsing buffer");
15466
15540
  parser.parse(buf);
@@ -15515,7 +15589,10 @@ var mqtt = (() => {
15515
15589
  }
15516
15590
  this._authenticationMethod = connectPacket.properties?.authenticationMethod;
15517
15591
  this._writePacket(connectPacket);
15518
- parser.on("error", this.emit.bind(this, "error"));
15592
+ parser.on("error", (err) => {
15593
+ parseFailed = true;
15594
+ this._onParserError(err, pump);
15595
+ });
15519
15596
  if (this.options.properties) {
15520
15597
  if (!this.options.properties.authenticationMethod && this.options.properties.authenticationData) {
15521
15598
  this.end(() => this.emit("error", new Error("Packet has no Authentication Method")));
@@ -15535,6 +15612,25 @@ var mqtt = (() => {
15535
15612
  this.connackTimer = setTimeout(() => this._onConnackTimeout(), this.options.connectTimeout);
15536
15613
  return this;
15537
15614
  }
15615
+ _onParserError(err, pump) {
15616
+ pump.discardParsedPackets();
15617
+ if (pump.isCurrent()) {
15618
+ this.log("_onParserError :: malformed packet, closing: %s", err.message);
15619
+ if (this.options.protocolVersion === 5 && !this.disconnecting && this.stream.writable) {
15620
+ this._writePacket({
15621
+ cmd: "disconnect",
15622
+ reasonCode: MALFORMED_PACKET
15623
+ });
15624
+ do {
15625
+ this.stream.uncork();
15626
+ } while (this.stream.writableCorked > 0);
15627
+ }
15628
+ this._cleanUp(true);
15629
+ } else {
15630
+ this.log("_onParserError :: stale connection: %s", err.message);
15631
+ }
15632
+ this.emit("error", new shared_1.ErrorWithReasonCode(`${ack_1.ReasonCodes[MALFORMED_PACKET]}: ${err.message}`, MALFORMED_PACKET));
15633
+ }
15538
15634
  _onConnackTimeout() {
15539
15635
  this.log("!!connectTimeout hit!! Calling _cleanUp with force `true`");
15540
15636
  this._cleanUp(true);
@@ -15574,7 +15670,7 @@ var mqtt = (() => {
15574
15670
  qos,
15575
15671
  retain,
15576
15672
  messageId,
15577
- dup
15673
+ dup: qos === 1 || qos === 2 ? dup : false
15578
15674
  };
15579
15675
  if (options.protocolVersion === 5) {
15580
15676
  packet.properties = properties;
@@ -16081,7 +16177,7 @@ var mqtt = (() => {
16081
16177
  let storePacket = packet;
16082
16178
  let err;
16083
16179
  if (storePacket.cmd === "publish") {
16084
- storePacket = (0, default_1.default)(packet);
16180
+ storePacket = { ...(0, default_1.default)(packet), dup: true };
16085
16181
  err = this._removeTopicAliasAndRecoverTopicName(storePacket);
16086
16182
  if (err) {
16087
16183
  return cb && cb(err);
@@ -16103,6 +16199,10 @@ var mqtt = (() => {
16103
16199
  alias = packet.properties.topicAlias;
16104
16200
  }
16105
16201
  const topic = packet.topic.toString();
16202
+ if (alias === 0) {
16203
+ this.log("applyTopicAlias :: error out of range. topic: %s - alias: %d", topic, alias);
16204
+ return new Error("Sending Topic Alias out of range");
16205
+ }
16106
16206
  if (this.topicAliasSend) {
16107
16207
  if (alias) {
16108
16208
  if (topic.length !== 0) {
@@ -16150,6 +16250,70 @@ var mqtt = (() => {
16150
16250
  }
16151
16251
  }
16152
16252
  }
16253
+ _checkOutgoingPublish(packet) {
16254
+ if (this.options.protocolVersion !== 5 || packet.cmd !== "publish") {
16255
+ return void 0;
16256
+ }
16257
+ if (packet.properties?.subscriptionIdentifier !== void 0) {
16258
+ return new Error("Publish refused: a client must not send a Subscription Identifier");
16259
+ }
16260
+ const server = this._serverProperties;
16261
+ if (!server || !this.connected) {
16262
+ return void 0;
16263
+ }
16264
+ if (server.maximumQoS !== void 0 && packet.qos > server.maximumQoS) {
16265
+ return new Error(`Publish refused: QoS ${packet.qos} exceeds the server Maximum QoS ${server.maximumQoS}`);
16266
+ }
16267
+ if (packet.retain && server.retainAvailable === false) {
16268
+ return new Error("Publish refused: the server does not support retained messages (Retain Available is 0)");
16269
+ }
16270
+ if (server.maximumPacketSize && publishSizeUpperBound(packet) > server.maximumPacketSize) {
16271
+ const size = encodedSize(this._publishAsSent(packet), this.options);
16272
+ if (size > server.maximumPacketSize) {
16273
+ return new Error(`Publish refused: packet size ${size} exceeds the server Maximum Packet Size ${server.maximumPacketSize}`);
16274
+ }
16275
+ }
16276
+ return void 0;
16277
+ }
16278
+ _publishAsSent(packet) {
16279
+ const topic = packet.topic.toString();
16280
+ const { autoAssignTopicAlias, autoUseTopicAlias } = this.options;
16281
+ if (!this.topicAliasSend || topic.length === 0 || packet.properties?.topicAlias || !(autoAssignTopicAlias || autoUseTopicAlias)) {
16282
+ return packet;
16283
+ }
16284
+ const alias = this.topicAliasSend.getAliasByTopic(topic);
16285
+ if (alias) {
16286
+ return {
16287
+ ...packet,
16288
+ topic: "",
16289
+ properties: { ...packet.properties, topicAlias: alias }
16290
+ };
16291
+ }
16292
+ if (!autoAssignTopicAlias) {
16293
+ return packet;
16294
+ }
16295
+ return {
16296
+ ...packet,
16297
+ properties: { ...packet.properties, topicAlias: 1 }
16298
+ };
16299
+ }
16300
+ _failPublish(packet, err, cb) {
16301
+ this.log("_failPublish :: %s", err.message);
16302
+ const { messageId } = packet;
16303
+ const entry = packet.qos > 0 ? this.outgoing[messageId] : void 0;
16304
+ if (!entry) {
16305
+ cb(err);
16306
+ return;
16307
+ }
16308
+ delete this.outgoing[messageId];
16309
+ this.outgoingStore.del({ messageId }, () => {
16310
+ this.messageIdProvider.deallocate(messageId);
16311
+ setImmediate2(() => {
16312
+ entry.cb(err);
16313
+ this._invokeStoreProcessingQueue();
16314
+ });
16315
+ });
16316
+ }
16153
16317
  _noop(err) {
16154
16318
  this.log("noop ::", err);
16155
16319
  }
@@ -16172,9 +16336,9 @@ var mqtt = (() => {
16172
16336
  this.log("_sendPacket :: (%s) :: start", this.options.clientId);
16173
16337
  cbStorePut = cbStorePut || this.noop;
16174
16338
  cb = cb || this.noop;
16175
- const err = this._applyTopicAlias(packet);
16339
+ const err = this._checkOutgoingPublish(packet) || this._applyTopicAlias(packet);
16176
16340
  if (err) {
16177
- cb(err);
16341
+ this._failPublish(packet, err, cb);
16178
16342
  return;
16179
16343
  }
16180
16344
  if (!this.connected) {
@@ -16312,6 +16476,10 @@ var mqtt = (() => {
16312
16476
  if (!sessionResumed) {
16313
16477
  this._discardIncomingQoS2State();
16314
16478
  }
16479
+ const discardOutgoingSession = this.options.protocolVersion === 5 && !this.options.clean && !sessionResumed;
16480
+ if (discardOutgoingSession) {
16481
+ this.log("_onConnect :: session not resumed, dropping sent messages from the outgoing store");
16482
+ }
16315
16483
  this.messageIdProvider.clear();
16316
16484
  this.connected = true;
16317
16485
  this._setupKeepaliveManager();
@@ -16349,6 +16517,11 @@ var mqtt = (() => {
16349
16517
  storeDeliver();
16350
16518
  return;
16351
16519
  }
16520
+ const neverSent = packet2.cmd === "publish" && !packet2.dup;
16521
+ if (discardOutgoingSession && !neverSent) {
16522
+ this._discardOutgoingSessionPacket(packet2, storeDeliver);
16523
+ return;
16524
+ }
16352
16525
  if (!this.disconnecting && !this.reconnectTimer) {
16353
16526
  cb = this.outgoing[packet2.messageId] ? this.outgoing[packet2.messageId].cb : null;
16354
16527
  this.outgoing[packet2.messageId] = {
@@ -16363,7 +16536,11 @@ var mqtt = (() => {
16363
16536
  };
16364
16537
  this._packetIdsDuringStoreProcessing[packet2.messageId] = true;
16365
16538
  if (this.messageIdProvider.register(packet2.messageId)) {
16366
- this._sendPacket(packet2, void 0, void 0, true);
16539
+ if (neverSent) {
16540
+ this._sendNeverSentPacket(packet2);
16541
+ } else {
16542
+ this._sendPacket(packet2, void 0, void 0, true);
16543
+ }
16367
16544
  } else {
16368
16545
  this.log("messageId: %d has already used.", packet2.messageId);
16369
16546
  }
@@ -16415,6 +16592,30 @@ var mqtt = (() => {
16415
16592
  }
16416
16593
  this._storeProcessingQueue.splice(0);
16417
16594
  }
16595
+ _sendNeverSentPacket(packet) {
16596
+ this.outgoingStore.put({ ...packet, dup: true }, (err) => {
16597
+ if (err) {
16598
+ this.log("_sendNeverSentPacket :: put error for messageId %d, sending anyway: %o", packet.messageId, err);
16599
+ }
16600
+ this._sendPacket(packet, void 0, void 0, true);
16601
+ });
16602
+ }
16603
+ _discardOutgoingSessionPacket(packet, next) {
16604
+ const { messageId } = packet;
16605
+ const pending = this.outgoing[messageId];
16606
+ delete this.outgoing[messageId];
16607
+ this._packetIdsDuringStoreProcessing[messageId] = true;
16608
+ this.log("_discardOutgoingSessionPacket :: session not resumed, dropping %s %d (topic %s, %s)", packet.cmd, messageId, packet.topic, pending ? "callback failed" : "no pending callback");
16609
+ this.outgoingStore.del({ messageId }, (err) => {
16610
+ if (err) {
16611
+ this.log("_discardOutgoingSessionPacket :: del error for messageId %d: %o", messageId, err);
16612
+ }
16613
+ if (pending) {
16614
+ pending.cb(new Error(packet.cmd === "pubrel" ? "Session lost (Session Present 0) before PUBCOMP: the delivery outcome of the QoS 2 message is unknown" : "Session lost (Session Present 0): the message was sent but not acknowledged, and is not sent again"));
16615
+ }
16616
+ (0, shared_1.nextTick)(next);
16617
+ });
16618
+ }
16418
16619
  _removeOutgoingAndStoreMessage(messageId, cb) {
16419
16620
  delete this.outgoing[messageId];
16420
16621
  this.outgoingStore.del({ messageId }, (err, packet) => {
@@ -20633,13 +20834,11 @@ var mqtt = (() => {
20633
20834
  var buildStream = (client, opts) => {
20634
20835
  opts.port = opts.port || 8883;
20635
20836
  opts.host = opts.hostname || opts.host || "localhost";
20636
- if (net_1.default.isIP(opts.host) === 0 && !opts.servername) {
20637
- opts.servername = opts.host;
20638
- }
20639
20837
  opts.rejectUnauthorized = opts.rejectUnauthorized !== false;
20640
20838
  delete opts.path;
20641
20839
  debug("port %d host %s rejectUnauthorized %b", opts.port, opts.host, opts.rejectUnauthorized);
20642
- const connection = connect(opts);
20840
+ const servername = opts.servername || (net_1.default.isIP(opts.host) === 0 ? opts.host : void 0);
20841
+ const connection = connect({ ...opts, servername });
20643
20842
  connection.on("secureConnect", () => {
20644
20843
  if (opts.rejectUnauthorized && !connection.authorized) {
20645
20844
  connection.emit("error", new Error("TLS not authorized"));
@@ -20913,7 +21112,34 @@ var mqtt = (() => {
20913
21112
  browser_process_exports.nextTick = setImmediate;
20914
21113
  }
20915
21114
  var debug = (0, debug_1.default)("mqttjs");
20916
- var protocols = null;
21115
+ var nodeProtocols = null;
21116
+ var browserProtocols = null;
21117
+ function loadNodeProtocols() {
21118
+ if (!nodeProtocols) {
21119
+ nodeProtocols = {};
21120
+ nodeProtocols.ws = require_ws().streamBuilder;
21121
+ nodeProtocols.wss = require_ws().streamBuilder;
21122
+ nodeProtocols.mqtt = require_tcp().default;
21123
+ nodeProtocols.tcp = require_tcp().default;
21124
+ nodeProtocols.ssl = require_tls().default;
21125
+ nodeProtocols.tls = nodeProtocols.ssl;
21126
+ nodeProtocols.mqtts = require_tls().default;
21127
+ }
21128
+ return nodeProtocols;
21129
+ }
21130
+ function loadBrowserProtocols() {
21131
+ if (!browserProtocols) {
21132
+ browserProtocols = {};
21133
+ browserProtocols.ws = require_ws().browserStreamBuilder;
21134
+ browserProtocols.wss = require_ws().browserStreamBuilder;
21135
+ browserProtocols.wx = require_wx().default;
21136
+ browserProtocols.wxs = require_wx().default;
21137
+ browserProtocols.ali = require_ali().default;
21138
+ browserProtocols.alis = require_ali().default;
21139
+ }
21140
+ return browserProtocols;
21141
+ }
21142
+ var SECURE_PROTOCOLS = ["mqtts", "tls", "ssl", "wss", "wxs", "alis"];
20917
21143
  function getDefaultWebSocketProtocol() {
20918
21144
  if (typeof location !== "undefined") {
20919
21145
  return location.protocol === "https:" ? "wss" : "ws";
@@ -20924,18 +21150,19 @@ var mqtt = (() => {
20924
21150
  return "ws";
20925
21151
  }
20926
21152
  function parseAuthOptions(opts) {
20927
- let matches;
20928
21153
  if (opts.auth) {
20929
- matches = opts.auth.match(/^(.+):(.+)$/);
20930
- if (matches) {
20931
- const [, username, password] = matches;
20932
- opts.username = username;
20933
- opts.password = password;
21154
+ const separator = opts.auth.indexOf(":");
21155
+ if (separator !== -1) {
21156
+ opts.username = opts.auth.slice(0, separator);
21157
+ opts.password = opts.auth.slice(separator + 1);
20934
21158
  } else {
20935
21159
  opts.username = opts.auth;
20936
21160
  }
20937
21161
  }
20938
21162
  }
21163
+ function stripProtocolColon(protocol) {
21164
+ return protocol?.replace(/:$/, "").toLowerCase();
21165
+ }
20939
21166
  function connect(brokerUrl, opts) {
20940
21167
  debug("connecting to an MQTT broker...");
20941
21168
  if (typeof brokerUrl === "object" && !opts) {
@@ -20959,8 +21186,9 @@ var mqtt = (() => {
20959
21186
  if (!opts.protocol && !isRelativeWebSocketUrl) {
20960
21187
  throw new Error("Missing protocol");
20961
21188
  }
20962
- opts.protocol = (opts.protocol || getDefaultWebSocketProtocol()).replace(/:$/, "");
21189
+ opts.protocol = opts.protocol || getDefaultWebSocketProtocol();
20963
21190
  }
21191
+ opts.protocol = stripProtocolColon(opts.protocol);
20964
21192
  opts.unixSocket = opts.unixSocket || opts.protocol?.includes("+unix");
20965
21193
  if (opts.unixSocket) {
20966
21194
  opts.protocol = opts.protocol.replace("+unix", "");
@@ -20978,7 +21206,7 @@ var mqtt = (() => {
20978
21206
  }
20979
21207
  if (opts.cert && opts.key) {
20980
21208
  if (opts.protocol) {
20981
- if (["mqtts", "wss", "wxs", "alis"].indexOf(opts.protocol) === -1) {
21209
+ if (!SECURE_PROTOCOLS.includes(opts.protocol)) {
20982
21210
  switch (opts.protocol) {
20983
21211
  case "mqtt":
20984
21212
  opts.protocol = "mqtts";
@@ -21000,27 +21228,10 @@ var mqtt = (() => {
21000
21228
  throw new Error("Missing secure protocol key");
21001
21229
  }
21002
21230
  }
21003
- if (!protocols) {
21004
- protocols = {};
21005
- if (!is_browser_1.default && !opts.forceNativeWebSocket) {
21006
- protocols.ws = require_ws().streamBuilder;
21007
- protocols.wss = require_ws().streamBuilder;
21008
- protocols.mqtt = require_tcp().default;
21009
- protocols.tcp = require_tcp().default;
21010
- protocols.ssl = require_tls().default;
21011
- protocols.tls = protocols.ssl;
21012
- protocols.mqtts = require_tls().default;
21013
- } else {
21014
- protocols.ws = require_ws().browserStreamBuilder;
21015
- protocols.wss = require_ws().browserStreamBuilder;
21016
- protocols.wx = require_wx().default;
21017
- protocols.wxs = require_wx().default;
21018
- protocols.ali = require_ali().default;
21019
- protocols.alis = require_ali().default;
21020
- }
21021
- }
21231
+ const protocols = is_browser_1.default || opts.forceNativeWebSocket ? loadBrowserProtocols() : loadNodeProtocols();
21022
21232
  if (!protocols[opts.protocol]) {
21023
- const isSecure = ["mqtts", "wss"].indexOf(opts.protocol) !== -1;
21233
+ const requested = opts.protocol;
21234
+ const isSecure = SECURE_PROTOCOLS.includes(requested);
21024
21235
  opts.protocol = [
21025
21236
  "mqtt",
21026
21237
  "mqtts",
@@ -21030,12 +21241,16 @@ var mqtt = (() => {
21030
21241
  "wxs",
21031
21242
  "ali",
21032
21243
  "alis"
21033
- ].filter((key, index) => {
21034
- if (isSecure && index % 2 === 0) {
21244
+ ].filter((key) => {
21245
+ if (isSecure && !SECURE_PROTOCOLS.includes(key)) {
21035
21246
  return false;
21036
21247
  }
21037
21248
  return typeof protocols[key] === "function";
21038
21249
  })[0];
21250
+ if (isSecure && !opts.protocol) {
21251
+ throw new Error(`No secure transport available for protocol "${requested}"`);
21252
+ }
21253
+ debug("no transport for %s, falling back to %s", requested, opts.protocol);
21039
21254
  }
21040
21255
  if (opts.clean === false && !opts.clientId) {
21041
21256
  throw new Error("Missing clientId for unclean clients");
@@ -21050,7 +21265,7 @@ var mqtt = (() => {
21050
21265
  }
21051
21266
  opts.host = opts.servers[client2._reconnectCount].host;
21052
21267
  opts.port = opts.servers[client2._reconnectCount].port;
21053
- opts.protocol = !opts.servers[client2._reconnectCount].protocol ? opts.defaultProtocol : opts.servers[client2._reconnectCount].protocol;
21268
+ opts.protocol = !opts.servers[client2._reconnectCount].protocol ? opts.defaultProtocol : stripProtocolColon(opts.servers[client2._reconnectCount].protocol);
21054
21269
  opts.hostname = opts.host;
21055
21270
  client2._reconnectCount++;
21056
21271
  }