Comparing version 0.1.8 to 0.1.9
@@ -12,2 +12,4 @@ /// <reference types="node" /> | ||
private mqttDebug; | ||
private packetDebug; | ||
private pingDebug; | ||
protected executeNextTick: ExecuteNextTick; | ||
@@ -14,0 +16,0 @@ protected executePeriodically: ExecutePeriodically; |
@@ -18,2 +18,4 @@ "use strict"; | ||
this.mqttDebug = debug('mqtt:client'); | ||
this.packetDebug = this.mqttDebug.extend('packet'); | ||
this.pingDebug = this.mqttDebug.extend('ping'); | ||
/** | ||
@@ -51,3 +53,3 @@ * An error has been encountered, the client will no longer work correctly | ||
}; | ||
this.parser = (_a = options.parser, (_a !== null && _a !== void 0 ? _a : new mqtt_parser_1.MqttParser(e => this.$error.next(e)))); | ||
this.parser = (_a = options.parser, (_a !== null && _a !== void 0 ? _a : new mqtt_parser_1.MqttParser(e => this.$error.next(e), this.mqttDebug.extend('parser')))); | ||
this.transport = (_b = options.transport, (_b !== null && _b !== void 0 ? _b : new transport_1.TlsTransport({ | ||
@@ -215,6 +217,5 @@ url: options.url, | ||
this.keepAliveTimer = this.executePeriodically(value * 1000, () => { | ||
const pingDebug = this.mqttDebug.extend('ping'); | ||
this.startFlow(flow_1.outgoingPingFlow()) | ||
.then(() => pingDebug(`PingPong @ ${Date.now()}`)) | ||
.catch(() => pingDebug('PingPong failed.')); | ||
.then(() => this.pingDebug(`PingPong @ ${Date.now()}`)) | ||
.catch(() => this.pingDebug('PingPong failed.')); | ||
}); | ||
@@ -279,3 +280,3 @@ } | ||
if (packet.packetType !== mqtt_constants_1.PacketTypes.TYPE_PINGREQ && packet.packetType !== mqtt_constants_1.PacketTypes.TYPE_PINGRESP) | ||
this.mqttDebug.extend('packet')(`${action} ${packet.constructor.name}` + | ||
this.packetDebug(`${action} ${packet.constructor.name}` + | ||
(packet.identifier ? ` id: ${packet.identifier}` : '') + | ||
@@ -282,0 +283,0 @@ // @ts-ignore - instanceof is too expensive |
@@ -78,6 +78,6 @@ "use strict"; | ||
this.remainingPacketLength += (encodedByte & 0x7f) * multiplier; | ||
if (multiplier > 128 * 128 * 128) { | ||
throw new Error(`Invalid length @${stream.position}/${stream.length}; currentLength: ${this.remainingPacketLength}`); | ||
} | ||
multiplier *= 0x80; | ||
if (multiplier > Math.pow(0x80, 4)) { | ||
throw new Error('Invalid length'); | ||
} | ||
} while ((encodedByte & 0x80) !== 0); | ||
@@ -84,0 +84,0 @@ } |
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
export declare class MqttParser { | ||
protected debug?: ((msg: string) => void) | undefined; | ||
protected stream: PacketStream; | ||
@@ -16,5 +17,5 @@ protected errorCallback: (e: Error) => void; | ||
private lock; | ||
constructor(errorCallback?: (e: Error) => void); | ||
constructor(errorCallback?: (e: Error) => void, debug?: ((msg: string) => void) | undefined); | ||
reset(): void; | ||
parse(data: Buffer): Promise<MqttPacket[]>; | ||
} |
@@ -9,3 +9,4 @@ "use strict"; | ||
class MqttParser { | ||
constructor(errorCallback) { | ||
constructor(errorCallback, debug) { | ||
this.debug = debug; | ||
this.mapping = [ | ||
@@ -66,2 +67,3 @@ [mqtt_constants_1.PacketTypes.TYPE_CONNACK, () => new packets_1.ConnectResponsePacket()], | ||
async parse(data) { | ||
var _a, _b, _c, _d; | ||
await this.lock.wait(); | ||
@@ -82,2 +84,5 @@ this.lock.lock(); | ||
catch (e) { | ||
(_b = (_a = this).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `No packet found for ${type}; | ||
@${this.stream.position}/${this.stream.length} | ||
parsed: ${results.length}`); | ||
continue; | ||
@@ -93,3 +98,5 @@ } | ||
}) | ||
.catch(errors_1.EndOfStreamError, () => { | ||
.catch(errors_1.EndOfStreamError, e => { | ||
var _a, _b; | ||
(_b = (_a = this).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `End of stream: ${e.stack}`); | ||
this.stream.position = startPos; | ||
@@ -99,3 +106,11 @@ exitParser = true; | ||
.catch((e) => { | ||
var _a, _b; | ||
(_b = (_a = this).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `Error in parser (type: ${type}): | ||
${e.stack}; | ||
exiting; | ||
resetting; | ||
stream: ${this.stream.data.toString('base64')}`); | ||
this.errorCallback(e); | ||
exitParser = true; | ||
this.stream = packet_stream_1.PacketStream.empty(); | ||
}); | ||
@@ -107,2 +122,7 @@ if (exitParser) | ||
catch (e) { | ||
(_d = (_c = this).debug) === null || _d === void 0 ? void 0 : _d.call(_c, `Error in parser: | ||
${e.stack}; | ||
resetting; | ||
stream: ${this.stream.data.toString('base64')}`); | ||
this.stream = packet_stream_1.PacketStream.empty(); | ||
this.errorCallback(e); | ||
@@ -109,0 +129,0 @@ } |
{ | ||
"name": "mqtts", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "MQTT client in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129654
2024