Edit Page

SailsSocket Properties

Overview

This page describes the properties available on each SailsSocket instance. These properties are set in the initial call to io.sails.connect which creates the SailsSocket, and cannot be changed while the socket is connected (with the exception of headers).

If the socket becomes disconnected (either involuntarily or as a result of a call to .disconnect), the properties can be changed until the socket connects again. This allows you to connect the same SailsSocket instance (keeping its bound events and queued requests intact) to a different server if necessary.

Common properties

Property Type Default Details
url Value of io.sails.url The URL that the socket is connected to, or will attempt to connect to.
transports 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 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().

Advanced properties

Property Type Default Details
query Value of io.sails.query Query string to use with the initial connection to the server. In server code, this can be accessed via req.socket.handshake.query in controller actions or socket.handshake.query in socket lifecycle callbacks. Note that information about the sails.io.js SDK version will be tacked onto whatever query string you specify.
initialConnectionHeaders Value of io.sails.initialConnectionHeaders Node.js only--not available in browser. Dictionary of headers to be sent with the initial connection to the server. In server code, these can be accessed via req.socket.handshake.headers in controller actions or socket.handshake.headers in socket lifecycle callbacks. This is useful for (for example) sending a cookie header with the initial handshake, allowing a socket to connect to a previously-established Sails session.
useCORSRouteToGetCookie -or- Value of io.sails.useCORSRouteToGetCookie Only relevant in browser environments, and if you are relying on the default Sails session + session cookies for authentication. For cross-origin socket connections, use this property to choose a route to send an initial JSONP request in order to retrieve a cookie, so that the right session can be established. The route should respond the string _sailsIoJSConnect(), which will allow the connection to continue. If useCORSRouteToGetCookie is true, the default /__getcookie route on the Sails server will be used. If it is false, no attempt will be made to contact the remote server before connecting the socket.

io.sails.* defaults

The io.sails object can be used to provide default values for new client sockets. For example, setting io.sails.url = "http://myapp.com:1234" will cause every new client socket to connect to http://myapp.com:1234, unless a url value is provided in the call to io.sails.connect().

The following are the default values for properties in io.sails.

Property Default
url In browser, the URL of the page that loaded the sails.io.js script. In Node.js, no default.
transports ['polling', 'websocket']
headers {}
query ''
initialConnectionHeaders {}
useCORSRouteToGetCookie true

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-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Sails logo
  • Home
  • Get started
  • Support
  • Documentation
  • Documentation

For a better experience on sailsjs.com, update your browser.

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Reference

  • Application
    • Events
    • Lifecycle
    • sails.getRouteFor()
    • sails.getUrlFor()
    • sails.lift()
    • sails.load()
    • sails.log()
    • sails.lower()
    • sails.request()
    • sails.getBaseUrl()
  • Blueprint API
    • add to
    • create
    • destroy
    • find one
    • find where
    • populate where
    • remove from
    • update
  • Command Line Interface
    • sails console
    • sails debug
    • sails generate
    • sails lift
    • sails new
    • sails version
  • Configuration
    • sails.config.*
    • sails.config.blueprints
    • sails.config.bootstrap()
    • sails.config.connections
    • sails.config.cors
    • sails.config.csrf
    • sails.config.globals
    • sails.config.http
    • sails.config.i18n
    • sails.config.log
    • sails.config.models
    • sails.config.policies
    • sails.config.routes
    • sails.config.session
    • sails.config.sockets
    • sails.config.views
  • Request (`req`)
    • req.accepted
    • req.acceptedCharsets
    • req.acceptedLanguages
    • req.body
    • req.cookies
    • req.fresh
    • req.headers
    • req.host
    • req.ip
    • req.ips
    • req.isSocket
    • req.method
    • req.options
      • req.options.values
      • req.options.where
    • req.originalUrl
    • req.params
    • req.path
    • req.protocol
    • req.query
    • req.secure
    • req.signedCookies
    • req.socket
    • req.subdomains
    • req.url
    • req.wantsJSON
    • req.xhr
    • req.accepts()
    • req.acceptsCharset()
    • req.acceptsLanguage()
    • req.allParams()
    • req.file()
    • req.get()
    • req.is()
    • req.param()
  • Response (`res`)
    • res.attachment()
    • res.badRequest()
    • res.clearCookie()
    • res.cookie()
    • res.created()
    • res.forbidden()
    • res.get()
    • res.json()
    • res.jsonp()
    • res.location()
    • res.negotiate()
    • res.notFound()
    • res.ok()
    • res.redirect()
    • res.send()
    • res.serverError()
    • res.set()
    • res.status()
    • res.type()
    • res.view()
  • Waterline (ORM)
    • Models
      • .count()
      • .create()
      • .destroy()
      • .find()
      • .findOne()
      • .findOrCreate()
      • .native()
      • .query()
      • .stream()
      • .update()
    • Populated Values
      • .add()
      • .remove()
    • Queries
      • .exec()
      • .limit()
      • .populate()
      • .skip()
      • .sort()
      • .where()
    • Records
      • .save()
      • .toJSON()
      • .toObject()
  • WebSockets
    • Resourceful PubSub
      • .message()
      • .publishAdd()
      • .publishCreate()
      • .publishDestroy()
      • .publishRemove()
      • .publishUpdate()
      • .subscribe()
      • .unsubscribe()
      • .unwatch()
      • .watch()
      • .subscribers()
    • sails.sockets
      • .addRoomMembersToRooms()
      • .blast()
      • .broadcast()
      • .getId()
      • .join()
      • .leave()
      • .leaveAll()
      • .removeRoomMembersFromRooms()
      • sails.sockets.emit()
      • sails.sockets.id()
      • sails.sockets.rooms()
      • sails.sockets.socketRooms()
      • sails.sockets.subscribers()
    • Socket Client
      • io.sails
      • io.socket
      • SailsSocket
        • Methods
        • Properties
      • io.socket.delete()
      • io.socket.get()
      • io.socket.off()
      • io.socket.on()
      • io.socket.post()
      • io.socket.put()
      • io.socket.request()

Built with Love

The Sails framework is maintained by a web & mobile studio in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!

Sails:
  • What is Sails?
  • Treeline IDE
  • Contribute
  • Logos/artwork
About:
  • The Sails Company
  • Security
  • News
  • Legal
Help:
  • Get started
  • Documentation
  • Docs
  • Enterprise
  • Hire us

© 2012-2018 The Sails Company. 
The Sails framework is free and open-source under the MIT License.