Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Blob #2229

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Add support for Blob #2229

merged 1 commit into from
Jul 2, 2024

Conversation

lpinca
Copy link
Member

@lpinca lpinca commented Jun 11, 2024

Closes #2206

@lpinca lpinca force-pushed the support/blob branch 7 times, most recently from 223c6fc to a83321b Compare June 13, 2024 17:53
@lpinca
Copy link
Member Author

lpinca commented Jun 13, 2024

@kettanaito I'm still not very happy with this because, other than compatibility with the WHAWG spec, it is pretty much useless. Anyway, here it is. I also didn't run any benchmarks to see the impact on performance.

@@ -1030,6 +1031,11 @@ function initAsClient(websocket, address, protocols, options) {
*/
function emitErrorAndClose(websocket, err) {
websocket._readyState = WebSocket.CLOSING;
//
// The following assignment is practically useless and is done only for

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which summarizes the entire change pretty flawlessly. I am still grateful for this consistency! Thank you!

@lpinca lpinca merged commit 59b9629 into master Jul 2, 2024
101 checks passed
@lpinca lpinca deleted the support/blob branch July 2, 2024 15:50
@titanism
Copy link

titanism commented Jul 4, 2024

Hi there @lpinca, I can't confirm exactly what's wrong here, but I did a minor version bump and this entirely broke our implementation of ws. It's sending everything over the wire as a BLOB now instead of as a Buffer it seems. Seems to be a major breaking change (e.g. we are using msgpackr under the hood to pack/unpack messages sent via websockets, and now they are throwing an error Source must be a Uint8Array or Buffer but was a Blob).

@lpinca
Copy link
Member Author

lpinca commented Jul 4, 2024

@titanism are you are setting websocket.binaryType to 'blob'? Let's continue the discussion in #2239.

Copy link

@nikwen nikwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just looking at the commit to make sure that upgrading ws won't break my app. Looks great overall. Just had a small suggestion. :)

Comment on lines +1198 to +1199
websocket._errorEmitted = true;
websocket.emit('error', err);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems worthwhile to pull out into a small function:

function emitError(err) {
  websocket._errorEmitted = true;
  websocket.emit('error', err);
}

Seems like these lines should always be called together. Pulling them out into a function will make it less likely that someone will forget to do so in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support sending Blob
7 participants