Comments (13)
It is not for historic reasons, see nodejs/undici#1795 (comment).
from ws.
See also nodejs/undici#1795 (comment).
from ws.
It is doable but in my opinion it is not worth it. Added complexity for little to no benefit.
from ws.
Strictly following the WHATWG specification is a non-goal for ws
.
from ws.
This is an important context, thanks for sharing! So, Blobs being written first is a Node.js thing?
This is also interesting:
In practice, even though it requires explicitly setting binaryType, 97% of messages are received as ArrayBuffers.
Especially given that the default binaryType
value for blob
. I believe Undici did end up supporting sending Blob
from the client (at least, I seem to be able to do that in tests).
from ws.
So, Blobs being written first is a Node.js thing?
Yes, because there is no official API to get an ArrayBuffer
synchronously from a Blob
and streams do not support Blob
s natively.
I believe Undici did end up supporting sending
Blob
from the client (at least, I seem to be able to do that in tests).
I think it is affected by the issue I wrote in that comment.
from ws.
Got it. Thanks for the great references! Do you consider this proposal to be out of scope? We should close it then.
from ws.
What about supporting this only on the surface level? Accepting the Blob
but converting it internally to nodebuffer
and proceeding as ws
does now? If that makes any sense, of course (would love to learn if it doesn't).
My main use case is showcasing ws
for testing, and it's not great to omit sending/receiving Blob
data.
from ws.
Accepting the
Blob
but converting it internally tonodebuffer
and proceeding asws
does now?
It is not trivial because again, converting a Blob
to an ArrayBuffer
/Buffer
synchronously is not supported by Node.js. We could pause the Sender
like we do when compressing data but I'm not very happy with it. Also what about support for Node.js versions where Blob
is not supported?
It is a lot easier to convert the Blob
before calling websocket.send()
.
websocket.send(await blob.arrayBuffer());
from ws.
It is not trivial because again, converting a Blob to an ArrayBuffer/Buffer synchronously is not supported by Node.js.
I keep missing this bit. Got it.
Also what about support for Node.js versions where Blob is not supported?
Blob
is supported since Node.js 18, which by itself reaches the maintenance mode in a few months. Does ws
support EOL versions of Node.js (16 and older)? If anything, I see this as a motivation to drop those old versions but you would know far better than me here.
from ws.
Yes, ws
still supports Node.js 10.
from ws.
It is a lot easier to convert the
Blob
before callingwebsocket.send()
.
I understand this. What I'm proposing is not a matter of convenience but expectations. As in, valid WebSocket usage as per spec should work. Sending a Blob
is a valid usage. Not supporting it is a limitation of ws
(as the immediate agent; the issue runs deeper as we've discussed) so it may be a good thing to try to find a solution/compromise here.
I also understand that ws
doesn't promise full WHATWG compliance as it's a server library and the spec has nothing about servers, afaik. I'm coming purely from the client usage. If a WebSocket client, like Undici, sends a Blob, it's okay if ws
receives and handles it as something else. The issue is that the client will never receive a Blob, even if its binaryType = 'blob'
(I will double-check on this but I recall that being the outcome of my testing).
from ws.
The issue is that the client will never receive a Blob, even if its
binaryType = 'blob'
(I will double-check on this but I recall that being the outcome of my testing)
That is correct for ws
. That binary type is not supported. Receiving a Blob
is easier as it can be created synchronously from an ArrayBuffer
but if we allow receiving it we should also allow sending it.
from ws.
Related Issues (20)
- Dual Triggering of WebSocket Events - ws.on('message') and stream.on('data') HOT 7
- Sec-WebSocket-Accept not found HOT 7
- ws issues with custom hostname HOT 2
- WebSocketServer.address() error needs more context HOT 2
- clientTracking - the client is not destroyed if the server closes or terminates the connection. HOT 2
- The code isn't working. HOT 14
- Is there anyway to disable the websocket closeTimeout? HOT 9
- Unhappy TypeScript when using compilerOptions: module: Node16 || NodeNext HOT 1
- WebSocket Ping-Pong Timeout and Connection Closure Failure HOT 3
- terminate() doesnt terminate instantly HOT 6
- ws doesn't work with sveltekit's adapter-cloudflare HOT 4
- Websocket opens randomly not everytime. HOT 5
- While building websocket-api:9.4.48.v20220622 with UAT, failed. (Test Case Failure) HOT 7
- query: difference between ws.onmessage = handler and ws.on('message', handler) HOT 2
- Messages are dispatched while microtask queue is not empty HOT 6
- Uhhh, what does .isAlive do again? HOT 2
- RangeError: Invalid WebSocket frame: MASK must be set HOT 1
- Invalid dns names should not cause an uncatchable fatal exception HOT 2
- Incorrect/incomplete documentation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ws.