Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 6b42c2400f
*Update dist 2023-02-25 22:16:59 -05:00
Derrick Hammer bdacd01849
*add emulateWebsocket to peer 2023-02-25 22:16:40 -05:00
3 changed files with 12 additions and 2 deletions

4
dist/peer.d.ts vendored
View File

@ -14,6 +14,7 @@ export interface DataSocketOptions {
onreceive?: OnReceive;
onsend?: OnSend;
onclose?: OnClose;
emulateWebsocket?: boolean;
}
export interface PeerOptions {
peer: any;
@ -31,6 +32,7 @@ export default class Peer {
private _onreceive;
private _onsend;
private _onclose;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, }: PeerOptionsWithProxy & DataSocketOptions);
private _emulateWebsocket;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket, }: PeerOptionsWithProxy & DataSocketOptions);
init(): Promise<void>;
}

5
dist/peer.js vendored
View File

@ -14,7 +14,8 @@ class Peer {
_onreceive;
_onsend;
_onclose;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, }) {
_emulateWebsocket;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, emulateWebsocket = false, }) {
this._proxy = proxy;
this._peer = peer;
this._muxer = muxer;
@ -22,6 +23,7 @@ class Peer {
this._onreceive = onreceive;
this._onsend = onsend;
this._onclose = onclose;
this._emulateWebsocket = emulateWebsocket;
}
async init() {
const write = async (data, cb) => {
@ -44,6 +46,7 @@ class Peer {
remotePort: self._peer.rawStream.remotePort,
remotePublicKey: self._peer.remotePublicKey,
write,
emulateWebsocket: self._emulateWebsocket,
});
self._socket.on("end", () => channel.close());
let ret = await self._onopen?.(self._socket, m);

View File

@ -19,6 +19,7 @@ export interface DataSocketOptions {
onreceive?: OnReceive;
onsend?: OnSend;
onclose?: OnClose;
emulateWebsocket?: boolean;
}
export interface PeerOptions {
@ -39,6 +40,7 @@ export default class Peer {
private _onreceive: OnReceive;
private _onsend: OnSend;
private _onclose: OnClose;
private _emulateWebsocket: boolean;
constructor({
proxy,
@ -48,6 +50,7 @@ export default class Peer {
onreceive,
onsend,
onclose,
emulateWebsocket = false,
}: PeerOptionsWithProxy & DataSocketOptions) {
this._proxy = proxy;
this._peer = peer;
@ -56,6 +59,7 @@ export default class Peer {
this._onreceive = onreceive;
this._onsend = onsend;
this._onclose = onclose;
this._emulateWebsocket = emulateWebsocket;
}
async init() {
@ -80,6 +84,7 @@ export default class Peer {
remotePort: self._peer.rawStream.remotePort,
remotePublicKey: self._peer.remotePublicKey,
write,
emulateWebsocket: self._emulateWebsocket,
});
self._socket.on("end", () => channel.close());
let ret = await self._onopen?.(self._socket, m);