chore: format everything
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export * from './types'
|
||||
export * from './websocket'
|
||||
export * from './websocket'
|
||||
|
||||
@@ -8,12 +8,15 @@ export abstract class AbstractSocketClient extends EventEmitter {
|
||||
abstract get isClosing(): boolean
|
||||
abstract get isConnecting(): boolean
|
||||
|
||||
constructor(public url: URL, public config: SocketConfig) {
|
||||
constructor(
|
||||
public url: URL,
|
||||
public config: SocketConfig
|
||||
) {
|
||||
super()
|
||||
this.setMaxListeners(0)
|
||||
}
|
||||
|
||||
abstract connect(): Promise<void>
|
||||
abstract close(): Promise<void>
|
||||
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
||||
}
|
||||
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { DEFAULT_ORIGIN } from '../../Defaults'
|
||||
import { AbstractSocketClient } from './types'
|
||||
|
||||
export class WebSocketClient extends AbstractSocketClient {
|
||||
|
||||
protected socket: WebSocket | null = null
|
||||
|
||||
get isOpen(): boolean {
|
||||
@@ -20,7 +19,7 @@ export class WebSocketClient extends AbstractSocketClient {
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if(this.socket) {
|
||||
if (this.socket) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,20 +28,20 @@ export class WebSocketClient extends AbstractSocketClient {
|
||||
headers: this.config.options?.headers as {},
|
||||
handshakeTimeout: this.config.connectTimeoutMs,
|
||||
timeout: this.config.connectTimeoutMs,
|
||||
agent: this.config.agent,
|
||||
agent: this.config.agent
|
||||
})
|
||||
|
||||
this.socket.setMaxListeners(0)
|
||||
|
||||
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response']
|
||||
|
||||
for(const event of events) {
|
||||
for (const event of events) {
|
||||
this.socket?.on(event, (...args: any[]) => this.emit(event, ...args))
|
||||
}
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
if(!this.socket) {
|
||||
if (!this.socket) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user