Skip to content

core: Implement cross-context LocalConnection via BroadcastChannel#23212

Open
Bubby4j wants to merge 3 commits intoruffle-rs:masterfrom
Bubby4j:localconnection-broadcast-channel
Open

core: Implement cross-context LocalConnection via BroadcastChannel#23212
Bubby4j wants to merge 3 commits intoruffle-rs:masterfrom
Bubby4j:localconnection-broadcast-channel

Conversation

@Bubby4j
Copy link
Contributor

@Bubby4j Bubby4j commented Mar 9, 2026

(note: LLM generated code by a Rust newbie)

Overview

This PR implements complete cross-context LocalConnection support for the Ruffle web player, enabling communication between different movies on a page, across iframes, and between different tabs/windows on the same origin.

Previously, LocalConnection only worked within a single Ruffle instance. This implementation introduces a BroadcastChannel-based backend for transport and a localStorage-based registry for listener discovery and health tracking.

Key Features

  • Cross-Tab Messaging: Uses the BroadcastChannel API to deliver AMF-serialized messages between Ruffle instances.
  • Listener Registry: Uses localStorage to track active LocalConnection listeners across the origin, implementing the "heartbeat" pattern used by Flash to prune stale connections.
  • Latency Minimized: Implemented an instantaneous player wake-up mechanism. The backend now holds a weak reference to the Player and triggers an immediate local connection update upon receiving a channel event, bypassing the standard frame-rate-bound polling loop.
  • Spec Compliance: Enforces the 40KB message size limit and handles superdomain/IP address logic correctly via get_superdomain.
  • Robustness & Safety:
    • Cleanup logic during beforeunload to ensure localStorage locks are released even if a tab is closed abruptly.

Limitations

  • Flash supported cross-origin LocalConnection in certain cases, but this is not easily implemented via BroadcastChannel, and is a far rarer use case. Same-origin only.

Testing

Automated Tests

  • WebdriverIO Integration Tests: Added a suite of cross-tab integration tests in web/packages/selfhosted/test/integration_tests/local_connection_cross_tab/:
    • connect/send between tabs.
    • Message size limit (40KB) enforcement.
    • Stale listener pruning via heartbeat timeouts.
    • Cleanup on tab close/beforeunload.
  • Unit Tests: Added tests for get_superdomain to verify IP address and domain split logic.

Manual Verification

  • Tested with a real-time chat app written in AS2 which has a separate swf loaded in an iframe for chat logs.

Related

#259

#2410
#10493
#10068

@Bubby4j Bubby4j marked this pull request as draft March 9, 2026 04:44
@Lord-McSweeney Lord-McSweeney added A-core Area: Core player, where no other category fits T-compat Type: Compatibility with Flash Player llm The PR contains mostly LLM-generated code labels Mar 9, 2026
@Bubby4j Bubby4j changed the title core: Implement cross-tab LocalConnection via BroadcastChannel core: Implement cross-context LocalConnection via BroadcastChannel Mar 9, 2026
@Bubby4j Bubby4j marked this pull request as ready for review March 9, 2026 05:28
@danielhjacobs danielhjacobs added the squash-on-merge Marks a PR to be squashed before merging. label Mar 12, 2026
@Bubby4j Bubby4j force-pushed the localconnection-broadcast-channel branch from 38a552c to 3e161a8 Compare March 15, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core player, where no other category fits llm The PR contains mostly LLM-generated code newsworthy squash-on-merge Marks a PR to be squashed before merging. T-compat Type: Compatibility with Flash Player

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants