* Writes a packet payload. * * @param {Object} packet * @private
(packets)
| 257 | * @private |
| 258 | */ |
| 259 | send(packets) { |
| 260 | this.writable = false; |
| 261 | |
| 262 | if (this.shouldClose) { |
| 263 | debug("appending close packet to payload"); |
| 264 | packets.push({ type: "close" }); |
| 265 | this.shouldClose(); |
| 266 | this.shouldClose = null; |
| 267 | } |
| 268 | |
| 269 | const doWrite = (data: string) => { |
| 270 | const compress = packets.some((packet) => { |
| 271 | return packet.options && packet.options.compress; |
| 272 | }); |
| 273 | this.write(data, { compress }); |
| 274 | }; |
| 275 | |
| 276 | if (this.protocol === 3) { |
| 277 | (this.parser as typeof parser_v3).encodePayload( |
| 278 | packets, |
| 279 | this.supportsBinary, |
| 280 | doWrite, |
| 281 | ); |
| 282 | } else { |
| 283 | (this.parser as typeof parser_v4).encodePayload(packets, doWrite); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Writes data as response to poll request. |
no test coverage detected