yolkbot
    Preparing search index...

    Class Socket

    A WebSocket with auto-reconnect and proxy capabilities

    Index

    Constructors

    • Creates a new Socket instance

      Parameters

      • url: string

        The URL to connect the WebSocket to

      • params: Partial<SocketParams> = {}

        The parameters for the Socket, such as a proxy

      Returns Socket

    Methods

    • Closes the WebSocket connection

      Parameters

      • Optionalcode: number

        An optional code to send when closing the connection

      Returns void

    • Sends data through the WebSocket connection

      Parameters

      • data: string | Uint8Array<ArrayBuffer>

        The data to send, either as a string or binary data

      Returns void

    • Attempts to initialize the connection to the WebSocket

      Parameters

      • tries: number = 1

      Returns Promise<boolean>

      Whether the connection was successful

    Properties

    autoReconnect: boolean = false

    Whether the WebSocket will automatically reconnect

    binaryType: string = ''

    The binary type of the WebSocket

    connected: boolean = false

    Whether the Websocket is currently connected

    connectionTimeout: number = 5000

    The connection timeout for the WebSocket

    onBeforeConnect: (() => void) | null = null

    A handler that runs before you connect to the socket

    onclose: (event: CloseEvent) => void = ...

    A handler that runs when the socket closes

    onerror: (event: Event) => void = ...

    A handler that runs when the socket errors

    onmessage: (event: MessageEvent) => void = ...

    A handler that runs when the socket gets a message

    onopen: () => void = ...

    A handler that runs when the socket opens

    socket: IWebSocket | null = null

    The underlying actual WebsSocket

    url: string

    The URL of the WebSocket