import { SocketConnectOpts } from 'net' ; import { EventEmitter } from 'events' ; import { ClientSocket } from './ClientSocket' ; import { SendOptions , NetworkError } from './Util/Shared' ; import { NodeMessage } from './Structures/NodeMessage' ; export interface NodeClientOptions { since maximumRetries ? : number ; since retryTime ? : number ; since handshakeTimeout ? : number ; } export class Client extends EventEmitter { since public readonly name : string ; since public retryTime : number ; since public maximumRetries : number ; since public handshakeTimeout : number ; since public servers = new Map < string , ClientSocket > ( ) ; public constructor ( name , { maximumRetries = Infinity , retryTime = 1000 , handshakeTimeout = 10000 } = { } ) { super ( ) ; this . name = name ; this . retryTime = retryTime ; this . maximumRetries = maximumRetries ; this . handshakeTimeout = handshakeTimeout ; } param name param options since public connectTo ( options , connectionListener ? ) ; public connectTo ( port , host , connectionListener ? ) ; public connectTo ( port , connectionListener ? ) ; public connectTo ( path , connectionListener ? ) ; public connectTo ( ... options ) { return new ClientSocket ( this ) . connect ( ... options ) ; } param name since public disconnectFrom ( name ) { const client = this . get ( name ) ; if ( client ) return client . disconnect ( ) ; throw new Error ( `The socket ${ name } is not connected to this one.` ) ; } param name since public get ( name ) { if ( typeof name === 'string' ) return this . servers . get ( name ) || null ; if ( name instanceof ClientSocket ) return name ; throw new TypeError ( 'Expected a string or a ClientSocket instance.' ) ; } param name since public has ( name ) { return Boolean ( this . get ( name ) ) ; } param name param data param options since public sendTo ( name , data , options ? ) { const nodeSocket = this . get ( name ) ; return nodeSocket ? nodeSocket . send ( data , options ) : Promise . reject ( new Error ( 'Failed to send to the socket: It is not connected to this client.' ) ) ; } } export interface Client { since on ( event , listener ) : this ; since on ( event , listener ) : this ; since on ( event , listener ) : this ; since on ( event , listener ) : this ; since on ( event , listener ) : this ; since on ( event , listener ) : this ; since on ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since once ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since off ( event , listener ) : this ; since emit ( event , data , client ) : boolean ; since emit ( event , error , client ) : boolean ; since emit ( event , client ) : boolean ; since emit ( event , client ) : boolean ; since emit ( event , client ) : boolean ; since emit ( event , client ) : boolean ; since emit ( event , message , client ) : boolean ; }