Skip to content

Commit b3c105a

Browse files
committed
fix premature channel events
1 parent e8d9f62 commit b3c105a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function use (extensions) {
6464

6565
this._nonce = randomBytes(24)
6666
this._remoteNonce = null
67+
this._ready = false
6768

6869
this._firstNonce = Buffer(24)
6970
this._nonce.copy(this._firstNonce)
@@ -293,6 +294,8 @@ function use (extensions) {
293294
this._open(ch)
294295
if (ch.buffer.length) this._parseSoon(ch)
295296

297+
ch._ready = true // to avoid premature events
298+
296299
return ch
297300
}
298301

@@ -418,7 +421,7 @@ function use (extensions) {
418421
Protocol.prototype._onmessage = function (remote, data, offset) {
419422
var channel = this._remote[remote]
420423

421-
if (!channel.key || channel.buffer.length) {
424+
if (!channel.key || channel.buffer.length || !channel._ready) {
422425
if (channel.buffer.length === 16) return this.destroy(new Error('Buffer overflow'))
423426
channel.buffer.push(data)
424427
return

0 commit comments

Comments
 (0)