mqtt 5.3.6 → 5.5.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/README.md +2 -1
- package/build/lib/BufferedDuplex.d.ts +1 -0
- package/build/lib/BufferedDuplex.js +5 -0
- package/build/lib/BufferedDuplex.js.map +1 -1
- package/build/lib/PingTimer.d.ts +3 -3
- package/build/lib/PingTimer.js +10 -34
- package/build/lib/PingTimer.js.map +1 -1
- package/build/lib/client.d.ts +3 -1
- package/build/lib/client.js +12 -1
- package/build/lib/client.js.map +1 -1
- package/build/lib/connect/ws.js.map +1 -1
- package/build/lib/get-timer.d.ts +8 -0
- package/build/lib/get-timer.js +51 -0
- package/build/lib/get-timer.js.map +1 -0
- package/build/lib/shared.d.ts +1 -0
- package/build/lib/shared.js.map +1 -1
- package/build/mqtt.d.ts +2 -1
- package/build/mqtt.js +3 -1
- package/build/mqtt.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.esm.js +5 -5
- package/dist/mqtt.js +101 -43
- package/dist/mqtt.min.js +5 -5
- package/package.json +4 -4
- package/src/lib/BufferedDuplex.ts +6 -0
- package/src/lib/PingTimer.ts +16 -19
- package/src/lib/client.ts +29 -4
- package/src/lib/connect/ws.ts +2 -0
- package/src/lib/get-timer.ts +38 -0
- package/src/lib/shared.ts +2 -0
- package/src/mqtt.ts +2 -0
package/dist/mqtt.js
CHANGED
|
@@ -17247,6 +17247,27 @@ var mqtt = (() => {
|
|
|
17247
17247
|
}
|
|
17248
17248
|
});
|
|
17249
17249
|
|
|
17250
|
+
// build/lib/is-browser.js
|
|
17251
|
+
var require_is_browser = __commonJS({
|
|
17252
|
+
"build/lib/is-browser.js"(exports5) {
|
|
17253
|
+
"use strict";
|
|
17254
|
+
init_buffer2();
|
|
17255
|
+
init_process2();
|
|
17256
|
+
init_navigator();
|
|
17257
|
+
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
17258
|
+
exports5.isWebWorker = void 0;
|
|
17259
|
+
var isStandardBrowserEnv = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
17260
|
+
var isWebWorkerEnv = () => {
|
|
17261
|
+
var _a, _b;
|
|
17262
|
+
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")));
|
|
17263
|
+
};
|
|
17264
|
+
var isReactNativeEnv = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
17265
|
+
var isBrowser = isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv();
|
|
17266
|
+
exports5.isWebWorker = isWebWorkerEnv();
|
|
17267
|
+
exports5.default = isBrowser;
|
|
17268
|
+
}
|
|
17269
|
+
});
|
|
17270
|
+
|
|
17250
17271
|
// node_modules/fast-unique-numbers/build/es5/bundle.js
|
|
17251
17272
|
var require_bundle = __commonJS({
|
|
17252
17273
|
"node_modules/fast-unique-numbers/build/es5/bundle.js"(exports5, module) {
|
|
@@ -17408,7 +17429,8 @@ var mqtt = (() => {
|
|
|
17408
17429
|
}
|
|
17409
17430
|
});
|
|
17410
17431
|
};
|
|
17411
|
-
var setInterval2 = function setInterval3(func
|
|
17432
|
+
var setInterval2 = function setInterval3(func) {
|
|
17433
|
+
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
17412
17434
|
var timerId = fastUniqueNumbers.generateUniqueNumber(scheduledIntervalFunctions);
|
|
17413
17435
|
scheduledIntervalFunctions.set(timerId, function() {
|
|
17414
17436
|
func();
|
|
@@ -17437,7 +17459,8 @@ var mqtt = (() => {
|
|
|
17437
17459
|
});
|
|
17438
17460
|
return timerId;
|
|
17439
17461
|
};
|
|
17440
|
-
var setTimeout2 = function setTimeout3(func
|
|
17462
|
+
var setTimeout2 = function setTimeout3(func) {
|
|
17463
|
+
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
17441
17464
|
var timerId = fastUniqueNumbers.generateUniqueNumber(scheduledTimeoutFunctions);
|
|
17442
17465
|
scheduledTimeoutFunctions.set(timerId, func);
|
|
17443
17466
|
worker.postMessage({
|
|
@@ -17491,7 +17514,7 @@ var mqtt = (() => {
|
|
|
17491
17514
|
return broker;
|
|
17492
17515
|
};
|
|
17493
17516
|
};
|
|
17494
|
-
var worker = `(()=>{var e={
|
|
17517
|
+
var worker = `(()=>{var e={472:(e,t,r)=>{var o,i;void 0===(i="function"==typeof(o=function(){"use strict";var e=new Map,t=new Map,r=function(t){var r=e.get(t);if(void 0===r)throw new Error('There is no interval scheduled with the given id "'.concat(t,'".'));clearTimeout(r),e.delete(t)},o=function(e){var r=t.get(e);if(void 0===r)throw new Error('There is no timeout scheduled with the given id "'.concat(e,'".'));clearTimeout(r),t.delete(e)},i=function(e,t){var r,o=performance.now();return{expected:o+(r=e-Math.max(0,o-t)),remainingDelay:r}},n=function e(t,r,o,i){var n=performance.now();n>o?postMessage({id:null,method:"call",params:{timerId:r,timerType:i}}):t.set(r,setTimeout(e,o-n,t,r,o,i))},a=function(t,r,o){var a=i(t,o),s=a.expected,d=a.remainingDelay;e.set(r,setTimeout(n,d,e,r,s,"interval"))},s=function(e,r,o){var a=i(e,o),s=a.expected,d=a.remainingDelay;t.set(r,setTimeout(n,d,t,r,s,"timeout"))};addEventListener("message",(function(e){var t=e.data;try{if("clear"===t.method){var i=t.id,n=t.params,d=n.timerId,c=n.timerType;if("interval"===c)r(d),postMessage({error:null,id:i});else{if("timeout"!==c)throw new Error('The given type "'.concat(c,'" is not supported'));o(d),postMessage({error:null,id:i})}}else{if("set"!==t.method)throw new Error('The given method "'.concat(t.method,'" is not supported'));var u=t.params,l=u.delay,p=u.now,m=u.timerId,v=u.timerType;if("interval"===v)a(l,m,p);else{if("timeout"!==v)throw new Error('The given type "'.concat(v,'" is not supported'));s(l,m,p)}}}catch(e){postMessage({error:{message:e.message},id:t.id,result:null})}}))})?o.call(t,r,t,e):o)||(e.exports=i)}},t={};function r(o){var i=t[o];if(void 0!==i)return i.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,r),n.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";r(472)})()})();`;
|
|
17495
17518
|
var loadOrReturnBroker = createLoadOrReturnBroker(workerTimersBroker.load, worker);
|
|
17496
17519
|
var clearInterval2 = function clearInterval3(timerId) {
|
|
17497
17520
|
return loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -17499,11 +17522,13 @@ var mqtt = (() => {
|
|
|
17499
17522
|
var clearTimeout2 = function clearTimeout3(timerId) {
|
|
17500
17523
|
return loadOrReturnBroker().clearTimeout(timerId);
|
|
17501
17524
|
};
|
|
17502
|
-
var setInterval2 = function setInterval3(
|
|
17503
|
-
|
|
17525
|
+
var setInterval2 = function setInterval3() {
|
|
17526
|
+
var _loadOrReturnBroker;
|
|
17527
|
+
return (_loadOrReturnBroker = loadOrReturnBroker()).setInterval.apply(_loadOrReturnBroker, arguments);
|
|
17504
17528
|
};
|
|
17505
|
-
var setTimeout$1 = function setTimeout2(
|
|
17506
|
-
|
|
17529
|
+
var setTimeout$1 = function setTimeout2() {
|
|
17530
|
+
var _loadOrReturnBroker2;
|
|
17531
|
+
return (_loadOrReturnBroker2 = loadOrReturnBroker()).setTimeout.apply(_loadOrReturnBroker2, arguments);
|
|
17507
17532
|
};
|
|
17508
17533
|
exports6.clearInterval = clearInterval2;
|
|
17509
17534
|
exports6.clearTimeout = clearTimeout2;
|
|
@@ -17513,30 +17538,9 @@ var mqtt = (() => {
|
|
|
17513
17538
|
}
|
|
17514
17539
|
});
|
|
17515
17540
|
|
|
17516
|
-
// build/lib/
|
|
17517
|
-
var
|
|
17518
|
-
"build/lib/
|
|
17519
|
-
"use strict";
|
|
17520
|
-
init_buffer2();
|
|
17521
|
-
init_process2();
|
|
17522
|
-
init_navigator();
|
|
17523
|
-
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
17524
|
-
exports5.isWebWorker = void 0;
|
|
17525
|
-
var isStandardBrowserEnv = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
17526
|
-
var isWebWorkerEnv = () => {
|
|
17527
|
-
var _a, _b;
|
|
17528
|
-
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")));
|
|
17529
|
-
};
|
|
17530
|
-
var isReactNativeEnv = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
17531
|
-
var isBrowser = isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv();
|
|
17532
|
-
exports5.isWebWorker = isWebWorkerEnv();
|
|
17533
|
-
exports5.default = isBrowser;
|
|
17534
|
-
}
|
|
17535
|
-
});
|
|
17536
|
-
|
|
17537
|
-
// build/lib/PingTimer.js
|
|
17538
|
-
var require_PingTimer = __commonJS({
|
|
17539
|
-
"build/lib/PingTimer.js"(exports5) {
|
|
17541
|
+
// build/lib/get-timer.js
|
|
17542
|
+
var require_get_timer = __commonJS({
|
|
17543
|
+
"build/lib/get-timer.js"(exports5) {
|
|
17540
17544
|
"use strict";
|
|
17541
17545
|
init_buffer2();
|
|
17542
17546
|
init_process2();
|
|
@@ -17574,27 +17578,64 @@ var mqtt = (() => {
|
|
|
17574
17578
|
return result;
|
|
17575
17579
|
};
|
|
17576
17580
|
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
17577
|
-
var worker_timers_1 = require_bundle3();
|
|
17578
17581
|
var is_browser_1 = __importStar(require_is_browser());
|
|
17582
|
+
var worker_timers_1 = require_bundle3();
|
|
17583
|
+
var workerTimer = {
|
|
17584
|
+
set: worker_timers_1.setTimeout,
|
|
17585
|
+
clear: worker_timers_1.clearTimeout
|
|
17586
|
+
};
|
|
17587
|
+
var nativeTimer = {
|
|
17588
|
+
set: (func, time) => setTimeout(func, time),
|
|
17589
|
+
clear: (timerId) => clearTimeout(timerId)
|
|
17590
|
+
};
|
|
17591
|
+
var getTimer = (variant) => {
|
|
17592
|
+
switch (variant) {
|
|
17593
|
+
case "native": {
|
|
17594
|
+
return nativeTimer;
|
|
17595
|
+
}
|
|
17596
|
+
case "worker": {
|
|
17597
|
+
return workerTimer;
|
|
17598
|
+
}
|
|
17599
|
+
case "auto":
|
|
17600
|
+
default: {
|
|
17601
|
+
return is_browser_1.default && !is_browser_1.isWebWorker ? workerTimer : nativeTimer;
|
|
17602
|
+
}
|
|
17603
|
+
}
|
|
17604
|
+
};
|
|
17605
|
+
exports5.default = getTimer;
|
|
17606
|
+
}
|
|
17607
|
+
});
|
|
17608
|
+
|
|
17609
|
+
// build/lib/PingTimer.js
|
|
17610
|
+
var require_PingTimer = __commonJS({
|
|
17611
|
+
"build/lib/PingTimer.js"(exports5) {
|
|
17612
|
+
"use strict";
|
|
17613
|
+
init_buffer2();
|
|
17614
|
+
init_process2();
|
|
17615
|
+
init_navigator();
|
|
17616
|
+
var __importDefault = exports5 && exports5.__importDefault || function(mod) {
|
|
17617
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
17618
|
+
};
|
|
17619
|
+
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
17620
|
+
var get_timer_1 = __importDefault(require_get_timer());
|
|
17579
17621
|
var PingTimer = class {
|
|
17580
|
-
constructor(keepalive, checkPing) {
|
|
17581
|
-
this._setTimeout = is_browser_1.default && !is_browser_1.isWebWorker ? worker_timers_1.setTimeout : (func, time) => setTimeout(func, time);
|
|
17582
|
-
this._clearTimeout = is_browser_1.default && !is_browser_1.isWebWorker ? worker_timers_1.clearTimeout : (timer) => clearTimeout(timer);
|
|
17622
|
+
constructor(keepalive, checkPing, variant) {
|
|
17583
17623
|
this.keepalive = keepalive * 1e3;
|
|
17584
17624
|
this.checkPing = checkPing;
|
|
17625
|
+
this.timer = (0, get_timer_1.default)(variant);
|
|
17585
17626
|
this.reschedule();
|
|
17586
17627
|
}
|
|
17587
17628
|
clear() {
|
|
17588
|
-
if (this.
|
|
17589
|
-
this.
|
|
17590
|
-
this.
|
|
17629
|
+
if (this.timerId) {
|
|
17630
|
+
this.timer.clear(this.timerId);
|
|
17631
|
+
this.timerId = null;
|
|
17591
17632
|
}
|
|
17592
17633
|
}
|
|
17593
17634
|
reschedule() {
|
|
17594
17635
|
this.clear();
|
|
17595
|
-
this.
|
|
17636
|
+
this.timerId = this.timer.set(() => {
|
|
17596
17637
|
this.checkPing();
|
|
17597
|
-
if (this.
|
|
17638
|
+
if (this.timerId) {
|
|
17598
17639
|
this.reschedule();
|
|
17599
17640
|
}
|
|
17600
17641
|
}, this.keepalive);
|
|
@@ -17659,6 +17700,7 @@ var mqtt = (() => {
|
|
|
17659
17700
|
var shared_1 = require_shared();
|
|
17660
17701
|
var TypedEmitter_1 = require_TypedEmitter();
|
|
17661
17702
|
var PingTimer_1 = __importDefault(require_PingTimer());
|
|
17703
|
+
var is_browser_1 = __importStar(require_is_browser());
|
|
17662
17704
|
var setImmediate = globalThis.setImmediate || ((...args) => {
|
|
17663
17705
|
const callback = args.shift();
|
|
17664
17706
|
(0, shared_1.nextTick)(() => {
|
|
@@ -17674,7 +17716,8 @@ var mqtt = (() => {
|
|
|
17674
17716
|
connectTimeout: 30 * 1e3,
|
|
17675
17717
|
clean: true,
|
|
17676
17718
|
resubscribe: true,
|
|
17677
|
-
writeCache: true
|
|
17719
|
+
writeCache: true,
|
|
17720
|
+
timerVariant: "auto"
|
|
17678
17721
|
};
|
|
17679
17722
|
var MqttClient = class _MqttClient extends TypedEmitter_1.TypedEventEmitter {
|
|
17680
17723
|
static defaultId() {
|
|
@@ -17692,6 +17735,12 @@ var mqtt = (() => {
|
|
|
17692
17735
|
}
|
|
17693
17736
|
this.log = this.options.log || (0, debug_1.default)("mqttjs:client");
|
|
17694
17737
|
this.noop = this._noop.bind(this);
|
|
17738
|
+
this.log("MqttClient :: version:", _MqttClient.VERSION);
|
|
17739
|
+
if (is_browser_1.isWebWorker) {
|
|
17740
|
+
this.log("MqttClient :: environment", "webworker");
|
|
17741
|
+
} else {
|
|
17742
|
+
this.log("MqttClient :: environment", is_browser_1.default ? "browser" : "node");
|
|
17743
|
+
}
|
|
17695
17744
|
this.log("MqttClient :: options.protocol", options.protocol);
|
|
17696
17745
|
this.log("MqttClient :: options.protocolVersion", options.protocolVersion);
|
|
17697
17746
|
this.log("MqttClient :: options.username", options.username);
|
|
@@ -18576,7 +18625,7 @@ var mqtt = (() => {
|
|
|
18576
18625
|
this.pingResp = true;
|
|
18577
18626
|
this.pingTimer = new PingTimer_1.default(this.options.keepalive, () => {
|
|
18578
18627
|
this._checkPing();
|
|
18579
|
-
});
|
|
18628
|
+
}, this.options.timerVariant);
|
|
18580
18629
|
}
|
|
18581
18630
|
}
|
|
18582
18631
|
_shiftPingInterval() {
|
|
@@ -18591,6 +18640,7 @@ var mqtt = (() => {
|
|
|
18591
18640
|
this.pingResp = false;
|
|
18592
18641
|
this._sendPacket({ cmd: "pingreq" });
|
|
18593
18642
|
} else {
|
|
18643
|
+
this.emit("error", new Error("Keepalive timeout"));
|
|
18594
18644
|
this.log("_checkPing :: calling _cleanUp with force true");
|
|
18595
18645
|
this._cleanUp(true);
|
|
18596
18646
|
}
|
|
@@ -18737,6 +18787,7 @@ var mqtt = (() => {
|
|
|
18737
18787
|
});
|
|
18738
18788
|
}
|
|
18739
18789
|
};
|
|
18790
|
+
MqttClient.VERSION = "5.5.0";
|
|
18740
18791
|
exports5.default = MqttClient;
|
|
18741
18792
|
}
|
|
18742
18793
|
});
|
|
@@ -20756,6 +20807,11 @@ var mqtt = (() => {
|
|
|
20756
20807
|
this.writeQueue = [];
|
|
20757
20808
|
this.proxy.end(callback);
|
|
20758
20809
|
}
|
|
20810
|
+
_destroy(err, callback) {
|
|
20811
|
+
this.writeQueue = [];
|
|
20812
|
+
this.proxy.destroy(err);
|
|
20813
|
+
callback(err);
|
|
20814
|
+
}
|
|
20759
20815
|
socketReady() {
|
|
20760
20816
|
this.emit("connect");
|
|
20761
20817
|
this.isSocketOpen = true;
|
|
@@ -21458,7 +21514,7 @@ var mqtt = (() => {
|
|
|
21458
21514
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
21459
21515
|
};
|
|
21460
21516
|
Object.defineProperty(exports5, "__esModule", { value: true });
|
|
21461
|
-
exports5.ReasonCodes = exports5.UniqueMessageIdProvider = exports5.DefaultMessageIdProvider = exports5.Store = exports5.MqttClient = exports5.connectAsync = exports5.connect = exports5.Client = void 0;
|
|
21517
|
+
exports5.ReasonCodes = exports5.PingTimer = exports5.UniqueMessageIdProvider = exports5.DefaultMessageIdProvider = exports5.Store = exports5.MqttClient = exports5.connectAsync = exports5.connect = exports5.Client = void 0;
|
|
21462
21518
|
var client_1 = __importDefault(require_client());
|
|
21463
21519
|
exports5.MqttClient = client_1.default;
|
|
21464
21520
|
var default_message_id_provider_1 = __importDefault(require_default_message_id_provider());
|
|
@@ -21472,6 +21528,8 @@ var mqtt = (() => {
|
|
|
21472
21528
|
Object.defineProperty(exports5, "connectAsync", { enumerable: true, get: function() {
|
|
21473
21529
|
return connect_1.connectAsync;
|
|
21474
21530
|
} });
|
|
21531
|
+
var PingTimer_1 = __importDefault(require_PingTimer());
|
|
21532
|
+
exports5.PingTimer = PingTimer_1.default;
|
|
21475
21533
|
exports5.Client = client_1.default;
|
|
21476
21534
|
__exportStar(require_client(), exports5);
|
|
21477
21535
|
__exportStar(require_shared(), exports5);
|