Upgrade socket.io from v3 to v4
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 redispubClient
andsubClient
, 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 theio
function is changed:
- const io = require('socket.io-client');
+ const { io } = require('socket.io-client');
References
- socket.io 4.x documentation
- socket.io 4.x server api documentation
- socket.io 4.x client api documentation