Ir para o conteúdo principal

Socket.IO 4.5.0

· 2 minutes de lecture
Damien Arrachequesne

Hello everyone!

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

Here are the new features in this release:

Catch-all listeners for outgoing packets

This is similar to onAny(), but for outgoing packets.

Syntax:

socket.onAnyOutgoing((event, ...args) => {
console.log(event);
});

This feature can be used on both sides, and will also work when broadcasting events:

io.on("connection", (socket) => {
socket.onAnyOutgoing((event, ...args) => {
console.log(event); // prints "some event"
});

io.emit("some event");
});

Multiple acknowledgements when broadcasting

You can now broadcast an event to multiple clients and expect an acknowledgement:

io.timeout(10000).emit("some-event", (err, responses) => {
if (err) {
// some clients did not acknowledge the event in the given delay
} else {
console.log(responses); // one response per client
}
});

Limit the number of packets sent in HTTP long-polling mode

The server will now include the value of the maxHttpBufferSize in the handshake, so the clients will now be able to decide how many packets they have to send to stay under this value.

Here is what the handshake will now look like:

0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000}

More information here.

Disconnection details

The "disconnect" event on the client side will now include additional details to help debugging if anything has gone wrong.

Example when sticky session is not enabled:

socket.on("disconnect", (reason, details) => {
console.log(details.context.status); // 400
console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}'
});

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

Size of the bundles:

minmin+gzip
socket.io.min.js42.6 KB (+ 2.2 KB ⬆️)13.6 KB (+ 0.5 KB ⬆️)
socket.io.msgpack.min.js47.7 KB (+ 2.1 KB ⬆️)14.6 KB (+ 0.4 KB ⬆️)
socket.io.esm.min.js34.5 KB (+ 1.4 KB ⬆️)11.5 KB (+ 0.2 KB ⬆️)

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