Following Upgrade socket.io from v2 to v3, this post is about upgrading socket.io and its associated packages to the latest versions as of when this post is written and the only setting changes seem to be from the redis-adapater and the way to import client io this time (for our specific use case).

Upgrade guide

Basically read the Migrating from 3.x to 4.0 official guide, then:

  • For npm packages
-   "socket.io": "3.1.2",
-   "socket.io-emitter": "3.2.0",
-   "socket.io-redis": "6.0.1",

+   "socket.io": "4.4.1",
+   "@socket.io/redis-emitter": "4.1.1",
+   "@socket.io/redis-adapter": "7.1.0",
  • For redis-adapter config
    The adapter has changed method signatures about the redis pubClient and subClient, see this issues/411 for details.
- this.io.adapter(
-  createAdapter({
-    pubClient,
-    subClient,
-  }),
- );

+ this.io.adapter(
+  createAdapter(pubClient, subClient),
+ );
  • For client (if any)
    The way to import the io function is changed:
- const io = require('socket.io-client');

+ const { io } = require('socket.io-client');

References

Post tagged with: js, javascript, socket.io, nodejs