Compare commits
No commits in common. "f457294772e5bb3af36c9b463fe7bcc48ad3b462" and "d37d37048c44b2212b91ddb5fc4734efaa1c781a" have entirely different histories.
f457294772
...
d37d37048c
35
index.js
35
index.js
|
@ -50,7 +50,7 @@ class Channel {
|
|||
for (const m of messages) this.addMessage(m);
|
||||
}
|
||||
|
||||
async open(handshake) {
|
||||
open(handshake) {
|
||||
const id =
|
||||
this._mux._free.length > 0
|
||||
? this._mux._free.pop()
|
||||
|
@ -81,7 +81,7 @@ class Channel {
|
|||
if (this._handshake) this._handshake.encode(state, handshake);
|
||||
|
||||
this._mux._write0(state.buffer);
|
||||
await this._mux.syncState?.();
|
||||
this._mux.syncState?.();
|
||||
}
|
||||
|
||||
_dec() {
|
||||
|
@ -93,10 +93,10 @@ class Channel {
|
|||
this._mux._safeDestroy(err);
|
||||
}
|
||||
|
||||
async _fullyOpenSoon() {
|
||||
_fullyOpenSoon() {
|
||||
this._mux._remote[this._remoteId - 1].session = this;
|
||||
queueTick(this._fullyOpen.bind(this));
|
||||
await this._mux.syncState?.();
|
||||
this._mux.syncState?.();
|
||||
}
|
||||
|
||||
_fullyOpen() {
|
||||
|
@ -133,7 +133,7 @@ class Channel {
|
|||
}
|
||||
}
|
||||
|
||||
async _close(isRemote) {
|
||||
_close(isRemote) {
|
||||
if (this.closed === true) return;
|
||||
this.closed = true;
|
||||
|
||||
|
@ -154,7 +154,7 @@ class Channel {
|
|||
this._track(this.onclose(isRemote, this));
|
||||
|
||||
if (this._active === 0) this._destroy();
|
||||
await this._mux.syncState?.();
|
||||
this._mux.syncState?.();
|
||||
}
|
||||
|
||||
_destroy() {
|
||||
|
@ -177,7 +177,7 @@ class Channel {
|
|||
this._mux.uncork();
|
||||
}
|
||||
|
||||
async close() {
|
||||
close() {
|
||||
if (this.closed === true) return;
|
||||
|
||||
const state = { buffer: null, start: 2, end: 2 };
|
||||
|
@ -190,7 +190,7 @@ class Channel {
|
|||
state.buffer[1] = 3;
|
||||
c.uint.encode(state, this._localId);
|
||||
|
||||
await this._mux._close(false);
|
||||
this._mux._close(false);
|
||||
this._mux._write0(state.buffer);
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ class Channel {
|
|||
}
|
||||
|
||||
module.exports = class Protomux {
|
||||
constructor(stream, { alloc, slave = false } = {}) {
|
||||
constructor(stream, { alloc } = {}) {
|
||||
if (stream.userData === null) stream.userData = this;
|
||||
|
||||
this.isProtomux = true;
|
||||
|
@ -287,7 +287,6 @@ module.exports = class Protomux {
|
|||
|
||||
this._infos = new Map();
|
||||
this._notify = new Map();
|
||||
this._slave = false;
|
||||
|
||||
this.stream.on("data", this._ondata.bind(this));
|
||||
this.stream.on("end", this._onend.bind(this));
|
||||
|
@ -494,11 +493,11 @@ module.exports = class Protomux {
|
|||
this.stream.end();
|
||||
}
|
||||
|
||||
async _decode(remoteId, state) {
|
||||
_decode(remoteId, state) {
|
||||
const type = c.uint.decode(state);
|
||||
|
||||
if (remoteId === 0) {
|
||||
await this._oncontrolsession(type, state);
|
||||
this._oncontrolsession(type, state);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -513,11 +512,11 @@ module.exports = class Protomux {
|
|||
return;
|
||||
}
|
||||
|
||||
await this.syncState?.();
|
||||
this.syncState?.();
|
||||
r.session._recv(type, state);
|
||||
}
|
||||
|
||||
async _oncontrolsession(type, state) {
|
||||
_oncontrolsession(type, state) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
this._onbatch(state);
|
||||
|
@ -536,7 +535,7 @@ module.exports = class Protomux {
|
|||
break;
|
||||
}
|
||||
|
||||
await this.syncState?.();
|
||||
this.syncState?.();
|
||||
}
|
||||
|
||||
_bufferMessage(r, type, { buffer, start, end }) {
|
||||
|
@ -575,7 +574,7 @@ module.exports = class Protomux {
|
|||
}
|
||||
}
|
||||
|
||||
async _onopensession(state) {
|
||||
_onopensession(state) {
|
||||
const remoteId = c.uint.decode(state);
|
||||
const protocol = c.string.decode(state);
|
||||
const id = c.buffer.decode(state);
|
||||
|
@ -590,10 +589,6 @@ module.exports = class Protomux {
|
|||
const rid = remoteId - 1;
|
||||
const info = this._get(protocol, id);
|
||||
|
||||
if (this._slave) {
|
||||
await this._mux.syncState?.();
|
||||
}
|
||||
|
||||
// allow the remote to grow the ids by one
|
||||
if (this._remote.length === rid) {
|
||||
this._remote.push(null);
|
||||
|
|
Reference in New Issue