Compare commits
No commits in common. "f89e2716f52cdb6e5cba2871d23b581671efa43e" and "b1ad8399d335eab0f032035837dfe00263d458e0" have entirely different histories.
f89e2716f5
...
b1ad8399d3
|
@ -1,4 +1,6 @@
|
||||||
|
/// <reference types="node" />
|
||||||
import { Duplex, DuplexEvents, Callback } from "streamx";
|
import { Duplex, DuplexEvents, Callback } from "streamx";
|
||||||
|
import { write } from "fs";
|
||||||
type AddressFamily = "IPv6" | "IPv4";
|
type AddressFamily = "IPv6" | "IPv4";
|
||||||
interface SocketOptions {
|
interface SocketOptions {
|
||||||
allowHalfOpen?: boolean;
|
allowHalfOpen?: boolean;
|
||||||
|
@ -18,9 +20,6 @@ export default class Socket extends Duplex {
|
||||||
writable: true;
|
writable: true;
|
||||||
remotePublicKey: Uint8Array;
|
remotePublicKey: Uint8Array;
|
||||||
private _emulateWebsocket;
|
private _emulateWebsocket;
|
||||||
addEventListener: typeof this.addListener;
|
|
||||||
removeEventListener: typeof this.removeListener;
|
|
||||||
send: typeof this.write;
|
|
||||||
constructor({ allowHalfOpen, remoteAddress, remotePort, remotePublicKey, write, emulateWebsocket, }?: SocketOptions);
|
constructor({ allowHalfOpen, remoteAddress, remotePort, remotePublicKey, write, emulateWebsocket, }?: SocketOptions);
|
||||||
private _connecting;
|
private _connecting;
|
||||||
get connecting(): boolean;
|
get connecting(): boolean;
|
||||||
|
@ -35,6 +34,11 @@ export default class Socket extends Duplex {
|
||||||
port: any;
|
port: any;
|
||||||
family: AddressFamily;
|
family: AddressFamily;
|
||||||
};
|
};
|
||||||
|
addEventListener: <TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping">(event: TEvent, listener: TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping" ? DuplexEvents<any, any>[TEvent] : (...args: any[]) => void) => this;
|
||||||
|
on: <TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping">(event: TEvent, listener: TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping" ? DuplexEvents<any, any>[TEvent] : (...args: any[]) => void) => this;
|
||||||
|
removeEventListener: <TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping">(event: TEvent, listener: TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping" ? DuplexEvents<any, any>[TEvent] : (...args: any[]) => void) => this;
|
||||||
|
off: <TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping">(event: TEvent, listener: TEvent extends "data" | "end" | "finish" | "pipe" | "readable" | "drain" | keyof import("streamx").StreamEvents | "piping" ? DuplexEvents<any, any>[TEvent] : (...args: any[]) => void) => this;
|
||||||
|
send: typeof write;
|
||||||
static isIP(input: string): number;
|
static isIP(input: string): number;
|
||||||
static isIPv4(input: string): boolean;
|
static isIPv4(input: string): boolean;
|
||||||
static isIPv6(input: string): boolean;
|
static isIPv6(input: string): boolean;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const streamx_1 = require("streamx");
|
const streamx_1 = require("streamx");
|
||||||
|
const fs_1 = require("fs");
|
||||||
const IPV4 = "IPv4";
|
const IPV4 = "IPv4";
|
||||||
const IPV6 = "IPv6";
|
const IPV6 = "IPv6";
|
||||||
class Socket extends streamx_1.Duplex {
|
class Socket extends streamx_1.Duplex {
|
||||||
|
@ -26,9 +27,6 @@ class Socket extends streamx_1.Duplex {
|
||||||
this.remoteFamily = type === 6 ? IPV6 : IPV4;
|
this.remoteFamily = type === 6 ? IPV6 : IPV4;
|
||||||
}
|
}
|
||||||
if (this._emulateWebsocket) {
|
if (this._emulateWebsocket) {
|
||||||
this.addEventListener = this.addListener;
|
|
||||||
this.removeEventListener = this.removeListener;
|
|
||||||
this.send = this.write;
|
|
||||||
this.addEventListener("data", (data) =>
|
this.addEventListener("data", (data) =>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.emit("message", new MessageEvent("data", { data })));
|
this.emit("message", new MessageEvent("data", { data })));
|
||||||
|
@ -85,6 +83,11 @@ class Socket extends streamx_1.Duplex {
|
||||||
family: this.remoteFamily,
|
family: this.remoteFamily,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
addEventListener = this.addListener;
|
||||||
|
on = this.addListener;
|
||||||
|
removeEventListener = this.removeListener;
|
||||||
|
off = this.removeListener;
|
||||||
|
send = fs_1.write;
|
||||||
static isIP(input) {
|
static isIP(input) {
|
||||||
if (Socket.isIPv4(input)) {
|
if (Socket.isIPv4(input)) {
|
||||||
return 4;
|
return 4;
|
||||||
|
|
|
@ -32,10 +32,6 @@ 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,
|
||||||
|
@ -61,9 +57,6 @@ 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 }))
|
||||||
|
@ -126,6 +119,13 @@ 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;
|
||||||
|
|
Loading…
Reference in New Issue