* Dispatches a message. * * @param {(Buffer|String)} data The message to send * @param {Boolean} [compress=false] Specifies whether or not to compress * `data` * @param {Object} options Options object * @param {Boolean} [options.fin=false] Specifies whether or not to set the
(data, compress, options, cb)
| 501 | * @private |
| 502 | */ |
| 503 | dispatch(data, compress, options, cb) { |
| 504 | if (!compress) { |
| 505 | this.sendFrame(Sender.frame(data, options), cb); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName]; |
| 510 | |
| 511 | this._bufferedBytes += options[kByteLength]; |
| 512 | this._state = DEFLATING; |
| 513 | perMessageDeflate.compress(data, options.fin, (_, buf) => { |
| 514 | if (this._socket.destroyed) { |
| 515 | const err = new Error( |
| 516 | 'The socket was closed while data was being compressed' |
| 517 | ); |
| 518 | |
| 519 | callCallbacks(this, err, cb); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | this._bufferedBytes -= options[kByteLength]; |
| 524 | this._state = DEFAULT; |
| 525 | options.readOnly = false; |
| 526 | this.sendFrame(Sender.frame(buf, options), cb); |
| 527 | this.dequeue(); |
| 528 | }); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Executes queued send operations. |
no test coverage detected