feat(call): SFU relay support via optional backend - #159
Draft
HexaField wants to merge 1 commit into
Draft
Conversation
✅ Deploy Preview for coasys-we ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Add an SFU adapter that wraps any SfuManager-compatible backend behind the existing CallMesh interface. The store branches on an optional sfuBackend in deps — when provided, the call connects through the SFU relay instead of building N-1 direct peer connections. New files: sfu.ts — SfuBackend structural interface + createCallSfu() adapter Store changes: - sfuBackend?: SfuBackend in CallStoreDeps - topology signal (mesh/sfu) for the template to surface mode - qualityPreference signal + setQualityPreference action (high/med/low) - SFU join with automatic mesh fallback on failure - Proper teardown of SFU state Exports: - createCallSfu, SfuBackend, SfuQuality, CallTopology The SfuBackend interface matches SfuManager from @coasys/ad4m without importing it — the host constructs the manager and passes it in. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HexaField
force-pushed
the
feat/sfu-integration
branch
from
August 27, 2026 02:04
8b01954 to
216ec28
Compare
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.
What
Adds SFU (Selective Forwarding Unit) support to the call module as an opt-in backend. When a host provides an
SfuBackendthrough the store's deps, the call connects through a relay server instead of building N−1 direct peer connections.The peer-to-peer mesh remains the default and the fallback — the SFU path activates only when a backend appears in deps, and falls back to mesh automatically if the SFU join fails.
Why
The mesh topology scales to about 4–6 participants before upstream bandwidth saturates. An SFU receives each participant's media once and forwards it selectively, shifting the bottleneck from the weakest uplink to the relay's bandwidth. This unblocks larger calls without changing anything about smaller ones.
How
New:
sfu.tsSfuBackend— structural interface satisfied bySfuManagerfrom@coasys/ad4mwithout importing it. The host constructs the manager (with neighbourhood proxy, room id, agent DID, ICE config) and passes it in. The call module carries no dependency on@coasys/ad4m.createCallSfu()— adapter that wraps anSfuBackendbehind the existingCallMeshinterface. Joins the SFU, maps participant events to stream/state callbacks, and handles track replacement on the singleRTCPeerConnection.Modified:
store.tssfuBackend?: SfuBackendadded toCallStoreDepstopologysignal ('mesh'|'sfu') — exposes the active topology for the templatequalityPreferencesignal +setQualityPreference()action — simulcast layer selection ('high'/'medium'/'low'), only meaningful in SFU modejoin()branches: SFU path acquires media first (the SFU needs tracks for the SDP offer), then joins the relay; mesh path unchangedModified:
index.tscreateCallSfu,SfuBackend,SfuQuality,CallTopologyIntegration
A host wiring up SFU support:
What the user sees
store.topology()returns'mesh'or'sfu'— the host decides how to render thisstore.setQualityPreference('medium')— the host adds a toggle if desiredTesting
🤖 Generated with Claude Code