Skip to content

feat(rwi): answer an SDP offer in call.leg_add - #310

Open
jsmey7 wants to merge 1 commit into
restsend:mainfrom
jsmey7:rwi-leg-add-offer
Open

jsmey7 wants to merge 1 commit into
restsend:mainfrom
jsmey7:rwi-leg-add-offer

Conversation

@jsmey7

@jsmey7 jsmey7 commented Nov 19, 2026

Copy link
Copy Markdown

call.leg_add dials a SIP target today, so a browser or WebRTC agent can join a call only by registering as a SIP user. This adds an optional offer to call.leg_add: the session builds the leg's media peer from the offer through the existing rustrtc WebRTC path (ICE + DTLS, as for WebRTC SIP callers), answers it, and the command completes with the answer.

{"action":"call.leg_add","action_id":"join-1","params":{"call_id":"session-1","leg_id":"0192f0c4a8e47b3c9d2e5f6a7b8c9d0e","offer":"v=0\r\n..."}}
{"type":"command_completed","action_id":"join-1","action":"call.leg_add","call_id":"session-1","status":"success","data":{"leg_id":"0192f0c4a8e47b3c9d2e5f6a7b8c9d0e","answer":"v=0\r\n..."}}
  • target and offer are exclusive; a request with both fails.
  • The command completes once ICE gathering finishes, within 10 s. The leg is connected at once and emits a leg-scoped call_answered with no call_ringing.
  • The answer puts the caller's negotiated codec first when the offer carries it, so a bridge passes audio through. Otherwise it follows the codec policy, or G.711 when none is configured, and the bridge transcodes.
  • ICE uses the existing external_ip, webrtc_port_start/webrtc_port_end and ice_servers settings.
  • The leg has no SIP dialog. call.bridge, call.leg_remove and call teardown work as for dialed legs, and leg events are unchanged.

Changes:

  • RwiCommandPayload::LegAdd gains offer: Option<String>, and CommandResult::LegAdded gains answer.
  • CallCommand::LegAddOffer carries a oneshot reply, and SipSessionHandle::add_offer_leg waits for it.
  • SipSession::handle_add_offer_leg reuses build_leg_config, create_leg, prepare_answer and commit_local_answer. It rejects a duplicate live leg ID and stops the peer on any failure.
  • docs/rwi.md and docs/rwi_zh.md document the request, the response and the leg ID rule below.

call.bridge pre-validation in command_dispatch.rs accepts only caller, callee, consult* or IDs of at least 32 hex characters. This already applies to dialed legs named like the attempt-b example in docs/rwi.md. The docs ask for such an ID rather than changing validation in this PR. Accepting any live leg there is a separate fix.

Tests:

  • rwi_leg_add_offer_answers_webrtc_and_bridges_to_caller checks the exclusivity error and the queued command. It checks the WebRTC answer for ICE credentials, a fingerprint, UDP/TLS/RTP/SAVPF and PCMU first for a PCMU caller. It then checks the connected state, the leg-scoped call_answered, duplicate refusal, the bridge and removal.
  • cargo test --lib -- rwi leg_add: 141 passed on main at b4f6b192 with this commit.
  • On the earlier pin 7224fcc9, the full cargo test --lib run passed 2444 tests. console::handlers::mfa::tests::mfa_disable_requires_matching_password failed because config/trunks/trunks.generated.toml was missing. That failure is environmental and unrelated.
  • scripts/check_test_sleeps.sh and regression/scripts/check_assertion_quality.py pass. cargo clippy --lib reports nothing on the changed lines.
  • An external WebRTC stack (str0m 0.25) joined a carrier call end to end in a Docker deployment. Tones went both ways with PCMU passthrough and with an Opus-only offer. ICE ran without TURN, and caller DTMF still raised dtmf events.

Merge likelihood

Medium-high, about 65–75 percent, if it is rebased onto main the day it is opened and stays one focused commit.

The evidence comes from GitHub PR history, read on 2026-11-18:

call.leg_add accepts an optional offer instead of a target. The session
creates the leg's media peer from the offer (ICE + DTLS selects the same
rustrtc WebRTC transport WebRTC SIP callers use), answers it, and the
command completes with data.answer. The leg is connected at once and joins
media only through call.bridge, so a controller can attach a browser or
WebRTC agent to any call without a SIP registration.

The answer prefers the caller's negotiated codec when offered, so the
bridge passes audio through, and otherwise follows the codec policy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant