diff --git a/lib/faye/websocket/protocol8_parser.js b/lib/faye/websocket/protocol8_parser.js index cd1dbdb..69c828b 100644 --- a/lib/faye/websocket/protocol8_parser.js +++ b/lib/faye/websocket/protocol8_parser.js @@ -11,6 +11,7 @@ var Protocol8Parser = function(webSocket, options) { }; var instance = { + BYTE: 255, FIN: 128, MASK: 128, RSV1: 64, @@ -169,6 +170,7 @@ var instance = { offset = header + (this._masking ? 4 : 0), masked = this._masking ? this.MASK : 0, frame = new Buffer(length + offset), + BYTE = this.BYTE, mask, i; frame[0] = this.FIN | opcode; @@ -178,22 +180,22 @@ var instance = { } else if (length <= 65535) { frame[1] = masked | 126; frame[2] = Math.floor(length / 256); - frame[3] = length & 255; + frame[3] = length & BYTE; } else { frame[1] = masked | 127; - frame[2] = Math.floor(length / Math.pow(2,56)) & 255; - frame[3] = Math.floor(length / Math.pow(2,48)) & 255; - frame[4] = Math.floor(length / Math.pow(2,40)) & 255; - frame[5] = Math.floor(length / Math.pow(2,32)) & 255; - frame[6] = Math.floor(length / Math.pow(2,24)) & 255; - frame[7] = Math.floor(length / Math.pow(2,16)) & 255; - frame[8] = Math.floor(length / Math.pow(2,8)) & 255; - frame[9] = length & 255; + frame[2] = Math.floor(length / Math.pow(2,56)) & BYTE; + frame[3] = Math.floor(length / Math.pow(2,48)) & BYTE; + frame[4] = Math.floor(length / Math.pow(2,40)) & BYTE; + frame[5] = Math.floor(length / Math.pow(2,32)) & BYTE; + frame[6] = Math.floor(length / Math.pow(2,24)) & BYTE; + frame[7] = Math.floor(length / Math.pow(2,16)) & BYTE; + frame[8] = Math.floor(length / Math.pow(2,8)) & BYTE; + frame[9] = length & BYTE; } if (code) { - frame[offset] = Math.floor(code / 256); - frame[offset+1] = code & 255; + frame[offset] = Math.floor(code / 256) & BYTE; + frame[offset+1] = code & BYTE; } buffer.copy(frame, offset + insert);