fix: provide websocket instead of stream to avoid potential backpressure issues (#289)
Now createWebSocketStream is not called therefore there are no memory leaks/backpressure to worry about.
Checklist
- [x] run
npm run testandnpm run benchmark - [x] tests and/or benchmarks are included
- [x] documentation is changed or added
- [x] commit message and code follows the Developer's Certification of Origin and the Code of conduct
@mcollina As discussed here https://github.com/fastify/fastify-websocket/issues/289#issuecomment-1973621926
I've removed stream creation completely. Another option here is to provide an object of shape { socket: WebSocket } to provide compatibility with most common use cases.
Also, could be nice to provide a function to convert that socket into a stream; so the object could even be { socket: WebSocket; getStream: (opts?: DuplexOptions) => Promise<Duplex> }.
I can update this PR to include either of the aforementioned solutions.
I don't think having a specific function is needed, let's just document how to create it using ws.
@mcollina I've added an example to README.md
CI is failing
@mcollina Resolved, for some reason the unit test was relying on the count of fastify log items to be constant, updated it to fail if level >= 50 instead.