Compare commits
No commits in common. "29c6a909b807b17fda1d6adf42ead8c448298d4d" and "c90e0227952ce8d3a4a7dfe065a73a259a5de03b" have entirely different histories.
29c6a909b8
...
c90e022795
|
@ -1,6 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
import { Duplex, DuplexEvents, Callback } from "streamx";
|
||||
import { write } from "fs";
|
||||
type AddressFamily = "IPv6" | "IPv4";
|
||||
interface SocketOptions {
|
||||
allowHalfOpen?: boolean;
|
||||
|
@ -8,7 +6,6 @@ interface SocketOptions {
|
|||
remotePort?: number;
|
||||
remotePublicKey?: Uint8Array;
|
||||
write?: (this: Duplex<any, any, any, any, true, true, DuplexEvents<any, any>>, data: any, cb: Callback) => void;
|
||||
emulateWebsocket?: boolean;
|
||||
}
|
||||
export default class Socket extends Duplex {
|
||||
private _allowHalfOpen;
|
||||
|
@ -19,8 +16,7 @@ export default class Socket extends Duplex {
|
|||
readable: true;
|
||||
writable: true;
|
||||
remotePublicKey: Uint8Array;
|
||||
private _emulateWebsocket;
|
||||
constructor({ allowHalfOpen, remoteAddress, remotePort, remotePublicKey, write, emulateWebsocket, }?: SocketOptions);
|
||||
constructor({ allowHalfOpen, remoteAddress, remotePort, remotePublicKey, write, }?: SocketOptions);
|
||||
private _connecting;
|
||||
get connecting(): boolean;
|
||||
get readyState(): string;
|
||||
|
@ -38,7 +34,6 @@ export default class Socket extends Duplex {
|
|||
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 isIPv4(input: string): boolean;
|
||||
static isIPv6(input: string): boolean;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const streamx_1 = require("streamx");
|
||||
const fs_1 = require("fs");
|
||||
const IPV4 = "IPv4";
|
||||
const IPV6 = "IPv6";
|
||||
class Socket extends streamx_1.Duplex {
|
||||
|
@ -11,14 +10,12 @@ class Socket extends streamx_1.Duplex {
|
|||
remoteFamily;
|
||||
bufferSize;
|
||||
remotePublicKey;
|
||||
_emulateWebsocket;
|
||||
constructor({ allowHalfOpen = false, remoteAddress, remotePort, remotePublicKey, write, emulateWebsocket = false, } = {}) {
|
||||
constructor({ allowHalfOpen = false, remoteAddress, remotePort, remotePublicKey, write, } = {}) {
|
||||
super({ write });
|
||||
this._allowHalfOpen = allowHalfOpen;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.remotePort = remotePort;
|
||||
this.remotePublicKey = remotePublicKey;
|
||||
this._emulateWebsocket = emulateWebsocket;
|
||||
if (remoteAddress) {
|
||||
const type = Socket.isIP(remoteAddress);
|
||||
if (!type) {
|
||||
|
@ -26,10 +23,6 @@ class Socket extends streamx_1.Duplex {
|
|||
}
|
||||
this.remoteFamily = type === 6 ? IPV6 : IPV4;
|
||||
}
|
||||
if (this._emulateWebsocket) {
|
||||
// @ts-ignore
|
||||
this.addEventListener("data", (data) => this.emit("message", data));
|
||||
}
|
||||
}
|
||||
_connecting;
|
||||
get connecting() {
|
||||
|
@ -75,7 +68,6 @@ class Socket extends streamx_1.Duplex {
|
|||
on = this.addListener;
|
||||
removeEventListener = this.removeListener;
|
||||
off = this.removeListener;
|
||||
send = fs_1.write;
|
||||
static isIP(input) {
|
||||
if (Socket.isIPv4(input)) {
|
||||
return 4;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Duplex, DuplexEvents, Callback } from "streamx";
|
||||
import { write } from "fs";
|
||||
|
||||
const IPV4 = "IPv4";
|
||||
const IPV6 = "IPv6";
|
||||
|
@ -16,7 +15,6 @@ interface SocketOptions {
|
|||
data: any,
|
||||
cb: Callback
|
||||
) => void;
|
||||
emulateWebsocket?: boolean;
|
||||
}
|
||||
|
||||
export default class Socket extends Duplex {
|
||||
|
@ -30,7 +28,6 @@ export default class Socket extends Duplex {
|
|||
declare readable: true;
|
||||
declare writable: true;
|
||||
public remotePublicKey: Uint8Array;
|
||||
private _emulateWebsocket: boolean;
|
||||
|
||||
constructor({
|
||||
allowHalfOpen = false,
|
||||
|
@ -38,14 +35,12 @@ export default class Socket extends Duplex {
|
|||
remotePort,
|
||||
remotePublicKey,
|
||||
write,
|
||||
emulateWebsocket = false,
|
||||
}: SocketOptions = {}) {
|
||||
super({ write });
|
||||
this._allowHalfOpen = allowHalfOpen;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.remotePort = remotePort;
|
||||
this.remotePublicKey = remotePublicKey;
|
||||
this._emulateWebsocket = emulateWebsocket;
|
||||
|
||||
if (remoteAddress) {
|
||||
const type = Socket.isIP(remoteAddress);
|
||||
|
@ -55,11 +50,6 @@ export default class Socket extends Duplex {
|
|||
|
||||
this.remoteFamily = type === 6 ? IPV6 : IPV4;
|
||||
}
|
||||
|
||||
if (this._emulateWebsocket) {
|
||||
// @ts-ignore
|
||||
this.addEventListener("data", (data: any) => this.emit("message", data));
|
||||
}
|
||||
}
|
||||
|
||||
private _connecting: boolean;
|
||||
|
@ -112,8 +102,6 @@ export default class Socket extends Duplex {
|
|||
removeEventListener = this.removeListener;
|
||||
off = this.removeListener;
|
||||
|
||||
send = write;
|
||||
|
||||
static isIP(input: string): number {
|
||||
if (Socket.isIPv4(input)) {
|
||||
return 4;
|
||||
|
|
Loading…
Reference in New Issue