1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const publish_1 = __importDefault(require("./publish"));
|
7 | const auth_1 = __importDefault(require("./auth"));
|
8 | const connack_1 = __importDefault(require("./connack"));
|
9 | const ack_1 = __importDefault(require("./ack"));
|
10 | const pubrel_1 = __importDefault(require("./pubrel"));
|
11 | const handle = (client, packet, done) => {
|
12 | const { options } = client;
|
13 | if (options.protocolVersion === 5 &&
|
14 | options.properties &&
|
15 | options.properties.maximumPacketSize &&
|
16 | options.properties.maximumPacketSize < packet.length) {
|
17 | client.emit('error', new Error(`exceeding packets size ${packet.cmd}`));
|
18 | client.end({
|
19 | reasonCode: 149,
|
20 | properties: { reasonString: 'Maximum packet size was exceeded' },
|
21 | });
|
22 | return client;
|
23 | }
|
24 | client.log('_handlePacket :: emitting packetreceive');
|
25 | client.emit('packetreceive', packet);
|
26 | switch (packet.cmd) {
|
27 | case 'publish':
|
28 | (0, publish_1.default)(client, packet, done);
|
29 | break;
|
30 | case 'puback':
|
31 | case 'pubrec':
|
32 | case 'pubcomp':
|
33 | case 'suback':
|
34 | case 'unsuback':
|
35 | client.reschedulePing();
|
36 | (0, ack_1.default)(client, packet);
|
37 | done();
|
38 | break;
|
39 | case 'pubrel':
|
40 | client.reschedulePing();
|
41 | (0, pubrel_1.default)(client, packet, done);
|
42 | break;
|
43 | case 'connack':
|
44 | (0, connack_1.default)(client, packet);
|
45 | done();
|
46 | break;
|
47 | case 'auth':
|
48 | client.reschedulePing();
|
49 | (0, auth_1.default)(client, packet);
|
50 | done();
|
51 | break;
|
52 | case 'pingresp':
|
53 | client.log('_handlePacket :: received pingresp');
|
54 | client.reschedulePing();
|
55 | done();
|
56 | break;
|
57 | case 'disconnect':
|
58 | client.emit('disconnect', packet);
|
59 | done();
|
60 | break;
|
61 | default:
|
62 | client.log('_handlePacket :: unknown command');
|
63 | done();
|
64 | break;
|
65 | }
|
66 | };
|
67 | exports.default = handle;
|
68 |
|
\ | No newline at end of file |