*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 _onsend;
private _onclose; private _onclose;
private _emulateWebsocket; private _emulateWebsocket;
private _channel?;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket, }: PeerOptionsWithProxy & DataSocketOptions); constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket, }: PeerOptionsWithProxy & DataSocketOptions);
init(): Promise<void>; init(): Promise<void>;
} }

17
dist/peer.js vendored
View File

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