Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sails-hook-sockets

balderdashy67.3kMIT3.0.2

Implements socket.io support in Sails

socket.io, sails.js, sails-hook, hook

readme

sails-hook-sockets

Implements Socket.io support in Sails.

This is a core hook in the Sails.js framework. You can override or disable it using your .sailsrc file or environment variables. See Concepts > Configuration for more information.

Help

If you have further questions or are having trouble, click here.

What version of Sails is this for?

This hook is for Sails v1.0 and up.

Prior to Sails v1.0, this hook was a dependency of Sails core. But now, it is now installed as a direct dependency of your Sails app.

What is this? What does it do?

This repo contains a hook, one of the building blocks Sails is made out of.

This hook's responsibilities are:

  • When initialized...
    • fire up socket.io server
    • listen for connect / disconnect events
      • listen for get/post/put/delete/patch events
        • create bare-bones request and response contexts, then pass them to the core interpreter in Sails to be routed on the fly.
    • Bind after "shadow" routes...
      • GET /__getcookie
    • Expose on the sails app object:

What version of Socket.io does this hook use?

Click here to check out the semver range for this hook's Socket.io dependency.

For reproducibility, we always pin 3rd party dependencies to a specific version, using a consistent verified version string when possible (see kit).

Bugs   NPM version

To report a bug, click here.

Contributing

Please observe the guidelines and conventions laid out in the Sails project contribution guide when opening issues or submitting pull requests.

NPM

Running the tests

First, clone this repo, cd into it, and install dependencies:

git clone https://github.com/balderdashy/sails-hook-sockets.git
cd sails-hook-sockets
npm install
Run them all

To run all the tests, start a local redis server on port 6380 and then run the tests using mocha:

redis-server --port 6380 --requirepass 'secret'
npm test
Run only certain tests

Alternatively, you can run a particular set of tests with:

node ./node_modules/mocha/bin/mocha -g 'without session'

(this may be useful if you don't want to wait for all the tests to run, or e.g. if you aren't able to install a redis server locally. However please make sure all the tests pass before submitting a PR.)

License

The Sails framework is free and open-source under the MIT License.

changelog

sails-hook-sockets changelog

3.0.2

  • Upgraded socket.io from 4.7.5 to 4.8.1 to resolve vulnerability warning

3.0.1

  • Upgraded socket.io from 4.7.2 to 4.7.5 to resolve vulnerability warning

3.0.0

  • Upgraded socket.io from 2.5.0 to 4.7.2 to resolve vulnerability warning
  • Upgraded socket.io-redis from 5.2.0 to 6.1.0 to resolve vulnerability warning

2.0.4

  • Upgraded semver from 4.3.6 to 7.5.2 to resolve vulnerability warning

2.0.3

  • Upgraded async from 2.0.1 to 2.6.4 to resolve vulnerability warning

2.0.2

  • Upgraded socket.io from 2.4.1 to 2.5.0 to resolve vulnerability warning

2.0.1

  • Upgraded socket.io from 2.2.0 to 2.4.1 to resolve deprecation warning

2.0.0

  • Upgraded machinepack-redis to resolve vulnerability/deprecation warnings (note this includes a major version bump of redis, the Redis client library)
  • Upgraded machinepack-urls to resolve vulnerability/deprecation warnings
  • Upgraded socket.io from 2.0.3 to 2.2.0 to resolve deprecation warning

1.1.0

  • [UPGRADE] Update socket.io dependency to version 1.5.1.
  • [ENHANCEMENT] Add validation for db option. Thanks bberry6! #9
  • [ENHANCEMENT] Add onlyAllowOrigins config to restrict the origins allowed to connect to the socket server. 9450c96

1.0.1

  • [BUGFIX] Made maxHttpBufferSize actually work by passing through to the underlying adapter. f5bf545
  • [DEPRECATION] Deprecated maxBufferSize option in favor of maxHttpBufferSize. f5bf545
  • [ENHANCEMENT] Make "websocket" the default transport. This is better supported by more clients than the "polling-first" method. The relevant changes have been made in sails.io.js as well. 8135ada

1.0.0

  • [BREAKING CHANGE] Removed deprecated sails.socket methods: .emit(), .emitToAll(), .rooms(), .socketRooms(), .subscribers(), .id().
  • [ENHANCEMENT] Added support for the "subEvent" option. Thanks @albi34! #26
  • [BUGFIX] Explicitly set content-type when responding to JSONP request. Thanks @arryon! #28

0.13.7

  • [BUGFIX] Correctly handle joining/leaving rooms using socket ID as the first argument. Thanks @Biktop! #22

0.13.6

  • [BUGFIX] Make "async" a full dependency, to ensure compatibility with Sails when globals are turned off a5bd1e1

0.13.5

  • [ENHANCEMENT] Forward the "nosession" header to the Sails virtual router (allowing sockets to connect without creating sessions) 7331197

0.13.4

  • [BUGFIX] Fix issue where admin bus crashes when "db" or "pass" is not specified in redis config 14210dc

0.13.3

  • [BUGFIX] Added missing require()s to ensured that hook works without Sails globals enabled

0.13.2

  • [ENHANCEMENT] Optimized .addRoomMembersToRooms(), .removeRoomMembersFromRooms() for use with single socket rooms
  • [ENHANCEMENT] Made .join() and .leave() work cross-server (when provided with a socket ID)
Low Risk Compatibility Warnings
  • Since .join() and .leave() no longer throw if given an ID of a socket that is not connected to the server--instead, they will use .addRoomMembersToRooms() or .removeRoomMembersFromRooms() to give any other connected servers the chance to find that socket. If you must check for socket connection on the server first, inspect sails.io.sockets.connected[socketId] (see http://socket.io/docs/server-api/#namespace#connected:object)

0.13.1

  • [ENHANCEMENT] Added .addRoomMembersToRooms()
  • [ENHANCEMENT] Added .removeRoomMembersFromRooms()
  • [ENHANCEMENT] Added .leaveAll()
  • [ENHANCEMENT] Refactored admin bus to connect directly to Redis rather than using a socket.io client connection
  • [DEPRECATION] Deprecated .subscribers().

0.13.0

  • [ENHANCEMENT] Added callback argument to .join(), .leave() and .subscribers().
  • [ENHANCEMENT] Added ability to broadcast to multiple rooms using .broadcast().
  • [DEPRECATION] Deprecated .rooms() method, since it uses undocumented socket.io functionality.
  • [DEPRECATION] Deprecated .emit() and .emitAll() and made them aliases for .broadcast().
  • [DEPRECATION] Deprecated .socketRooms().
  • [DEPRECATION] Deprecated .id() (made it an alias of .getId()).
  • [DEPRECATION] Deprecated synchronous use of .subscribers().
Low Risk Compatibility Warnings
  • Since .emit() and .emitAll() are now aliases for .broadcast(), they will no longer throw or give feedback if any of the specified sockets aren't connected to the server making the call. If you must check for socket connection on the server first, inspect sails.io.sockets.connected[socketId] (see http://socket.io/docs/server-api/#namespace#connected:object)