*Change WS aliases to be conditional

*Remove on/off aliases since streamx already provides it
This commit is contained in:
Derrick Hammer 2023-02-25 22:46:34 -05:00
parent b1ad8399d3
commit 84f2f96e12
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 7 deletions

View File

@ -32,6 +32,10 @@ export default class Socket extends Duplex {
public remotePublicKey: Uint8Array; public remotePublicKey: Uint8Array;
private _emulateWebsocket: boolean; private _emulateWebsocket: boolean;
declare addEventListener: typeof this.addListener;
declare removeEventListener: typeof this.removeListener;
declare send: typeof this.write;
constructor({ constructor({
allowHalfOpen = false, allowHalfOpen = false,
remoteAddress, remoteAddress,
@ -57,6 +61,9 @@ export default class Socket extends Duplex {
} }
if (this._emulateWebsocket) { if (this._emulateWebsocket) {
this.addEventListener = this.addListener;
this.removeEventListener = this.removeListener;
this.send = this.write;
this.addEventListener("data", (data: any) => this.addEventListener("data", (data: any) =>
// @ts-ignore // @ts-ignore
this.emit("message", new MessageEvent("data", { data })) this.emit("message", new MessageEvent("data", { data }))
@ -119,13 +126,6 @@ export default class Socket extends Duplex {
}; };
} }
addEventListener = this.addListener;
on = this.addListener;
removeEventListener = this.removeListener;
off = this.removeListener;
send = write;
static isIP(input: string): number { static isIP(input: string): number {
if (Socket.isIPv4(input)) { if (Socket.isIPv4(input)) {
return 4; return 4;