1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const shared_1 = require("../shared");
|
4 | const ack_1 = require("./ack");
|
5 | const handleAuth = (client, packet) => {
|
6 | const { options } = client;
|
7 | const version = options.protocolVersion;
|
8 | const rc = version === 5 ? packet.reasonCode : packet.returnCode;
|
9 | if (version !== 5) {
|
10 | const err = new shared_1.ErrorWithReasonCode(`Protocol error: Auth packets are only supported in MQTT 5. Your version:${version}`, rc);
|
11 | client.emit('error', err);
|
12 | return;
|
13 | }
|
14 | client.handleAuth(packet, (err, packet2) => {
|
15 | if (err) {
|
16 | client.emit('error', err);
|
17 | return;
|
18 | }
|
19 | if (rc === 24) {
|
20 | client.reconnecting = false;
|
21 | client['_sendPacket'](packet2);
|
22 | }
|
23 | else {
|
24 | const error = new shared_1.ErrorWithReasonCode(`Connection refused: ${ack_1.ReasonCodes[rc]}`, rc);
|
25 | client.emit('error', error);
|
26 | }
|
27 | });
|
28 | };
|
29 | exports.default = handleAuth;
|
30 |
|
\ | No newline at end of file |