*Update dist

This commit is contained in:
Derrick Hammer 2023-03-02 05:26:40 -05:00
parent 4220037402
commit c9cfb64c80
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 8 deletions

1
dist/peer.d.ts vendored
View File

@ -33,6 +33,7 @@ export default class Peer {
private _onsend;
private _onclose;
private _emulateWebsocket;
private _channel?;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket, }: PeerOptionsWithProxy & DataSocketOptions);
init(): Promise<void>;
}

17
dist/peer.js vendored
View File

@ -15,14 +15,15 @@ class Peer {
_onsend;
_onclose;
_emulateWebsocket;
_channel;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket = false, }) {
this._proxy = proxy;
this._peer = peer;
this._muxer = muxer;
this._onopen = onopen;
this._onreceive = onreceive;
this._onsend = onsend;
this._onclose = onclose;
this._onopen = onopen?.bind(this);
this._onreceive = onreceive?.bind(this);
this._onsend = onsend?.bind(this);
this._onclose = onclose?.bind(this);
this._emulateWebsocket = emulateWebsocket;
}
async init() {
@ -32,7 +33,7 @@ class Peer {
cb();
};
const self = this;
const channel = this._muxer.createChannel({
this._channel = this._muxer.createChannel({
protocol: this._proxy.protocol,
async onopen(m) {
if (!m) {
@ -48,7 +49,7 @@ class Peer {
write,
emulateWebsocket: self._emulateWebsocket,
});
self._socket.on("end", () => channel.close());
self._socket.on("end", () => this._channel.close());
let ret = await self._onopen?.(self._socket, m);
if (!ret || (ret && ret.connect === false)) {
// @ts-ignore
@ -61,7 +62,7 @@ class Peer {
await self._onclose?.(self._socket);
},
});
const pipe = channel.addMessage({
const pipe = this._channel.addMessage({
async onmessage(m) {
if (m instanceof Uint8Array) {
m = buffer_1.Buffer.from(m);
@ -70,7 +71,7 @@ class Peer {
await self._onreceive?.(m);
},
});
await channel.open();
await this._channel.open();
}
}
exports.default = Peer;