Edit Page

The io.sails object

Overview

#

The io.sails object is the home of global configuration options for the sails.io.js library and any sockets it creates. Most of the properties on io.sails are used as settings when connecting a client socket to the server or as top-level configuration for the client library itself. io.sails also provides a .connect() method used for creating new socket connections manually.

See Socket Client for information about your different options for configuring io.sails.

The .connect() method

#

If io.sails.autoConnect is false, or if you need to create more than one socket connection with the sails.io.js library, you do so via io.sails.connect([url], [options]). Both arguments are optional, and the value of the io.sails properties (like url, transports, etc.) are used as defaults. See the SailsSocket properties reference for options.

io.sails.autoConnect

#

When io.sails.autoConnect is set to true (the default setting), the library will wait one cycle of the event loop after loading and then attempt to create a new SailsSocket and connect it to the URL specified by io.sails.url. When used in the browser, the new socket will be exposed as io.socket. When used in a Node.js script, the new socket will be attached as the socket property of the variable used to initialize the sails.io.js library.

io.sails.reconnection

#

When io.sails.reconnection is set to true, sockets will automatically (and continuously) attempt to reconnect to the server if they become disconnected unexpectedly (that is, not as the result of a call to .disconnect()). If set to false (the default), no automatic reconnection attempt will be made. Defaults to false.

io.sails.environment

#

Use io.sails.environment to set an environment for sails.io.js, which affects how much information is logged to the console. Valid values are development (full logs) and production (minimal logs).

Other properties and defaults

#

The other properties of io.sails are used as defaults when creating new sockets (either the eager socket or via io.sails.connect()). See the SailsSocket properties reference for a full list of available options, as well as a table of the default io.sails values. Here are the most commonly used properties:

Property Type Default Details
url String Value of io.sails.url The URL that the socket is connected to, or will attempt to connect to.
transports Array Value of io.sails.transports The transports that the socket will attempt to connect using. Transports will be tried in order, with upgrades allowed: that is, if you list both "polling" and "websocket", then after establishing a long-polling connection the server will attempt to upgrade it to a websocket connection. This setting should match the value of sails.config.sockets.transports in your Sails app.
headers Dictionary Value of io.sails.headers Dictionary of headers to be sent by default with every request from this socket. Can be overridden via the headers option in .request().

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference