Skip to content

implement WebSocketStream - #2713

Closed
KhafraDev wants to merge 1 commit into
nodejs:mainfrom
KhafraDev:websocket-stream
Closed

KhafraDev wants to merge 1 commit into
nodejs:mainfrom
KhafraDev:websocket-stream

Conversation

@KhafraDev

@KhafraDev KhafraDev commented Feb 7, 2024 •

Copy link
Copy Markdown
Member

https://whatpr.org/websockets/48/7b748d3...7b81f79.html#the-websocketstream-interface

Now that the spec has been written, it's time to add it.

const ws = new WebSocketStream(`wss://my.websocket.server`)

ws.opened.then((init) => {
  const writer = init.writable.getWriter()

  writer.ready.then(() => writer.write(Buffer.from([65, 66, 67])))
})

@codecov-commenter

codecov-commenter commented Feb 7, 2024 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.62079% with 565 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (03a2d43) to head (13187d0).
⚠️ Report is 1128 commits behind head on main.

Files with missing lines Patch % Lines
lib/websocket/stream/websocketstream.js 0.00% 359 Missing ⚠️
lib/web/websocket/stream/websocketstream.js 71.98% 100 Missing ⚠️
lib/websocket/stream/websocketerror.js 0.00% 76 Missing ⚠️
lib/web/websocket/util.js 82.92% 28 Missing ⚠️
lib/web/fetch/webidl.js 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2713      +/-   ##
==========================================
- Coverage   93.64%   91.63%   -2.01%     
==========================================
  Files          86       90       +4     
  Lines       23862    24897    +1035     
==========================================
+ Hits        22345    22815     +470     
- Misses       1517     2082     +565     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KhafraDev
KhafraDev marked this pull request as ready for review February 8, 2024 23:00
@KhafraDev

Copy link
Copy Markdown
Member Author

@nodejs/undici this is ready to review now, although this should not be merged until WebSocketStream is added into the spec. whatwg/websockets#48

@ronag

ronag commented Feb 25, 2024 •

Copy link
Copy Markdown
Member

@KhafraDev I don't have so much opinion on this one. I'm not interested in the Web API stuff. Which is why I'd like to separate them out more from undici core.

If you can get one more approving review it should be mergeable. @mcollina

@KhafraDev

Copy link
Copy Markdown
Member Author

Maybe we could start pinging the web standards team for reviews?

Comment thread lib/websocket/stream/websocketstream.js
// 12. Let writable be a new WritableStream .
// 13. Set up writable with writeAlgorithm , closeAlgorithm , and abortAlgorithm .
const writable = new WritableStream({
write: (chunk) => this.#write(chunk),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is respecting backpressure.

@KhafraDev KhafraDev Mar 6, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

WritableStream should have backpressure built into it, at least according to mdn https://developer.mozilla.org/en-US/docs/Web/API/WritableStream

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but you are not forwarding the information of the underlining socket being busy up.
https://github.com/nodejs/undici/pull/2713/files#diff-c1287dec52a96e140d7231c268bfa35a6f1e0390c46ccaf15b3ba5834f2a7342R322 will return false if the socket is "full", and then emit a 'drain' event when free again. This is not connected in any way to the WritableStream.

Comment thread lib/websocket/stream/websocketstream.js
Comment thread lib/websocket/symbols.js Outdated
kReceivedClose: Symbol('received close'),
kByteParser: Symbol('byte parser')
kByteParser: Symbol('byte parser'),
kPromises: Symbol('kPromises')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keep the style?

Suggested change
kPromises: Symbol('kPromises')
kPromises: Symbol('promises')

@KhafraDev
KhafraDev force-pushed the websocket-stream branch 2 times, most recently from ae7a600 to 1abf223 Compare March 6, 2024 02:07
enumerable

implement some more

implement close

finish open

run WPTs

update wpts and fix 9/19 failures

fix most remaining failures

fix remaining test failures

fix writing

fix: implement writing completely

fixup

fixup
@KhafraDev
KhafraDev marked this pull request as draft July 7, 2024 19:08
@KhafraDev KhafraDev closed this Sep 6, 2024
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.

5 participants