phoenix
    Preparing search index...

    Class Socket

    The Socket class.

    For IE8 support use an ES5-shim (https://github.com/es-shims/es5-shim)

    Index

    Constructors

    • Initializes the socket.

      Parameters

      • endPoint: string

        The string WebSocket endpoint, ie, "ws://example.com/socket", "wss://example.com" "/socket" (inherited host & protocol)

      • opts: SocketOptions = {}

        Optional configuration

      Returns Socket

    Methods

    • Initiates a new channel for the given topic

      Parameters

      • topic: string
      • chanParams: Record<string, any> = {}

        Parameters for the channel

      Returns Channel

    • Parameters

      • Optionalparams: Record<string, any>

        The params to send when connecting, for example {user_id: userToken}

        Passing params to connect is deprecated; pass them in the Socket constructor instead: new Socket("/socket", {params: {user_id: userToken}}).

      Returns void

    • Disconnects the socket

      See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes for valid status codes.

      Parameters

      • Optionalcallback: () => void

        Callback which is called after socket is disconnected.

      • Optionalcode: number

        A status code for disconnection.

      • Optionalreason: string

        A textual description of the reason to disconnect.

      Returns void

    • The fully qualified socket url

      Returns string

    • Returns the LongPoll transport reference

      Returns TransportClass

    • Returns true if a logger has been set on this socket.

      Returns boolean

    • Logs the message. Override this.logger for specialized logging. noops by default

      Parameters

      • kind: string
      • msg: string
      • Optionaldata: any

      Returns void

    • Return the next message ref, accounting for overflows

      Returns string

    • Removes onOpen, onClose, onError, and onMessage registrations.

      Parameters

      • refs: string[]

        list of refs returned by calls to onOpen, onClose, onError, and onMessage

      Returns void

    • Registers callbacks for connection close events

      Parameters

      • callback: (event: CloseEvent) => void

      Returns string

    • Registers callbacks for connection error events

      Parameters

      • callback: (error: any, transport?: Transport, establishedConnections?: number) => void

      Returns string

      socket.onError(function(error){ alert("An error occurred") })
      
    • Registers callbacks for connection message events

      Parameters

      • callback: (message: Message) => void

      Returns string

    • Registers callbacks for connection open events

      Parameters

      • callback: () => void

      Returns string

      socket.onOpen(function(){ console.info("the socket was opened") })
      
    • Pings the server and invokes the callback with the RTT in milliseconds

      Parameters

      • callback: (rtt: number) => void

        Returns true if the ping was pushed or false if unable to be pushed.

      Returns boolean

    • Returns the socket protocol

      Returns string

    • Disconnects and replaces the active transport

      Parameters

      • newTransport: Transport

        The new transport class to instantiate

      Returns void