Open
Description
Which application or package is this feature request for?
discord.js
Feature
NodeJS will be enabling the WebSocket
class by default in NodeJS 22: nodejs/node#51594 and is already available in NodeJS 21 as experimental. This would make the dependency on ws
package optional or allow removing entirely.
I will say that in my own usage of it, there are some discrepancies/missing properties between the ws package and the native, so I'm waiting for the @types/node update so that it is very clear what the differences are.
Ideal solution or implementation
Similar to how you can choose to use ffmpeg/avconv, tweetnacl/libsodium, etc. it would be nice to be able to use the WebSocket
provided by node instead of a 3rd party version.
Something like:
const ws = options.useNativeWebSocket && WebSocket ? WebSocket : require('ws');
...
let wsInstance = new ws('wss://...');
or just
let ws = null;
try {
ws = require('ws');
}
catch (ex) {
if (typeof WebSocket !== 'undefined') {
ws = WebSocket;
}
else {
throw new Error("No Websocket class found");
}
}
...
let wsInstance = new ws('wss://...');
Alternative solutions or implementations
No response
Other context
No response