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

Package detail

socket.io-adapter

socketio29.6mMIT2.5.5TypeScript support: included

default socket.io in-memory adapter

readme

socket.io-adapter

Default socket.io in-memory adapter class.

Compatibility table:

Adapter version Socket.IO server version
1.x.x 1.x.x / 2.x.x
2.x.x 3.x.x

How to use

This module is not intended for end-user usage, but can be used as an interface to inherit from other adapters you might want to build.

As an example of an adapter that builds on top of this, please take a look at socket.io-redis.

License

MIT

changelog

History

Release notes

2.5.5 (2024-06-18)

This release contains a bump of the ws dependency, which includes an important security fix.

Advisory: https://github.com/advisories/GHSA-3h5v-q93c-6h6q

2.5.4 (2024-02-22)

Bug Fixes

  • ensure the order of the commands (a13f35f)
  • types: ensure compatibility with TypeScript < 4.5 (ca397f3)

2.5.3 (2024-02-21)

Two abstract classes were imported from the Redis adapter repository:

  • the ClusterAdapter class, which manages the messages sent between the server instances of the cluster
  • the ClusterAdapterWithHeartbeat class, which extends the ClusterAdapter and adds a heartbeat mechanism in order to check the healthiness of the other instances

Other adapters can then just extend those classes and only have to implement the pub/sub mechanism (and not the internal chit-chat protocol):

class MyAdapter extends ClusterAdapterWithHeartbeat {
  constructor(nsp, pubSub, opts) {
    super(nsp, opts);
    this.pubSub = pubSub;
    pubSub.subscribe("main-channel", (message) => this.onMessage(message));
    pubSub.subscribe("specific-channel#" + this.uid, (response) => this.onResponse(response));
  }

  doPublish(message) {
    return this.pubSub.publish("main-channel", message);
  }

  doPublishResponse(requesterUid, response) {
    return this.pubSub.publish("specific-channel#" + requesterUid, response);
  }
}

Besides, the number of "timeout reached: only x responses received out of y" errors (which can happen when a server instance leaves the cluster) should be greatly reduced by this commit.

Bug Fixes

  • cluster: fix count in fetchSockets() method (80af4e9)
  • cluster: notify the other nodes when closing (0e23ff0)

Performance Improvements

  • cluster: use timer.refresh() (d99a71b)

2.5.2 (2023-01-12)

The ws dependency was moved from peerDependencies to dependencies, in order to prevent issues like this.

2.5.1 (2023-01-06)

Bug Fixes

  • properly precompute the WebSocket frames (99b0f18)

2.5.0 (2023-01-06)

Features

  • implement connection state recovery (f529412)

Performance Improvements

  • precompute the WebSocket frames when broadcasting (5f7b47d)

2.4.0 (2022-03-30)

Features

  • broadcast and expect multiple acks (a7f1c90)
  • notify listeners for each outgoing packet (38ee887)

2.3.3 (2021-11-16)

Bug Fixes

  • fix broadcasting volatile packets with binary attachments (88eee59)

2.3.2 (2021-08-28)

Bug Fixes

  • fix race condition when leaving rooms (#74) (912e13a)

2.3.1 (2021-05-19)

Bug Fixes

  • restore compatibility with binary parsers (a33e42b)

2.3.0 (2021-05-10)

Features

  • add a serverSideEmit empty function (c4cbd4b)
  • add support for the "wsPreEncoded" writing option (5579d40)

2.2.0 (2021-02-27)

Features

  • add some utility methods (1c9827e)
  • allow excluding all sockets in a room (#66) (985bb41)

2.1.0 (2021-01-15)

Features

2.0.3 (2020-11-05)

Features

  • add init() and close() methods (2e023bf)
  • use ES6 Sets and Maps (53ed3f4)

Bug Fixes

  • Encoder#encode() is now synchronous (c043650)

2.0.3-rc2 (2020-10-20)

Features

  • add init() and close() methods (2e023bf)

2.0.3-rc1 (2020-10-15)

2.0.2 (2020-09-28)

The dist/ directory was not up-to-date when publishing the previous version...

2.0.1 (2020-09-28)

Bug Fixes

  • Encoder#encode() is now synchronous (c043650)

2.0.0 (2020-09-25)

Features