- Notifications
You must be signed in to change notification settings - Fork10.1k
socket.io-client@4.8.0
Compare
Could not load tags
Nothing to show
{{ refName }}defaultLoading
· 22 commits to main since this release
4a0555c
This commit was signed with the committer’sverified signature. The key has expired.
Features
Custom transport implementations
Thetransports
option now accepts an array of transport implementations:
import{io}from"socket.io-client";import{XHR,WebSocket}from"engine.io-client";constsocket=io({transports:[XHR,WebSocket]});
Here is the list of provided implementations:
Transport | Description |
---|---|
Fetch | HTTP long-polling based on the built-infetch() method. |
NodeXHR | HTTP long-polling based on theXMLHttpRequest object provided by thexmlhttprequest-ssl package. |
XHR | HTTP long-polling based on the built-inXMLHttpRequest object. |
NodeWebSocket | WebSocket transport based on theWebSocket object provided by thews package. |
WebSocket | WebSocket transport based on the built-inWebSocket object. |
WebTransport | WebTransport transport based on the built-inWebTransport object. |
Usage:
Transport | browser | Node.js | Deno | Bun |
---|---|---|---|---|
Fetch | ✅ | ✅ (1) | ✅ | ✅ |
NodeXHR | ✅ | ✅ | ✅ | |
XHR | ✅ | |||
NodeWebSocket | ✅ | ✅ | ✅ | |
WebSocket | ✅ | ✅ (2) | ✅ | ✅ |
WebTransport | ✅ | ✅ |
(1) sincev18.0.0
(2) sincev21.0.0
Test each low-level transports
When setting thetryAllTransports
option totrue
, if the first transport (usually, HTTP long-polling) fails, then the other transports will be tested too:
import{io}from"socket.io-client";constsocket=io({tryAllTransports:true});
This feature is useful in two cases:
- when HTTP long-polling is disabled on the server, or if CORS fails
- when WebSocket is tested first (with
transports: ["websocket", "polling"]
)
The only potential downside is that the connection attempt could take more time in case of failure, as there have been reports of WebSocket connection errors taking several seconds before being detected (that's one reason for using HTTP long-polling first). That's why the option defaults tofalse
for now.
Added in579b243.
Bug Fixes
- accept string | undefined as init argument (bis) (60c757f)
- allow to manually stop the reconnection loop (13c6d2e)
- close the engine upon decoding exception (04c8dd9)
- do not send a packet on an expired connection (#5134) (8adcfbf)
Dependencies
Assets2
Uh oh!
There was an error while loading.Please reload this page.
18 people reacted