Module sip

Module sip 

Source
Expand description

In-process SIP — answer raw SIP calls with no carrier service in the path.

(feature sip) Where super::twilio relies on a carrier service to terminate the phone network and hand audio over a WebSocket, this module terminates the call itself: SIP signalling via rsipstack (the stack underneath the rustpbx PBX), and G.711-over-RTP media built from this crate’s own pure layers (super::rtp, super::sdp, super::g711). Any SIP endpoint — a softphone, an Asterisk/FreeSWITCH PBX, a provider’s SIP trunk — dials the agent directly, and each call attaches to a Live session through the same voice::pump as every other audio surface.

// `ignore`: `SipAgent` needs the `sip` feature and a bound UDP socket.
let mut agent = SipAgent::bind("0.0.0.0:5060".parse()?).await?;
while let Some(incoming) = agent.next_call().await {
    let session = Live::builder()
        .instruction("Answer the phone politely.")
        .greeting("Greet the caller.")
        .connect_from_env().await?;
    let call = incoming.answer(&session).await?;
    tokio::spawn(async move { call.ended().await; });
}

RFC 4733 telephone events (DTMF) are negotiated in the SDP answer when the offer proposes them; keypresses land in session state under the shared super::bridge keys, where flow guards read them — identical to the Twilio path. What is deliberately not here yet: SIP registration (the agent is a directly-dialed UAS) and SRTP. Media is symmetric RTP: the agent sends to the offer’s address but re-latches onto the source of the first arriving packet, which keeps NATted softphones working.

Structs§

IncomingCall
A ringing inbound call: answer it onto a session, or reject it.
SipAgent
A SIP user agent server: binds a UDP SIP port and yields incoming calls.
SipCall
An answered SIP call with media flowing.

Enums§

SipError
Errors from the SIP agent.