mirror of
https://github.com/JasonYANG170/IOTConnect-Web.git
synced 2024-11-27 22:26:32 +00:00
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const publish_1 = __importDefault(require("./publish"));
|
|
const auth_1 = __importDefault(require("./auth"));
|
|
const connack_1 = __importDefault(require("./connack"));
|
|
const ack_1 = __importDefault(require("./ack"));
|
|
const pubrel_1 = __importDefault(require("./pubrel"));
|
|
const handle = (client, packet, done) => {
|
|
const { options } = client;
|
|
if (options.protocolVersion === 5 &&
|
|
options.properties &&
|
|
options.properties.maximumPacketSize &&
|
|
options.properties.maximumPacketSize < packet.length) {
|
|
client.emit('error', new Error(`exceeding packets size ${packet.cmd}`));
|
|
client.end({
|
|
reasonCode: 149,
|
|
properties: { reasonString: 'Maximum packet size was exceeded' },
|
|
});
|
|
return client;
|
|
}
|
|
client.log('_handlePacket :: emitting packetreceive');
|
|
client.emit('packetreceive', packet);
|
|
switch (packet.cmd) {
|
|
case 'publish':
|
|
(0, publish_1.default)(client, packet, done);
|
|
break;
|
|
case 'puback':
|
|
case 'pubrec':
|
|
case 'pubcomp':
|
|
case 'suback':
|
|
case 'unsuback':
|
|
(0, ack_1.default)(client, packet);
|
|
done();
|
|
break;
|
|
case 'pubrel':
|
|
(0, pubrel_1.default)(client, packet, done);
|
|
break;
|
|
case 'connack':
|
|
(0, connack_1.default)(client, packet);
|
|
done();
|
|
break;
|
|
case 'auth':
|
|
(0, auth_1.default)(client, packet);
|
|
done();
|
|
break;
|
|
case 'pingresp':
|
|
client.pingResp = true;
|
|
done();
|
|
break;
|
|
case 'disconnect':
|
|
client.emit('disconnect', packet);
|
|
done();
|
|
break;
|
|
default:
|
|
client.log('_handlePacket :: unknown command');
|
|
done();
|
|
break;
|
|
}
|
|
};
|
|
exports.default = handle;
|
|
//# sourceMappingURL=index.js.map
|