UNPKG

1.9 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const ack_1 = require("./ack");
7const topic_alias_send_1 = __importDefault(require("../topic-alias-send"));
8const shared_1 = require("../shared");
9const handleConnack = (client, packet) => {
10 client.log('_handleConnack');
11 const { options } = client;
12 const version = options.protocolVersion;
13 const rc = version === 5 ? packet.reasonCode : packet.returnCode;
14 clearTimeout(client['connackTimer']);
15 delete client['topicAliasSend'];
16 if (packet.properties) {
17 if (packet.properties.topicAliasMaximum) {
18 if (packet.properties.topicAliasMaximum > 0xffff) {
19 client.emit('error', new Error('topicAliasMaximum from broker is out of range'));
20 return;
21 }
22 if (packet.properties.topicAliasMaximum > 0) {
23 client['topicAliasSend'] = new topic_alias_send_1.default(packet.properties.topicAliasMaximum);
24 }
25 }
26 if (packet.properties.serverKeepAlive && options.keepalive) {
27 options.keepalive = packet.properties.serverKeepAlive;
28 }
29 if (packet.properties.maximumPacketSize) {
30 if (!options.properties) {
31 options.properties = {};
32 }
33 options.properties.maximumPacketSize =
34 packet.properties.maximumPacketSize;
35 }
36 }
37 if (rc === 0) {
38 client.reconnecting = false;
39 client['_onConnect'](packet);
40 }
41 else if (rc > 0) {
42 const err = new shared_1.ErrorWithReasonCode(`Connection refused: ${ack_1.ReasonCodes[rc]}`, rc);
43 client.emit('error', err);
44 }
45};
46exports.default = handleConnack;
47//# sourceMappingURL=connack.js.map
\No newline at end of file