mqtt 5.5.4 → 5.5.6
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/build/lib/client.d.ts +4 -1
- package/build/lib/client.js +23 -17
- package/build/lib/client.js.map +1 -1
- package/build/lib/connect/tcp.js.map +1 -1
- package/build/lib/connect/ws.js +1 -3
- package/build/lib/connect/ws.js.map +1 -1
- package/build/lib/handlers/index.js +4 -1
- package/build/lib/handlers/index.js.map +1 -1
- package/build/lib/is-browser.js +12 -1
- package/build/lib/is-browser.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +3 -3
- package/dist/mqtt.js +41 -23
- package/dist/mqtt.min.js +3 -3
- package/package.json +1 -1
- package/src/lib/client.ts +35 -23
- package/src/lib/connect/tcp.ts +0 -1
- package/src/lib/connect/ws.ts +5 -3
- package/src/lib/handlers/index.ts +9 -1
- package/src/lib/is-browser.ts +25 -2
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.5.
|
|
12637
|
+
module.exports = { version: "5.5.6" };
|
|
12638
12638
|
}
|
|
12639
12639
|
});
|
|
12640
12640
|
|
|
@@ -17191,6 +17191,10 @@ var mqtt = (() => {
|
|
|
17191
17191
|
});
|
|
17192
17192
|
return client;
|
|
17193
17193
|
}
|
|
17194
|
+
client.pingResp = Date.now();
|
|
17195
|
+
if (!["pingresp", "publish"].includes(packet.cmd)) {
|
|
17196
|
+
client["_shiftPingInterval"]();
|
|
17197
|
+
}
|
|
17194
17198
|
client.log("_handlePacket :: emitting packetreceive");
|
|
17195
17199
|
client.emit("packetreceive", packet);
|
|
17196
17200
|
switch (packet.cmd) {
|
|
@@ -17217,7 +17221,6 @@ var mqtt = (() => {
|
|
|
17217
17221
|
done();
|
|
17218
17222
|
break;
|
|
17219
17223
|
case "pingresp":
|
|
17220
|
-
client.pingResp = true;
|
|
17221
17224
|
done();
|
|
17222
17225
|
break;
|
|
17223
17226
|
case "disconnect":
|
|
@@ -17264,7 +17267,18 @@ var mqtt = (() => {
|
|
|
17264
17267
|
init_navigator();
|
|
17265
17268
|
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
17266
17269
|
exports5.isReactNativeBrowser = exports5.isWebWorker = void 0;
|
|
17267
|
-
var isStandardBrowserEnv = () =>
|
|
17270
|
+
var isStandardBrowserEnv = () => {
|
|
17271
|
+
var _a;
|
|
17272
|
+
if (typeof window !== "undefined") {
|
|
17273
|
+
const electronRenderCheck = ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) === null || _a === void 0 ? void 0 : _a.toLowerCase().indexOf(" electron/")) > -1;
|
|
17274
|
+
if (electronRenderCheck && (process_exports === null || process_exports === void 0 ? void 0 : process_exports.versions)) {
|
|
17275
|
+
const electronMainCheck = Object.prototype.hasOwnProperty.call(process_exports.versions, "electron");
|
|
17276
|
+
return !electronMainCheck;
|
|
17277
|
+
}
|
|
17278
|
+
return typeof window.document !== "undefined";
|
|
17279
|
+
}
|
|
17280
|
+
return false;
|
|
17281
|
+
};
|
|
17268
17282
|
var isWebWorkerEnv = () => {
|
|
17269
17283
|
var _a, _b;
|
|
17270
17284
|
return Boolean(typeof self === "object" && ((_b = (_a = self === null || self === void 0 ? void 0 : self.constructor) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.includes("WorkerGlobalScope")));
|
|
@@ -17838,11 +17852,7 @@ var mqtt = (() => {
|
|
|
17838
17852
|
this.connected = false;
|
|
17839
17853
|
this.log("close :: clearing connackTimer");
|
|
17840
17854
|
clearTimeout(this.connackTimer);
|
|
17841
|
-
this.
|
|
17842
|
-
if (this.pingTimer) {
|
|
17843
|
-
this.pingTimer.destroy();
|
|
17844
|
-
this.pingTimer = null;
|
|
17845
|
-
}
|
|
17855
|
+
this._destroyPingTimer();
|
|
17846
17856
|
if (this.topicAliasRecv) {
|
|
17847
17857
|
this.topicAliasRecv.clear();
|
|
17848
17858
|
}
|
|
@@ -18471,11 +18481,7 @@ var mqtt = (() => {
|
|
|
18471
18481
|
this._clearReconnect();
|
|
18472
18482
|
this._setupReconnect();
|
|
18473
18483
|
}
|
|
18474
|
-
|
|
18475
|
-
this.log("_cleanUp :: destroy pingTimer");
|
|
18476
|
-
this.pingTimer.destroy();
|
|
18477
|
-
this.pingTimer = null;
|
|
18478
|
-
}
|
|
18484
|
+
this._destroyPingTimer();
|
|
18479
18485
|
if (done && !this.connected) {
|
|
18480
18486
|
this.log("_cleanUp :: (%s) :: removing stream `done` callback `close` listener", this.options.clientId);
|
|
18481
18487
|
this.stream.removeListener("close", done);
|
|
@@ -18554,7 +18560,6 @@ var mqtt = (() => {
|
|
|
18554
18560
|
this.log("_writePacket :: packet: %O", packet);
|
|
18555
18561
|
this.log("_writePacket :: emitting `packetsend`");
|
|
18556
18562
|
this.emit("packetsend", packet);
|
|
18557
|
-
this._shiftPingInterval();
|
|
18558
18563
|
this.log("_writePacket :: writing to stream");
|
|
18559
18564
|
const result = mqtt_packet_1.default.writeToStream(packet, this.stream, this.options);
|
|
18560
18565
|
this.log("_writePacket :: writeToStream result %s", result);
|
|
@@ -18640,29 +18645,44 @@ var mqtt = (() => {
|
|
|
18640
18645
|
_setupPingTimer() {
|
|
18641
18646
|
this.log("_setupPingTimer :: keepalive %d (seconds)", this.options.keepalive);
|
|
18642
18647
|
if (!this.pingTimer && this.options.keepalive) {
|
|
18643
|
-
this.pingResp = true;
|
|
18644
18648
|
this.pingTimer = new PingTimer_1.default(this.options.keepalive, () => {
|
|
18645
18649
|
this._checkPing();
|
|
18646
18650
|
}, this.options.timerVariant);
|
|
18651
|
+
this.pingResp = Date.now();
|
|
18652
|
+
}
|
|
18653
|
+
}
|
|
18654
|
+
_destroyPingTimer() {
|
|
18655
|
+
if (this.pingTimer) {
|
|
18656
|
+
this.log("_destroyPingTimer :: destroying ping timer");
|
|
18657
|
+
this.pingTimer.destroy();
|
|
18658
|
+
this.pingTimer = null;
|
|
18647
18659
|
}
|
|
18648
18660
|
}
|
|
18649
18661
|
_shiftPingInterval() {
|
|
18650
18662
|
if (this.pingTimer && this.options.keepalive && this.options.reschedulePings) {
|
|
18651
|
-
this.
|
|
18663
|
+
this._reschedulePing();
|
|
18652
18664
|
}
|
|
18653
18665
|
}
|
|
18666
|
+
_reschedulePing() {
|
|
18667
|
+
this.log("_reschedulePing :: rescheduling ping");
|
|
18668
|
+
this.pingTimer.reschedule();
|
|
18669
|
+
}
|
|
18654
18670
|
_checkPing() {
|
|
18655
18671
|
this.log("_checkPing :: checking ping...");
|
|
18656
|
-
|
|
18657
|
-
|
|
18658
|
-
this.
|
|
18659
|
-
this.
|
|
18672
|
+
const timeSincePing = Date.now() - this.pingResp - 100;
|
|
18673
|
+
if (timeSincePing <= this.options.keepalive * 1e3) {
|
|
18674
|
+
this.log("_checkPing :: ping response received in time");
|
|
18675
|
+
this._sendPing();
|
|
18660
18676
|
} else {
|
|
18661
18677
|
this.emit("error", new Error("Keepalive timeout"));
|
|
18662
18678
|
this.log("_checkPing :: calling _cleanUp with force true");
|
|
18663
18679
|
this._cleanUp(true);
|
|
18664
18680
|
}
|
|
18665
18681
|
}
|
|
18682
|
+
_sendPing() {
|
|
18683
|
+
this.log("_sendPing :: sending pingreq");
|
|
18684
|
+
this._sendPacket({ cmd: "pingreq" });
|
|
18685
|
+
}
|
|
18666
18686
|
_resubscribe() {
|
|
18667
18687
|
this.log("_resubscribe");
|
|
18668
18688
|
const _resubscribeTopicsKeys = Object.keys(this._resubscribeTopics);
|
|
@@ -21138,9 +21158,6 @@ var mqtt = (() => {
|
|
|
21138
21158
|
}
|
|
21139
21159
|
function setDefaultOpts(opts) {
|
|
21140
21160
|
const options = opts;
|
|
21141
|
-
if (!opts.hostname) {
|
|
21142
|
-
options.hostname = "localhost";
|
|
21143
|
-
}
|
|
21144
21161
|
if (!opts.port) {
|
|
21145
21162
|
if (opts.protocol === "wss") {
|
|
21146
21163
|
options.port = 443;
|
|
@@ -21211,6 +21228,7 @@ var mqtt = (() => {
|
|
|
21211
21228
|
var streamBuilder = (client, opts) => {
|
|
21212
21229
|
debug("streamBuilder");
|
|
21213
21230
|
const options = setDefaultOpts(opts);
|
|
21231
|
+
options.hostname = options.hostname || options.host || "localhost";
|
|
21214
21232
|
const url = buildUrl(options, client);
|
|
21215
21233
|
const socket = createWebSocket(client, url, options);
|
|
21216
21234
|
const webSocketStream = ws_1.default.createWebSocketStream(socket, options.wsOptions);
|