# Interface SocketOptions

interface SocketOptions {
authToken?: string;
binaryType?: string;
debug?: boolean;
decode?: (
payload: string | ArrayBuffer,
callback: (decoded: Message) => void,
) => void;
encode?: (
payload: any,
callback: (encoded: string | ArrayBuffer) => void,
) => void;
heartbeatIntervalMs?: number;
logger?: (kind: string, msg: string, data?: any) => void;
longpollerTimeout?: number;
longPollFallbackMs?: number;
params?: Record<string, any> | (() => Record<string, any>);
reconnectAfterMs?: (tries: number) => number;
rejoinAfterMs?: (tries: number) => number;
sessionStorage?: {
getItem(key: string): string;
removeItem(key: string): void;
setItem(key: string, value: string): void;
};
timeout?: number;
transport?: Transport;
vsn?: string;
}

- Defined in socket.ts:118

##### Index

### Properties

authToken?
binaryType?
debug?
decode?
encode?
heartbeatIntervalMs?
logger?
longpollerTimeout?
longPollFallbackMs?
params?
reconnectAfterMs?
rejoinAfterMs?
sessionStorage?
timeout?
transport?
vsn?

## Properties

### `Optional` authToken

authToken?: string

The optional authentication token to be exposed on the server under the `:auth_token` connect_info key.

- Defined in socket.ts:211

### `Optional` binaryType

binaryType?: string

The binary type to use for binary WebSocket frames.

Defaults to "arraybuffer"

- Defined in socket.ts:217

### `Optional` debug

debug?: boolean

When true, enables debug logging. Default false.

- Defined in socket.ts:134

### `Optional` decode

decode?: (
payload: string | ArrayBuffer,
callback: (decoded: Message) => void,
) => void

The function to decode incoming messages.

Defaults to JSON:

    (payload, callback) => callback(JSON.parse(payload))

- Defined in socket.ts:150

### `Optional` encode

encode?: (
payload: any,
callback: (encoded: string | ArrayBuffer) => void,
) => void

The function to encode outgoing messages.

Defaults to JSON encoder.

- Defined in socket.ts:140

### `Optional` heartbeatIntervalMs

heartbeatIntervalMs?: number

The millisec interval to send a heartbeat message.

Defaults to `30000`.

- Defined in socket.ts:162

### `Optional` logger

logger?: (kind: string, msg: string, data?: any) => void

The optional function for specialized logging, ie:

    function(kind, msg, data) {
      console.log(`${kind}: ${msg}`, data)
    }

- Defined in socket.ts:196

### `Optional` longpollerTimeout

longpollerTimeout?: number

The maximum timeout of a long poll AJAX request.

Defaults to 20s (double the server long poll timer).

- Defined in socket.ts:202

### `Optional` longPollFallbackMs

longPollFallbackMs?: number

The millisecond time to attempt the primary transport before falling back to the LongPoll transport. Disabled by default.

- Defined in socket.ts:130

### `Optional` params

params?: Record<string, any> | (() => Record<string, any>)

The optional params to pass when connecting.

- Defined in socket.ts:206

### `Optional` reconnectAfterMs

reconnectAfterMs?: (tries: number) => number

The optional function that returns the socket reconnect interval, in milliseconds.

Defaults to stepped backoff of:

    function(tries){
      return [10, 50, 100, 150, 200, 250, 500, 1000, 2000][tries - 1] || 5000
    }

- Defined in socket.ts:175

### `Optional` rejoinAfterMs

rejoinAfterMs?: (tries: number) => number

The optional function that returns the millisec rejoin interval for individual channels.

    function(tries){
      return [1000, 2000, 5000][tries - 1] || 10000
    }

- Defined in socket.ts:186

### `Optional` sessionStorage

sessionStorage?: {
getItem(key: string): string;
removeItem(key: string): void;
setItem(key: string, value: string): void;
}

An optional Storage compatible object Phoenix uses sessionStorage for longpoll fallback history. Overriding the store is useful when Phoenix won't have access to `sessionStorage`. For example, This could happen if a site loads a cross-domain channel in an iframe. Example usage:

    class InMemoryStorage {
      constructor() { this.storage = {} }
      getItem(keyName) { return this.storage[keyName] || null }
      removeItem(keyName) { delete this.storage[keyName] }
      setItem(keyName, keyValue) { this.storage[keyName] = keyValue }
    }

- Defined in socket.ts:237

### `Optional` timeout

timeout?: number

The default timeout in milliseconds to trigger push timeouts.

Defaults to `10000`

- Defined in socket.ts:156

### `Optional` transport

transport?: Transport

The Websocket Transport, for example WebSocket or Phoenix.LongPoll.

Defaults to WebSocket with automatic LongPoll fallback if WebSocket is not defined. To fallback to LongPoll when WebSocket attempts fail, use `longPollFallbackMs: 2500`.

- Defined in socket.ts:125

### `Optional` vsn

vsn?: string

The serializer's protocol version to send on connect.

Defaults to "2.0.0".

- Defined in socket.ts:223