Skip to main content

Socket.IO 4.4.0

· 2 min read
Damien Arrachequesne

Hello everyone!

We have just published a new minor version of Socket.IO: 4.4.0

After a big focus on the client in the latest release, this release is more oriented towards the server.

Support for uWebSocket.js#

Why should one choose between performance and reliability? Starting with, you can now use the HTTP/WebSocket server provided by the uWebSocket.js package:

const { App } = require("uWebSockets.js");const { Server } = require("");
const app = new App();const io = new Server();
io.on("connection", (socket) => {  // ...});
app.listen(3000, (token) => {  if (!token) {    console.warn("port already in use");  }});

It acts as a replacement for both the default Node.js HTTP server and the WebSocket server provided by the ws package, and should improve the memory footprint and the latency of your application. Benchmarks coming soon!

Emit with timeout#

There is a new socket.timeout() method available on both sides:

socket.timeout(5000).emit("my-event", (err) => {  if (err) {    // the other side did not acknowledge the event in the given delay  }}); can now be typed#

For TypeScript users, the can now be typed:

interface SocketData {  name: string;  age: number;}
const io = new Server<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>();
io.on("connection", (socket) => { = "john"; = 42;});

This release also includes some bug fixes, please see the complete diff below.


Size of the bundles:

minmin+gzip KB (+ 0.4 KB ⬆️)13.1 KB (+ 0.1 KB ⬆️) KB (+ 0.4 KB ⬆️)14.2 KB (-) KB (+ 0.3 KB ⬆️)11.3 KB (+ 0.2 KB ⬆️)

That's all for this release, thanks for reading!