MCPcopy Index your code
hub / github.com/websockets/ws / dispatch

Method dispatch

lib/sender.js:503–529  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 2

sendMethod · 0.95
getBlobDataMethod · 0.95

Calls 5

sendFrameMethod · 0.95
dequeueMethod · 0.95
callCallbacksFunction · 0.85
frameMethod · 0.80
compressMethod · 0.80

Tested by

no test coverage detected