-
Notifications
You must be signed in to change notification settings - Fork 963
Add WebSocket handler for Browser and Node #9191
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
Conversation
|
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.
See the comments for more but I'm leaning towards not offering this for Node given the complications and not being sure there's a big demand for it anyway. I feel really bad about that given the effort you've put into the Node implementation and the clever dead code trick but it might come back.
Size Report 1Affected ProductsNo changes between base commit (a4897a6) and merge commit (a06a3a1).Test Logs |
Size Analysis Report 1Affected ProductsNo changes between base commit (a4897a6) and merge commit (a06a3a1).Test Logs |
* limitations under the License. | ||
*/ | ||
|
||
import { NodeWebSocketHandler } from './node/websocket'; |
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.
Does this work? The rollup alias just replaces the node
in the import path, it doesn't replace the name of the imported symbol, right? Isn't this supposed to be just WebSocketHandlerImpl
or something and the exported symbol from node/websocket.ts
and browser/websocket.ts
both have the same name?
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.
This file platform/websocket.ts
is only used during tests ran with ts-node
, where the rollup alias isn't applied.
In the code that is bundled, we should not import BrowserWebSocketHandler
or NodeWebSocketHandler
directly. Instead, we should use the factory method createWebSocketHandler
.
We could make the class names identical WebSocketHandlerImpl
, but I prefer them being more explicit for readability reasons if there's no technical requirement for them to have the same name.
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.
Oh I see, you just don't have an example of a prod code consumer calling createWebSocketHandler in this PR.
Adds a WebSocket handler with implementations in Browser and Node environments. This will be used for BiDi.
Changes:
WebSocketHandler
:BrowserWebSocketHandler
) and Node (NodeWebSocketHandler
).NodeWebSocketHandler
uses the built-in globalWebSocket
available in Node >= 22.ws
as a dev dependency for types and the mock test server (Node 22 doesn't support web socket servers).BrowserWebSocketHandler
using a mockedwindow.WebSocket
.NodeWebSocketHandler
using a localMockWebSocketServer
.test:node
generateAliasConfig
to the set of rollup helpers, and uses it for platform import aliasing.