Last active
November 21, 2022 20:50
-
-
Save yakovenkodenis/51e62b3cbf5b2f62cabd5f37a32ccf69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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