Skip to content

Instantly share code, notes, and snippets.

@yakovenkodenis
Last active November 21, 2022 20:50
Show Gist options
  • Save yakovenkodenis/51e62b3cbf5b2f62cabd5f37a32ccf69 to your computer and use it in GitHub Desktop.
Save yakovenkodenis/51e62b3cbf5b2f62cabd5f37a32ccf69 to your computer and use it in GitHub Desktop.
parseFrame(buffer) {
// ... first and second byte processing ...
const isMasked = Boolean((secondByte >>> 7) & 0b00000001); // get first bit of a second byte
if (isMasked) {
const maskingKey = buffer.readUInt32BE(offset); // read 4-byte (32-bit) masking key
offset += 4;
const payload = buffer.subarray(offset);
const result = this._unmask(payload, maskingKey);
return result.toString('utf-8');
}
return buffer.subarray(offset).toString('utf-8');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment