GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: implement WebSocketStream by KhafraDev · Pull Request #3560 · nodejs/undici

Conversation

@KhafraDev

@KhafraDev KhafraDev commented Sep 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

With better-organized internals, this is now much easier and almost completely detached from WebSocket. I could rewrite it to be completely independent of WebSocket, which would allow us to remove it at any time (the only shared internals are a new getURLRecord function and the closing logic).

const stream = new WebSocketStream('https://echo.websocket.org/')
const { readable, writable } = await stream.opened

;(async () => {
  /** @type {ReadableStreamReader} */
  const reader = readable.getReader()

  while (true) {
    const { done, value } = await reader.read()
    if (done) break
    console.log('received message', { value })
  }
})();

setInterval(() => {
  console.log('sending message.')
  /** @type {WritableStreamDefaultWriter} */
  const writer = writable.getWriter()

  writer.write('Hello, world!')

  writer.releaseLock()
}, 5000)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KhafraDev
KhafraDev force-pushed the websocketstream-again branch from 1c931a2 to deae218 Compare September 7, 2024 23:11
@KhafraDev
KhafraDev marked this pull request as ready for review September 8, 2024 17:27
KhafraDev added 15 commits September 8, 2024 13:29
@KhafraDev
start
44cd930
fixup

fixup

fixup
@KhafraDev
fixup
5eb9372
@KhafraDev
fixup
86b4922
@KhafraDev
fixup
5baedea
@KhafraDev
run wpts
64e3c8a
@KhafraDev
fix 49 errors
f3a3d8b
@KhafraDev
fix 49 errors
89b71f6
@KhafraDev
fix 7 errors
4abc633
@KhafraDev
fix 12 failures
8d78080
@KhafraDev
fix 10 failures
fa6c8dd
@KhafraDev
fixup
fccad1f
@KhafraDev
fix 9 failures
43a9b8d
@KhafraDev
fix 3 failures
7586cc2
@KhafraDev
fix 3 failures
a42ae7b
@KhafraDev
fix rest of failures
1237174
@KhafraDev
KhafraDev force-pushed the websocketstream-again branch from 58d5072 to 1237174 Compare September 8, 2024 17:29
@KhafraDev
fixup
7d0554b
@KhafraDev

KhafraDev commented Sep 8, 2024

Copy link
Copy Markdown
Member Author

@nodejs/undici This passes the same subset of WebSocketStream tests that Deno passes. It's missing types and docs now. Looking for code reviews before doing the trivial stuff.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

KhafraDev added 2 commits September 8, 2024 13:41
@KhafraDev
mark timing test as flaky
e3e1818
@KhafraDev
spell
55cf4de
Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/connection.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/connection.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/connection.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/connection.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/receiver.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketerror.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketerror.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketerror.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/util.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/util.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Outdated
try {
string = webidl.converters.USVString(chunk)
} catch (e) {
return Promise.reject(e)

@Uzlopak Uzlopak Sep 9, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

couldnt we reuse the already created deferred promise?

return promise.reject(e)
?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Uzlopak
Uzlopak reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

tsctx
tsctx reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Uzlopak Uzlopak changed the title websocketstream (again) feat: implement WebSocketStream Sep 9, 2024
tsctx
tsctx reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

tsctx
tsctx reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

tsctx
tsctx reviewed Sep 9, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Uzlopak

Uzlopak commented Sep 9, 2024

Copy link
Copy Markdown
Contributor

I wanted to test the WebSocketError thing i mentioned above and found this.

const { WebSocketError } = require('./lib/web/websocket/stream/websocketerror');

console.log(Object.keys(new WebSocketError('asd')));

It is not possible to instantiate WebSocketError by requiring the file alone.

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

KhafraDev added 4 commits September 9, 2024 17:55
@KhafraDev
fixup
2f37e60
@KhafraDev
Merge branch 'main' into websocketstream-again
d45cac7
@KhafraDev
fixup
1d8507a
@KhafraDev
run the CI again! woo!
a64328a
@KhafraDev

KhafraDev commented Sep 25, 2024

Copy link
Copy Markdown
Member Author

@tsctx @Uzlopak PTAL.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KhafraDev

KhafraDev commented Sep 25, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I wanted to test the WebSocketError thing i mentioned above and found this.

A limitation of cjs - there isn't much we can do about shared webidl declarations. If we moved them to webidl.js, we'd have circular imports, if we move them to another file, we have to import another file. You can const { WebSocketError } = require('.') instead. (once I export it... although I'd be willing to bet it's bug-free)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tsctx
tsctx previously requested changes Sep 25, 2024
View reviewed changes
Comment thread lib/web/websocket/stream/websocketstream.js
return
}
} else if (type === opcodes.BINARY) {
chunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength)

@tsctx tsctx Sep 25, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
chunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
chunk = data.byteLength === data.buffer.byteLength ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : new Uint8Array(data)

Copy buffer if needed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tsctx
tsctx dismissed their stale review September 25, 2024 12:36

.

@KhafraDev

KhafraDev commented Sep 26, 2024

Copy link
Copy Markdown
Member Author

please approve so I can land... nits can wait, this is experimental

I want to make websocket PRs but I don't want to manage multiple branches at once. ty

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anonrig
anonrig approved these changes Sep 26, 2024
View reviewed changes
@KhafraDev
KhafraDev merged commit cfab33f into nodejs:main Sep 26, 2024
@KhafraDev
KhafraDev deleted the websocketstream-again branch September 26, 2024 01:50
@github-actions github-actions Bot mentioned this pull request Dec 3, 2024
[Release] v7.1.0 #3922
Merged
This was referenced Dec 16, 2024
[Release] v7.1.1 #3952
Closed
[Release] v7.2.0 #3962
Merged
@github-actions github-actions Bot mentioned this pull request Mar 12, 2025
[Release] v6.21.2 #4092
Closed
@github-actions github-actions Bot mentioned this pull request May 12, 2025
[Release] v6.21.3 #4211
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Uzlopak Uzlopak Uzlopak left review comments
@anonrig anonrig anonrig approved these changes
@tsctx tsctx tsctx left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@KhafraDev @Uzlopak @anonrig @tsctx
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.