Skip to content

Commit

Permalink
fixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
castorw committed Mar 22, 2018
1 parent 580ae87 commit f221205
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/client/socksclient.ts
Expand Up @@ -26,6 +26,7 @@ import {
} from '../common/helpers';
import { ReceiveBuffer } from '../common/receivebuffer';
import { SocksClientError, shuffleArray } from '../common/util';
import { Duplex } from 'stream';

// Exposes SocksClient event types
declare interface SocksClient {
Expand All @@ -52,7 +53,7 @@ declare interface SocksClient {

class SocksClient extends EventEmitter implements SocksClient {
private _options: SocksClientOptions;
private _socket: net.Socket;
private _socket: Duplex;
private _state: SocksClientState;
// This is an internal ReceiveBuffer that holds all received data while we wait for enough data to process.
private _receiveBuffer: ReceiveBuffer;
Expand Down Expand Up @@ -270,7 +271,7 @@ class SocksClient extends EventEmitter implements SocksClient {
* Starts the connection establishment to the proxy and destination.
* @param existing_socket Connected socket to use instead of creating a new one (internal use).
*/
public connect(existing_socket?: net.Socket) {
public connect(existing_socket?: Duplex) {
this._onDataReceived = (data: Buffer) => this.onDataReceived(data);
this._onClose = () => this.onClose();
this._onError = (err: Error) => this.onError(err);
Expand Down Expand Up @@ -301,7 +302,7 @@ class SocksClient extends EventEmitter implements SocksClient {
if (existing_socket) {
this._socket.emit('connect');
} else {
this._socket.connect(
(this._socket as net.Socket).connect(
this._options.proxy.port,
this._options.proxy.ipaddress
);
Expand Down Expand Up @@ -441,7 +442,7 @@ class SocksClient extends EventEmitter implements SocksClient {
this.state = SocksClientState.Error;

// Destroy Socket
if (!this._socket.destroyed) {
if (this._socket instanceof net.Socket && !this._socket.destroyed) {
this._socket.destroy();
}

Expand Down
4 changes: 2 additions & 2 deletions typings/client/socksclient.d.ts
@@ -1,8 +1,8 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import * as net from 'net';
import { SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksClientBoundEvent, SocksClientEstablishedEvent, SocksUDPFrameDetails } from '../common/constants';
import { SocksClientError } from '../common/util';
import { Duplex } from 'stream';
interface SocksClient {
on(event: 'error', listener: (err: SocksClientError) => void): this;
on(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
Expand Down Expand Up @@ -67,7 +67,7 @@ declare class SocksClient extends EventEmitter implements SocksClient {
* Starts the connection establishment to the proxy and destination.
* @param existing_socket Connected socket to use instead of creating a new one (internal use).
*/
connect(existing_socket?: net.Socket): void;
connect(existing_socket?: Duplex): void;
/**
* Handles internal Socks timeout callback.
* Note: If the Socks client is not BoundWaitingForConnection or Established, the connection will be closed.
Expand Down

0 comments on commit f221205

Please sign in to comment.