feat(core): Add roWebSocket component with full Node and browser support - #1234
Merged
Merged
Conversation
…ort (Roku OS 16.0) Implements the new WebSocket BrightScript component (ifWebSocket/roWebSocketEvent) with real network I/O on both platforms: a per-socket helper process backed by the `ws` package on Node/CLI (full protocol fidelity, including Ping/Pong control frames, custom headers, and Basic-Auth), and a main-thread-owned real WebSocket bridged to the interpreter worker via a new SharedArrayBuffer-backed event queue on the browser build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
- Mark roWebSocket's port field readonly (only ever set externally via ifSetMessagePort) - Suppress the Math.random() security-rating hit on generateUniqueId(): a non-cryptographic socket correlation id, same reasoning already reviewed as safe for the identical pattern in RoStreamSocket.ts/RoDataGramSocket.ts - Add an explicit comment to WebSocketBrowserBridge's intentionally empty setAutoPingReply no-op Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
…ER ifdef Matches the existing convention (RoURLTransfer.ts's XMLHttpRequest import) instead of a runtime typeof importScripts check. Each platform's bundle now excludes the other platform's transport entirely (verified: brs-ws-queue is absent from the browser bundle, webSocketCommand is absent from the node bundle), rather than relying on webpack's resolve.fallback to stub out the unused one at runtime. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
…nside one function - WebSocketBrowserBridge.ts -> WebSocketBridge.ts (the browser transport) - WebSocketBridge.ts (Node helper-process transport) -> WebSocketNodeBridge.ts - Fix a typo introduced during the rename (WebSockeBridge -> WebSocketBridge) and update every doc-comment/prose reference to the new names across RoWebSocket.ts, WebSocketTransport.ts, webSocketHost.ts, and the test files createTransport() keeps both platform branches' `return` inside one function body rather than two separate per-branch function declarations: splitting it breaks the Node package's cli/ecp webpack bundles with a real TS2393 "Duplicate function implementation" (ts-loader sees both declarations in that configuration, even though only one survives ifdef-loader's stripping) - a real build failure outranks the resulting SonarCloud "unreachable code" false positive, which is suppressed with a NOSONAR comment instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
SonarCloud flags the second return (unreachable from a plain parser's view after the first branch's unconditional return), not the first one the comment was on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
roWebSocket component with full Node and browser support
Sideloadable channel exercising every ifWebSocket method against a public echo server, runnable identically on real Roku, the CLI, and the browser simulator. Real-hardware testing found two BrightScript pitfalls along the way: a function-name field observer runs on the thread that wrote the field, not the thread that registered it (fixed by observing with a roMessagePort instead), and a user sub/function named after a BrightScript global (log vs Log()) is silently never called. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
roWebSocketBrightScript component (Roku OS 16.0) —ifWebSocket,ifHttpAgent, and all 9roWebSocketEventtypes (Opened/Closed/Error/MsgSent/Text/DataReceived/Ping/PongReceived/Timer) matching the documentedGetInfo()field tables.roStreamSocket/roDataGramSocketwhich stay browser-mocked:WebSocketBridge.ts, a per-socket helper process (mirroringStreamBridge.ts/DatagramBridge.ts) backed by thewspackage — full protocol fidelity including real Ping/Pong control frames, custom headers, Basic-Auth, and TLS peer/host verification.WebSocketlives on the main thread (src/api/webSocketHost.ts, shared by the app worker and every SceneGraph Task worker) since the interpreter's own worker thread busy-spins insideWait()and can never run its own WebSocket callbacks. A newSharedEventQueue(src/core/SharedEventQueue.ts) — a lock-free-ish, lossless, orderedSharedArrayBufferevent log — carries events back to the worker. Documented browser platform gaps (no script control over handshake headers/auth/cert verification, no script-visible Ping/Pong) are noted indocs/limitations.md.disposeSocketsForRealm, keyed by owning worker thread id, wired intosrc/api/index.tsandsrc/api/task.ts.Test plan
npm run lint/npm run prettiercleannpm run build(browser + node + scenegraph) succeedstest/brsTypes/components/RoWebSocket.test.js— real loopback I/O against a separate child-process server (open/send/receive, binary messages, synchronousOpen(wait_time), reconnect on the same object, timers, transport-start failure signaling)test/api/webSocketHost.test.js— browser main-thread bridge logic (Node's nativeWebSocketstanding in for the browser's), including per-realm socket disposaltest/core/SharedEventQueue.test.js— including a genuine cross-worker_threadsdelivery testCo-Authored-By: Claude Sonnet 5 noreply@anthropic.com
🤖 Generated with Claude Code
https://claude.ai/code/session_01FBGL5HoJjAyCwbqpQQ9t4a