exports

exports

new exports(topic, params, socket)

Source:
Parameters:
Name Type Description
topic string
params Object | function
socket Socket

exports

Initializes the Presence

Constructor

new exports(channel, opts)

Source:
Parameters:
Name Type Description
channel Channel

The Channel

opts Object

The options, for example {events: {state: "state", diff: "diff"}}

exports

Initializes the Push

Constructor

new exports(channel, event, payload, timeout)

Source:
Parameters:
Name Type Description
channel Channel

The Channel

event string

The event, for example "combo_join"

payload Object

The payload, for example {user_id: 123}

timeout number

The push timeout in milliseconds

exports

Initializes the Socket *

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

Constructor

new exports(endPoint, optsopt)

Source:
Parameters:
Name Type Attributes Description
endPoint string

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

opts Object <optional>

Optional configuration

Properties
Name Type Attributes Description
transport function <optional>

The transport, for example WebSocket or LongPoll.

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

longPollFallbackMs number <optional>

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

debug boolean <optional>

When true, enables debug logging. Default false.

encode function <optional>

The function to encode outgoing messages.

Defaults to JSON encoder.

decode function <optional>

The function to decode incoming messages.

Defaults to JSON:

(payload, callback) => callback(JSON.parse(payload))
timeout number <optional>

The default timeout in milliseconds to trigger push timeouts.

Defaults DEFAULT_TIMEOUT

heartbeatIntervalMs number <optional>

The millisec interval to send a heartbeat message

reconnectAfterMs function <optional>

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
}
rejoinAfterMs function <optional>

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

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

The optional function for specialized logging, ie:

function(kind, msg, data) {
  console.log(`${kind}: ${msg}`, data)
}
longpollerTimeout number <optional>

The maximum timeout of a long poll AJAX request.

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

params Object | function <optional>

The optional params to pass when connecting

authToken string <optional>

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

binaryType string <optional>

The binary type to use for binary WebSocket frames.

Defaults to "arraybuffer"

vsn vsn <optional>

The serializer's protocol version to send on connect.

Defaults to DEFAULT_VSN.

sessionStorage Object <optional>

An optional Storage compatible object Combo uses sessionStorage for longpoll fallback history. Overriding the store is useful when Combo 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 }
}

exports

Creates a timer that accepts a timerCalc function to perform calculated timeout retries, such as exponential backoff.

Constructor

new exports(callback, timerCalc)

Source:
Example
let reconnectTimer = new Timer(() => this.connect(), function(tries){
  return [1000, 5000, 10000][tries - 1] || 10000
})
reconnectTimer.scheduleTimeout() // fires after 1000
reconnectTimer.scheduleTimeout() // fires after 5000
reconnectTimer.reset()
reconnectTimer.scheduleTimeout() // fires after 1000
Parameters:
Name Type Description
callback function
timerCalc function