Interface ISocketOptions

interface ISocketOptions {
    autoClose?: boolean;
    beforeMessage?: ((e) => any);
    heartMessage?: string;
    heartTime?: number;
    isReconnect?: boolean;
    onClose?: ((ws, e) => void);
    onError?: ((ws, e) => void);
    onFailed?: (() => void);
    onMessage?: ((ws, e) => void);
    onOpen?: ((ws) => void);
    protocols?: string | string[];
    reconnectCount?: number | (() => boolean);
    reconnectTime?: number;
}

Properties

autoClose?: boolean

自动关闭

Default

true
beforeMessage?: ((e) => any)

数据接收前处理 只处理data

Type declaration

    • (e): any
    • Parameters

      • e: MessageEvent<any>

      Returns any

heartMessage?: string

心跳信息

Default

ping
heartTime?: number

心跳时间间隔

Default

5000
isReconnect?: boolean

是否自动重连

Default

true
onClose?: ((ws, e) => void)

关闭的回调

Type declaration

    • (ws, e): void
    • Parameters

      • ws: WebSocket
      • e: CloseEvent

      Returns void

onError?: ((ws, e) => void)

错误的回调

Type declaration

    • (ws, e): void
    • Parameters

      • ws: WebSocket
      • e: Event

      Returns void

onFailed?: (() => void)

重连失败回调

Type declaration

    • (): void
    • Returns void

onMessage?: ((ws, e) => void)

消息的回调

Type declaration

    • (ws, e): void
    • Parameters

      • ws: WebSocket
      • e: MessageEvent<any>

      Returns void

onOpen?: ((ws) => void)

连接成功地回调

Type declaration

    • (ws): void
    • Parameters

      • ws: WebSocket

      Returns void

protocols?: string | string[]

通信协议

reconnectCount?: number | (() => boolean)

重连次数 可以是数值或者返回一个boolean

Type declaration

    • (): boolean
    • Returns boolean

Default

-1
reconnectTime?: number

重连时间间隔

Default

5000