Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Receiver extends stream.Writable {
* @param {Function} cb Callback
*/
_write(chunk, encoding, cb) {
if (this._opcode === 0x08) return cb();
if (this._opcode === 0x08 && this._state == GET_INFO) return cb();

this._bufferedBytes += chunk.length;
this._buffers.push(chunk);
Expand Down Expand Up @@ -454,6 +454,7 @@ class Receiver extends stream.Writable {
this.end();
}

this._state = GET_INFO;
return;
}

Expand Down
13 changes: 13 additions & 0 deletions test/receiver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ describe('Receiver', function() {
receiver.write(Buffer.from('8800', 'hex'));
});

it('parses a close message spanning multiple writes', function(done) {
const receiver = new Receiver();

receiver.on('conclude', (code, data) => {
assert.strictEqual(code, 1000);
assert.strictEqual(data, 'DONE');
done();
});

receiver.write(Buffer.from('8806', 'hex'));
receiver.write(Buffer.from('03e8444F4E45', 'hex'));
});

it('parses a masked text message', function(done) {
const receiver = new Receiver();

Expand Down