Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Sender {
* @param {Object} options Options object
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
* FIN bit
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
* `data`
* @param {Boolean|String} [options.mask=false] Specifies whether or not to mask
* `data`. A 'clear' value applies an empty mask to improve performance
* @param {Number} options.opcode The opcode
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
* modified
Expand All @@ -53,7 +53,8 @@ class Sender {
* @public
*/
static frame(data, options) {
const merge = options.mask && options.readOnly;
const clear = options.mask == 'clear';
const merge = options.mask && options.readOnly && !clear;
let offset = options.mask ? 6 : 2;
let payloadLength = data.length;

Expand Down Expand Up @@ -81,14 +82,16 @@ class Sender {

if (!options.mask) return [target, data];

randomFillSync(mask, 0, 4);
clear ? mask.fill(0) : randomFillSync(mask, 0, 4);

target[1] |= 0x80;
target[offset - 4] = mask[0];
target[offset - 3] = mask[1];
target[offset - 2] = mask[2];
target[offset - 1] = mask[3];

if (clear) return [target, data];

if (merge) {
applyMask(data, mask, target, offset, data.length);
return [target];
Expand Down