Agents
Constructor
agent(name: string, config: map)
Returns Agent
Connect a headless baresip agent and return a handle.
Config options — agent(name, #{ … }):
| Field | Type | Description |
|---|---|---|
username | string · required | SIP user (registration / auth) |
domain | string · required | SIP domain / registrar |
password | string | auth password |
display_name | string | caller display name |
transport | string | udp (default), tcp or tls |
auth_user | string | auth user, if it differs from username |
outbound | string | outbound proxy URI |
stun_server | string | STUN server, e.g. stun:host:port |
media_enc | string | media encryption, e.g. srtp, zrtp, dtls_srtp |
regint | int | re-registration interval (seconds); 0 disables |
mwi | bool | subscribe to message-waiting indication |
dtmf_mode | string | "info" for reliable headless DTMF (SIP INFO) |
headers | map | extra SIP headers on the INVITE, e.g. #{ "X-Foo": "bar" } |
Example
#![allow(unused)]
fn main() {
let a = agent("A", #{
username: env("A_USER"),
domain: env("SIP_DOMAIN"),
password: env("A_PASS"),
});
}
Methods
agent.abort_transfer()
Receiver Agent
Abort the pending attended transfer.
agent.accept()
Receiver Agent
Answer the agent’s incoming call.
Example
#![allow(unused)]
fn main() {
await_until(|| assert(b.state).equals(State::Ringing), "15s");
b.accept();
}
agent.attended_transfer(target: Agent)
Start an attended transfer: place a consultation call to another agent.
Complete it with complete_transfer() once that call is established.
agent.attended_transfer(target: string)
Receiver Agent
Start an attended transfer to a literal URI or bare number.
agent.complete_transfer()
Receiver Agent
Complete the pending attended transfer (REFER with Replaces).
agent.dial(target: Agent)
Dial another agent at its AOR.
Example
#![allow(unused)]
fn main() {
a.dial(b); // dial agent B at its AOR
a.dial("+49301234567"); // …or a number/URI in A's domain
await_until(|| assert(b.state).equals(State::Ringing), "15s");
}
agent.dial(target: string)
Receiver Agent
Dial a literal SIP URI, or a bare number/extension in the agent’s own domain.
agent.dtmf(digits: string)
Receiver Agent
Send DTMF tones (characters 0-9, *, #, A-D) back-to-back.
Example
#![allow(unused)]
fn main() {
a.dtmf("123#");
}
agent.dtmf(digits: string, gap: string)
Receiver Agent
Send DTMF tones with a pause between digits, e.g. dtmf("123#", "200ms").
agent.hangup()
Receiver Agent
Hang up the agent’s active call.
Example
#![allow(unused)]
fn main() {
a.hangup();
await_until(|| assert(a.state).equals(State::Idle), "10s");
}
agent.header(name: string)
Receiver Agent · Returns any
Value of a header on a received INVITE (string), or () if absent.
agent.headers()
Receiver Agent · Returns map
All received INVITE headers as a map (name → value); duplicates collapse,
use header(name) for a specific one.
agent.hold()
Receiver Agent
Put the active call on hold.
agent.info()
Receiver Agent · Returns map
A map of the agent’s current state: name, aor, registered, state,
reason, status_code, calls. Handy to print(...) or assert on.
agent.mute()
Receiver Agent
Toggle mute on the active call.
Example
#![allow(unused)]
fn main() {
a.mute(); // mute; call again to unmute
}
agent.register()
Receiver Agent
(Re-)register the agent’s account.
Example
#![allow(unused)]
fn main() {
a.register();
await_until(|| assert(a.registered).is_true(), "10s");
}
agent.resume()
Receiver Agent
Resume a held call.
agent.send_audio(source: AudioSpec)
Receiver Agent · Takes AudioSpec
Switch the agent’s active-call audio source: tone(Hz), file(path) or silent().
Example
#![allow(unused)]
fn main() {
a.send_audio(tone(440)); // play a 440 Hz tone
a.send_audio(file("prompt.wav"));
}
agent.to_json()
Receiver Agent · Returns string
The agent’s current state as a JSON string (for log(...)/debugging).
agent.transfer(target: Agent)
Blind-transfer (REFER) the active call to another agent’s AOR.
Example
#![allow(unused)]
fn main() {
callee.transfer(target); // hand the caller off to `target`
}
agent.transfer(target: string)
Receiver Agent
Blind-transfer (REFER) the active call to a literal URI or bare number.
agent.verify_audio(freq: int, within: string)
Receiver Agent
Assert the agent is receiving a tone at freq Hz within the window (Goertzel).
Example
#![allow(unused)]
fn main() {
a.send_audio(tone(440));
b.verify_audio(440, "5s"); // b hears A's 440 Hz tone
}
agent.verify_audio_connection(b: Agent)
Assert two-way audio between two agents (a→b then b→a) at 1000 Hz.
Fields
agent.peer
The current call’s remote party (the caller for an incoming call); read
peer.uri / peer.number / peer.name (each () if there’s no call).
agent.reason
Receiver Agent · Returns any
The last closed call’s reason (string), or () if none yet.
agent.registered
Receiver Agent · Returns bool
Whether the agent’s account is currently registered.
agent.state
Receiver Agent · Returns CallState
The agent’s current call phase: Idle, Ringing or Established.
agent.status_code
Receiver Agent · Returns any
SIP status code from the last closed call’s reason (int, e.g. 603),
or () if the reason isn’t a SIP response (local hangup, reset, …).