Manager

The Manager manages the Engine.IO client instance, which is the low-level engine that establishes the connection to the server (by using transports like WebSocket or HTTP long-polling).

The Manager handles the reconnection logic.

A single Manager can be used by several Sockets. You can find more information about this multiplexing feature here.

Please note that, in most cases, you won’t use the Manager directly but use the Socket instance instead.

new Manager(url[, options])

  • url (String)
  • options (Object)
  • Returns Manager

Available options:

OptionDefault valueDescription
path/socket.ioname of the path that is captured on the server side
reconnectiontruewhether to reconnect automatically
reconnectionAttemptsInfinitynumber of reconnection attempts before giving up
reconnectionDelay1000how long to initially wait before attempting a new reconnection. Affected by +/- randomizationFactor, for example the default initial delay will be between 500 to 1500ms.
reconnectionDelayMax5000maximum amount of time to wait between reconnections. Each attempt increases the reconnection delay by 2x along with a randomization factor.
randomizationFactor0.50 <= randomizationFactor <= 1
timeout20000connection timeout before an error event is emitted
autoConnecttrueby setting this false, you have to call manager.open whenever you decide it’s appropriate
query{}additional query parameters that are sent when connecting a namespace (then found in socket.handshake.query object on the server-side)
parser-the parser to use. Defaults to an instance of the Parser that ships with socket.io. See socket.io-parser.

Available options for the underlying Engine.IO client:

OptionDefault valueDescription
upgradetruewhether the client should try to upgrade the transport from long-polling to something better.
forceJSONPfalseforces JSONP for polling transport.
jsonptruedetermines whether to use JSONP when necessary for polling. If disabled (by settings to false) an error will be emitted (saying “No transports available”) if no other transports are available. If another transport is available for opening a connection (e.g. WebSocket) that transport will be used instead.
forceBase64falseforces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
enablesXDRfalseenables XDomainRequest for IE8 to avoid loading bar flashing with click sound. default to false because XDomainRequest has a flaw of not sending cookie.
timestampRequests-whether to add the timestamp with each transport request. Note: polling requests are always stamped unless this option is explicitly set to false
timestampParamtthe timestamp parameter
transports[“polling”, “websocket”]a list of transports to try (in order). Engine always attempts to connect directly with the first one, provided the feature detection test for it passes.
transportOptions{}hash of options, indexed by transport name, overriding the common options for the given transport
rememberUpgradefalseIf true and if the previous websocket connection to the server succeeded, the connection attempt will bypass the normal upgrade process and will initially try websocket. A connection attempt following a transport error will use the normal upgrade process. It is recommended you turn this on only when using SSL/TLS connections, or if you know that your network does not block websockets.
onlyBinaryUpgradesfalsewhether transport upgrades should be restricted to transports supporting binary data
requestTimeout0timeout for xhr-polling requests in milliseconds (0) (only for polling transport)
protocols-a list of subprotocols (see MDN reference) (only for websocket transport)

Node.js-only options for the underlying Engine.IO client:

OptionDefault valueDescription
agentfalsethe http.Agent to use
pfx-Certificate, Private key and CA certificates to use for SSL.
key-Private key to use for SSL.
passphrase-A string of passphrase for the private key or pfx.
cert-Public x509 certificate to use.
ca-An authority certificate or array of authority certificates to check the remote host against.
ciphers-A string describing the ciphers to use or exclude. Consult the cipher format list for details on the format.
rejectUnauthorizedtrueIf true, the server certificate is verified against the list of supplied CAs. An “error” event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent.
perMessageDeflatetrueparameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
extraHeaders{}Headers that will be passed for each request to the server (via xhr-polling and via websockets). These values then can be used during handshake or for special proxies.
forceNodefalseUses NodeJS implementation for websockets - even if there is a native Browser-Websocket available, which is preferred by default over the NodeJS implementation. (This is useful when using hybrid platforms like nw.js or electron)
localAddress-the local IP address to connect to

manager.reconnection([value])

  • value (Boolean)
  • Returns Manager|Boolean

Sets the reconnection option, or returns it if no parameters are passed.

manager.reconnectionAttempts([value])

  • value (Number)
  • Returns Manager|Number

Sets the reconnectionAttempts option, or returns it if no parameters are passed.

manager.reconnectionDelay([value])

  • value (Number)
  • Returns Manager|Number

Sets the reconnectionDelay option, or returns it if no parameters are passed.

manager.reconnectionDelayMax([value])

  • value (Number)
  • Returns Manager|Number

Sets the reconnectionDelayMax option, or returns it if no parameters are passed.

manager.timeout([value])

  • value (Number)
  • Returns Manager|Number

Sets the timeout option, or returns it if no parameters are passed.

manager.open([callback])

  • callback (Function)
  • Returns Manager

If the manager was initiated with autoConnect to false, launch a new connection attempt.

The callback argument is optional and will be called once the attempt fails/succeeds.

manager.connect([callback])

Synonym of manager.open([callback]).

manager.socket(nsp, options)

  • nsp (String)
  • options (Object)
  • Returns Socket

Creates a new Socket for the given namespace. Only auth ({ auth: {key: "value"} }) is read from the options object. Other keys will be ignored and should be passed when instancing a new Manager(nsp, options).

Event: ‘error’

  • error (Object) error object

Fired upon a connection error.

  1. socket.io.on("error", (error) => {
    // ...
    });

Event: ‘reconnect’

  • attempt (Number) reconnection attempt number

Fired upon a successful reconnection.

  1. socket.io.on("reconnect", (attempt) => {
    // ...
    });

Event: ‘reconnect_attempt’

  • attempt (Number) reconnection attempt number

Fired upon an attempt to reconnect.

  1. socket.io.on("reconnect_attempt", (attempt) => {
    // ...
    });

Event: ‘reconnect_error’

  • error (Object) error object

Fired upon a reconnection attempt error.

  1. socket.io.on("reconnect_error", (error) => {
    // ...
    });

Event: ‘reconnect_failed’

Fired when couldn’t reconnect within reconnectionAttempts.

  1. socket.io.on("reconnect_failed", () => {
    // ...
    });

Event: ‘ping’

Fired when a ping packet is received from the server.

  1. socket.io.on("ping", () => {
    // ...
    });