@seriousme/opifex
Version:
MQTT client & server for Deno & NodeJS
28 lines • 957 B
JavaScript
import { PacketType } from "../deps.js";
/**
* Handles PUBREL (QoS 2 publish release) packets
*
* @param ctx - The connection context
* @param packet - The PUBREL packet received from the client
* @returns Promise that resolves when handling is complete
* @description
* For QoS 2 message delivery:
* 1. Initiates onward delivery of the Application Message
* 2. Discards the stored message
* 3. Sends PUBCOMP packet with the Packet Identifier
*/
export async function handlePubrel(ctx, packet) {
const id = packet.id;
if (ctx.store?.pendingIncoming.has(id)) {
const storedPacket = ctx.store.pendingIncoming.get(id);
if (storedPacket) {
ctx.persistence.publish(storedPacket.topic, storedPacket);
ctx.store.pendingIncoming.delete(id);
await ctx.send({
type: PacketType.pubcomp,
id,
});
}
}
}
//# sourceMappingURL=handlePubrel.js.map