Skip to main content

WebSocket API

Connect to RustPBX

RustPBX uses WebSocket connections

Address

The listening address of RustPBX is configured in RustPBX's config.toml:

config.toml
http_addr = "0.0.0.0:8080"

Paths

Different paths correspond to different voice call types:

  • /call: Audio stream transmitted via WebSocket
  • /call/sip: Audio stream transmitted via SIP/RTP
  • /call/webrtc: Audio stream transmitted via WebRTC RTP

Parameters

  • id (optional, string): Session ID. Defaults to server-generated UUID. (Should be set to dialogId when answering)
  • dump (optional, bool, default: true): Whether to enable dump
  • pingInterval (optional, int, unit: seconds, default: 20): WebSocket Ping interval. When enabled, will periodically receive SessionEvent::Ping events
  • serverSideTrack (optional, string, default: serverSideTrack): Set server-side TrackID

Example

  • ws://localhost:8080/call/sip?id=session123&dump=true

Commands

Commands are sent over the WebSocket connection as JSON messages, with the command field indicating the command type.

Invite - Initiate Call

Purpose: Initiate a new call.

info
  • SIP calls require setting option.caller and option.callee to the caller and callee SIP addresses respectively
  • WebRTC calls require setting option.offer to the call's SDP offer

Example:

{
"command": "invite",
"option": {
"denoise": true,
"callee": "sip:alice@192.168.3.197:12345",
"caller": "sip:192.168.3.197:3050",
"vad": {
"type": "silero",
"silenceTimeout": 5000
},
"asr": {
"provider": "tencent"
},
"tts": {
"provider": "tencent",
"speaker": "601003"
},
"sip": {}
}
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "invite"
optionCallOptionCall configuration parameters, see CallOption for details

Accept - Answer Incoming Call

Purpose: Answer an incoming call.

info

Answering calls requires setting the id parameter in the connection URL to dialogId, which is provided by the webhook request. See:

Example:

{
"command": "accept",
"option": {
"denoise": true,
"vad": {
"type": "silero",
"silenceTimeout": 5000
},
"asr": {
"provider": "tencent"
},
"tts": {
"provider": "tencent",
"speaker": "601003"
}
}
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "accept"
optionCallOptionCall configuration parameters, see CallOption for details

Reject - Reject Incoming Call

Purpose: Reject an incoming call.

info

Request failure response code list: Request Failure 4xx

Example:

{
"command": "reject",
"reason": "Busy Here",
"code": 486
}

Parameters:

FieldTypeRequiredDefaultDescription
commandstring-Must be "reject"
reasonstring-Rejection reason
codenumber-SIP response code

Ringing - Ringing

Purpose: Send ringing response for incoming call. (180 Ringing)

Note

If recorder is set in the Ringing command, the recorder option in subsequent Accept commands will not override the recording settings during the ringing phase.

Example:

{
"command": "ringing",
"recorder": {
"recorderFile": "/path/to/recording.wav",
"samplerate": 16000,
"ptime": 200
},
"earlyMedia": true,
"ringtone": "http://example.com/ringtone.wav"
}

Parameters:

FieldTypeRequiredDefaultDescription
commandstring-Must be "ringing"
recorderRecorderOption-Call recording configuration
earlyMediabooleanfalseEnable early media during ringing
ringtonestring-Custom ringtone URL

TTS - Text-to-Speech

Purpose: Convert text to speech and play audio.

Example:

{
"command": "tts",
"text": "Hello, this is a test message",
"speaker": "xiaoyan",
"playId": "unique_play_id",
"autoHangup": false,
"streaming": false,
"endOfStream": false,
"waitInputTimeout": 30,
"option": {
"provider": "tencent",
"volume": 5,
"speed": 1.0
}
}

Parameters:

FieldTypeRequiredDefaultDescription
commandstring-Must be "tts"
textstring-Text to synthesize
speakerstring-Voice type, see provider voice lists
playIdstring-TTS Track identifier.
autoHangupbooleanfalseWhether to automatically hang up after TTS playback completes
streamingbooleanfalseWhether to enable streaming TTS
endOfStreambooleanfalseWhether this is the last command for the current playId
waitInputTimeoutnumber-Maximum time to wait for user input, unit: seconds
optionSynthesisOption-TTS provider-specific options, can configure voice format, sample rate, etc.
base64booleanfalseWhether to use base64 encoding
tip
  • When streaming TTS is enabled, TTS commands will be sent in the same WebSocket connection.
  • Set endOfStream = true when all TTS commands for the playId have been sent. The TTS Track will exit after all command results finish playing and send a Track End event.
  • Set base64=true to pass base64-encoded PCM audio through the text field.
  • If playId is set, the Track End event sent by this TTS Track will include this playId.
  • If the current playId is the same as a previous TTS command's playId, it will reuse the previous TTS Track; otherwise, it will terminate the previous TTS Track and create a new TTS Track.

For details, see TTS(Text-to-Speech)

Play - Play Audio

Purpose: Play audio from URL.

Example:

{
"command": "play",
"url": "http://example.com/audio.mp3",
"autoHangup": false,
"waitInputTimeout": 30
}

Parameters:

FieldTypeRequiredDefaultDescription
commandstring-Must be "play"
urlstring-Audio file URL to play (supports HTTP/HTTPS). This URL will be returned as playId in the trackEnd event
autoHangupbooleanfalseIf true, will automatically hang up after playback completes
waitInputTimeoutnumber-Maximum time to wait for user input, unit: seconds

Interrupt - Interrupt Playback

Purpose: Interrupt current TTS or audio playback.

info
  • If the current TTS result has not finished playing, an Interruption event will be triggered, containing the played time and the time when audio was received from the TTS provider. If the provider supports subtitles, it will also include the estimated position of the played text.
  • If graceful = true is set, it will wait for the current TTS command result to finish playing before exiting, see Interruption.

Example:

{
"command": "interrupt",
"graceful": false
}

Parameters:

FieldTypeRequiredDefaultDescription
commandstring-Must be "interrupt"
gracefulbooleanfalseWhether to gracefully interrupt

Refer - Transfer Call

Purpose: Transfer call to another party (SIP REFER).

Example:

{
"command": "refer",
"caller": "sip:alice@example.com",
"callee": "sip:charlie@example.com",
"options": {
"denoise": true,
"timeout": 30,
"moh": "http://example.com/hold_music.wav",
"autoHangup": true
}
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "refer"
callerstringTransfer caller SIP address (currently connected local SIP address, e.g.: sip:{localIP}:13050)
calleestringTransfer target SIP URI (e.g., sip:bob@example.com)
optionsReferOptionTransfer configuration, see ReferOption for details

Mute - Mute

Purpose: Mute all or specified Tracks.

info

If trackId is specified, mute the corresponding Track; otherwise, mute all Tracks.

Example:

{
"command": "mute",
"trackId": "track-123"
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "mute"
trackIdstringTrack ID to mute (if not specified, mute all tracks)

Unmute - Unmute

Purpose: Unmute muted Tracks.

info

If trackId is specified, unmute the corresponding Track; otherwise, unmute all Tracks.

Example:

{
"command": "unmute",
"trackId": "track-123"
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "unmute"
trackIdstringTrack ID to unmute (if not specified, unmute all tracks)

Hangup - Hangup

Purpose: End the call.

Example:

{
"command": "hangup",
"reason": "user_requested",
"initiator": "user"
}

Parameters:

FieldTypeRequiredDescription
commandstringMust be "hangup"
reasonstringHangup reason
initiatorstringParty that initiated the hangup (user, system, etc.)

Events

Events are received from the server in JSON format. All timestamps are in milliseconds. Each event contains an event field indicating the event type, and most events also include a trackId field indicating the related Track.

Incoming - Incoming Call Event

Trigger: When an incoming call is received (SIP calls only).

Example:

{
"event": "incoming",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"caller": "sip:alice@example.com",
"callee": "sip:bob@example.com",
"sdp": "v=0\r\no=- 1234567890 2 IN IP4 127.0.0.1\r\n..."
}

Fields:

FieldTypeDescription
eventstringAlways "incoming"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
callerstringCaller's SIP address
calleestringCallee's SIP address
sdpstringSDP offer from the caller

Answer - Answer Event

Trigger: When the call is answered and SDP negotiation is complete.

info

For SIP calls, the Answer event is triggered when 200 OK is received.

Example:

{
"event": "answer",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"sdp": "v=0\r\no=- 1234567890 2 IN IP4 127.0.0.1\r\n..."
}

Fields:

FieldTypeDescription
eventstringAlways "answer"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
sdpstringSDP answer from the callee

Reject - Reject Event

Trigger: When the call is rejected.

Example:

{
"event": "reject",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"reason": "Busy",
"code": 486
}

Fields:

FieldTypeDescription
eventstringAlways "reject"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
reasonstringRejection reason
codenumberSIP response code (optional)
info

Request failure response code list: Request Failure 4xx

Ringing - Ringing Event

Trigger: When the call is ringing (SIP calls only).

Example:

{
"event": "ringing",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"earlyMedia": false
}

Fields:

FieldTypeDescription
eventstringAlways "ringing"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
earlyMediabooleanWhether early media is available

Hangup - Hangup Event

Trigger: When the call ends.

Example:

{
"event": "hangup",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"reason": "user_requested",
"initiator": "user",
"startTime": "2024-01-01T12:00:00Z",
"hangupTime": "2024-01-01T12:05:30Z",
"answerTime": "2024-01-01T12:00:05Z",
"from": {
"username": "alice",
"realm": "example.com",
"source": "sip:alice@example.com"
}
}

Fields:

FieldTypeDescription
eventstringAlways "hangup"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
reasonstringHangup reason (optional)
initiatorstringParty that initiated the hangup (optional)
startTimestringISO 8601 timestamp of call start
hangupTimestringISO 8601 timestamp of call end
answerTimestringISO 8601 timestamp of call answer (optional)
ringingTimestringISO 8601 timestamp of call ringing start (optional)
fromAttendeeCaller information (optional)
toAttendeeCallee information (optional)
extraobjectAdditional call metadata (optional)

Speaking - Speaking Event

Trigger: When VAD detects speech. Call Option must configure VAD

Example:

{
"event": "speaking",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"startTime": 1640995200000
}

Fields:

FieldTypeDescription
eventstringAlways "speaking"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
startTimenumberTime when speech started (milliseconds)

Silence - Silence Event

Trigger: When more than speechPadding milliseconds have passed since the current speech started, and more than silencePadding milliseconds have passed since the last Silence event was triggered (if any). Call Option must configure VAD.

Example:

{
"event": "silence",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"startTime": 1640995195000,
"duration": 5000
}

Fields:

FieldTypeDescription
eventstringAlways "silence"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
startTimenumberTime when silence started (milliseconds)
durationnumberSilence duration (milliseconds)

AsrFinal - ASR Final Event

Trigger: Stable result of speech recognition.

Example:

{
"event": "asrFinal",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"index": 1,
"startTime": 1640995200000,
"endTime": 1640995205000,
"text": "Hello, how can I help you today?"
}

Fields:

FieldTypeDescription
eventstringAlways "asrFinal"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
indexnumberASR result sequence number
startTimenumberSpeech start time (milliseconds, optional)
endTimenumberSpeech end time (milliseconds, optional)
textstringSpeech recognition result

AsrDelta - ASR Delta Event

Trigger: Intermediate result of speech recognition (may change).

Example:

{
"event": "asrDelta",
"trackId": "track-abc123",
"index": 1,
"timestamp": 1640995200000,
"text": "Hello, how can"
}

Fields:

FieldTypeDescription
eventstringAlways "asrDelta"
trackIdstringUnique identifier of the Track
indexnumberASR result sequence number
timestampnumberEvent timestamp (milliseconds)
startTimenumberSpeech start time (milliseconds, optional)
endTimenumberSpeech end time (milliseconds, optional)
textstringSpeech recognition result (may change)

TrackStart - Track Start Event

Trigger: When a Track starts (RTP, TTS, file playback, etc.).

Example:

{
"event": "trackStart",
"trackId": "track-tts-456",
"timestamp": 1640995200000,
"playId": "llm-001"
}

Fields:

FieldTypeDescription
eventstringAlways "trackStart"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
playIdstringTTS command's playId (optional) or Play command's URL (optional)
info

Both TTS and Play commands create corresponding Tracks. The playId in TrackStart is:

  • TTS Track: TTS command's playId (optional)
  • Play Track: Play command's URL

TrackEnd - Track End Event

Trigger: When a Track ends (RTP ends, TTS completes, file playback completes, etc.).

Example:

{
"event": "trackEnd",
"trackId": "track-tts-456",
"timestamp": 1640995230000,
"duration": 30000,
"ssrc": 1234567890,
"playId": "llm-001"
}

Fields:

FieldTypeDescription
eventstringAlways "trackEnd"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
durationnumberTrack duration (milliseconds)
ssrcnumberRTP synchronization source identifier
playIdstringTTS command's playId (optional) or Play command's URL (optional)
info

Both TTS and Play commands create corresponding Tracks. The playId in TrackEnd is:

  • TTS Track: TTS command's playId (optional)
  • Play Track: Play command's URL

Interruption - Interruption Event

Trigger: When an Interrupt command is received and there are unfinished TTS commands.

Example:

{
"event": "interruption",
"trackId": "track-tts-456",
"timestamp": 1640995215000,
"playId": "llm-001",
"subtitle": "Hello, this is a long message that was interrupted",
"position": 5,
"totalDuration": 30000,
"current": 15000
}

Fields:

FieldTypeDescription
eventstringAlways "interruption"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
playIdstringFor TTS commands, this is the playId from the TTS command (optional)
subtitlestringCurrent TTS text being played at interruption (optional)
positionnumberWord index position in subtitle at interruption (optional)
totalDurationnumberTotal duration of TTS content (milliseconds)
currentnumberTime elapsed since TTS start at interruption (milliseconds)

Dtmf - DTMF Event

Trigger: When a keypress is detected.

Example:

{
"event": "dtmf",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"digit": "1"
}

Fields:

FieldTypeDescription
eventstringAlways "dtmf"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
digitstringDTMF digit (0-9, *, #, A-D)

Metrics - Metrics Event

Trigger: When performance metrics are available.

Example:

{
"event": "metrics",
"timestamp": 1640995200000,
"key": "ttfb.asr.tencent",
"duration": 150,
"data": {
"index": 1,
"provider": "tencent"
}
}

Fields:

FieldTypeDescription
eventstringAlways "metrics"
timestampnumberEvent timestamp (milliseconds)
keystringMetric key (e.g., "ttfb.asr.tencent")
durationnumberDuration (milliseconds)
dataobjectAdditional metric data

Error - Error Event

Trigger: When an error occurs during processing.

Example:

{
"event": "error",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"sender": "asr",
"error": "Connection timeout to ASR service",
"code": 408
}

Fields:

FieldTypeDescription
eventstringAlways "error"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
senderstringComponent that generated the error (asr, tts, media, etc.)
errorstringError message description
codenumberError code (optional)

Binary - Binary Event

Trigger: When binary audio data is sent (WebSocket calls only).

Example:

{
"event": "binary",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"data": []
}

Fields:

FieldTypeDescription
eventstringAlways "binary"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
dataarrayBinary audio data bytes

Ping - Ping Event

Trigger: When periodic Ping messages are sent (if the pingInterval parameter is set in the connection URL), see Connect to RustPBX.

Example:

{
"event": "ping",
"timestamp": 1640995200000,
"payload": "optional_payload"
}

Fields:

FieldTypeDescription
eventstringAlways "ping"
timestampnumberEvent timestamp (milliseconds)
payloadstringOptional payload data (optional)

Other - Other Event

Trigger: When custom or extended events are generated.

Example:

{
"event": "other",
"trackId": "track-abc123",
"timestamp": 1640995200000,
"sender": "custom_plugin",
"extra": {
"custom_field": "custom_value"
}
}

Fields:

FieldTypeDescription
eventstringAlways "other"
trackIdstringUnique identifier of the Track
timestampnumberEvent timestamp (milliseconds)
senderstringComponent that generated the event
extraobjectAdditional event data (optional)

Options

CallOption

The CallOption object is used in Invite and Accept commands, containing call configuration.

Example:

{
"denoise": true,
"offer": "SDP offer string",
"callee": "sip:callee@example.com",
"caller": "sip:caller@example.com",
"codec": "g722",
"recorder": {
"recorderFile": "/path/to/recording.wav",
"samplerate": 16000
},
"asr": {
"provider": "tencent",
"language": "zh-CN"
},
"tts": {
"provider": "tencent",
"speaker": "xiaoyan"
}
}

Fields:

FieldTypeRequiredDefaultDescription
denoisebooleanfalseEnable audio processing noise reduction
offerstring-SDP offer string for WebRTC/SIP negotiation
calleestring-Callee's SIP URI or phone number (e.g., "sip:bob@example.com")
callerstring-Caller's SIP URI or phone number (e.g., "sip:alice@example.com")
codecstring"pcmu"Audio codec: "pcmu", "pcma", "g722", "pcm" (only for WebSocket calls)
recorderRecorderOption-Call recording configuration
vadVADOption-Voice activity detection configuration
asrTranscriptionOption-Automatic Speech Recognition (ASR) configuration
ttsSynthesisOption-Text-to-Speech configuration
mediaPassMediaPassOption-Media Pass configuration
handshakeTimeoutstring-Connection handshake timeout (e.g., "30s")
enableIpv6booleanfalseEnable IPv6 support
sipSipOption-SIP registration account, password, and domain configuration
extraobject-Additional parameters

RecorderOption

Call recording configuration options.

Example:

{
"recorderFile": "/path/to/recording.wav",
"samplerate": 16000,
"ptime": 200
}

Fields:

FieldTypeRequiredDefaultDescription
recorderFilestring-Recording file path
sampleratenumber16000Recording sample rate, unit: Hz
ptimenumber200Packet time, unit: milliseconds

TranscriptionOption

Automatic Speech Recognition (ASR) configuration options.

Example:

{
"provider": "tencent",
"language": "zh-CN",
"appId": "app_id",
"secretId": "your_secret_id",
"secretKey": "your_secret_key",
"modelType": "16k_zh",
"samplerate": 16000,
"startWhenAnswer": true
}

Fields:

FieldTypeRequiredDefaultDescription
providerstring-ASR provider: tencent, aliyun, Deepgram, etc.
languagestring-Language (e.g., "zh-CN", "en-US") (see corresponding provider documentation for details)
appIdstring-Tencent Cloud's appId
secretIdstring-Tencent Cloud's secretId
secretKeystring-Tencent Cloud's secretKey, or other provider's API Key
modelTypestring-ASR model type (e.g., "16k_zh", "8k_en"), see provider documentation for details
bufferSizenumber-Audio buffer size, unit: bytes
sampleratenumber16000Sample rate
endpointstring-Custom service endpoint URL
extraobject-Provider-specific parameters
startWhenAnswerbooleanfalseRequest ASR service after call is answered

SynthesisOption

Text-to-Speech (TTS) configuration options.

Example:

{
"provider": "tencent",
"speaker": "xiaoyan",
"volume": 5,
"speed": 1.0,
"emotion": "neutral",
"samplerate": 16000
}

Fields:

FieldTypeRequiredDefaultDescription
providerstring-TTS provider: "tencent", "aliyun", "deepgram", "voiceapi"
speakerstring-Voice, see provider documentation
volumenumber5Volume (1-10)
speednumber1.0Speech rate
sampleratenumber16000Sample rate, unit: hz
appIdstring-Tencent Cloud's appId
secretIdstring-Tencent Cloud's secretId
secretKeystring-Tencent Cloud's secretKey, or other provider's API Key
codecstring-Encoding format
subtitlebooleanfalseWhether to enable subtitles
endpointstring-Custom TTS service endpoint URL
extraobject-Additional provider-specific parameters
maxConcurrentTasksnumber-Maximum concurrent tasks for non-streaming TTS commands, default is 1

VADOption

Voice Activity Detection (VAD) configuration options.

Example:

{
"type": "webrtc",
"samplerate": 16000,
"speechPadding": 250,
"silencePadding": 100,
"voiceThreshold": 0.5,
"maxBufferDurationSecs": 50
}

Fields:

FieldTypeRequiredDefaultDescription
typestring"webrtc"VAD algorithm type: "silero" , "ten" , "webrtc"
sampleratenumber16000Sample rate
speechPaddingnumber250Start detection speechPadding milliseconds after speech starts
silencePaddingnumber100Silence event trigger interval, unit: milliseconds
rationumber0.5Speech detection ratio threshold
voiceThresholdnumber0.5Voice energy threshold
maxBufferDurationSecsnumber50Maximum buffer duration, unit: seconds
silenceTimeoutnumber-Silence detection timeout, unit: milliseconds
endpointstring-Custom VAD service endpoint
secretKeystring-VAD service authentication key
secretIdstring-VAD service authentication ID

MediaPassOption

Media pass-through configuration options, using WebSocket service to completely take over audio processing.

RustPBX will send all audio data to the configured WebSocket service and play audio received from that service to the other party of the audio connection.

See: Media Pass

Example:

{
"url": "ws://localhost:9090/media",
"inputSampleRate": 16000,
"outputSampleRate": 16000,
"packetSize": 2560
}

Fields:

FieldTypeRequiredDefaultDescription
urlstring-WebSocket connection URL for media stream
inputSampleRatenumber-Audio sample rate received from WebSocket server (also the track's sample rate)
outputSampleRatenumber-Audio sample rate sent to WebSocket server
packetSizenumber2560Packet size sent to WebSocket server, unit: bytes

ReferOption

Transfer configuration options.

Example:

{
"denoise": true,
"timeout": 30,
"moh": "http://example.com/hold_music.wav",
"asr": {
"provider": "tencent",
"language": "zh-CN"
},
"autoHangup": true,
"sip": {
"username": "transfer_user",
"password": "transfer_password"
}
}

Fields:

FieldTypeRequiredDefaultDescription
denoisebooleanfalseEnable noise reduction during transfer
timeoutnumber-Transfer timeout, unit: seconds
mohstring-Hold music URL to play during transfer
asrTranscriptionOption-Automatic speech recognition configuration
autoHangupbooleanfalseAutomatically hang up after transfer completes
sipSipOption-SIP configuration

SipOption

SIP protocol configuration options.

Example:

{
"username": "user",
"password": "password",
"realm": "example.com",
"headers": {
"X-Custom-Header": "value"
}
}

Fields:

FieldTypeRequiredDefaultDescription
usernamestring-SIP username for authentication
passwordstring-SIP password for authentication
realmstring-SIP domain/realm for authentication
headersobject-Additional SIP protocol headers (key-value pairs)

Attendee

Call participant information.

Example:

{
"username": "alice",
"realm": "example.com",
"source": "sip:alice@example.com"
}

Fields:

FieldTypeDescription
usernamestringUsername part of SIP URI
realmstringDomain/realm part of SIP URI
sourcestringComplete SIP URI or phone number

REST API Endpoints

List Active Calls

Endpoint: GET /call/lists

Description: Returns a list of active calls.

Response:

{
"calls": [
{
"id": "session-id",
"call_type": "webrtc",
"created_at": "2024-01-01T12:00:00Z",
"option": {
"caller": "1234567890",
"callee": "0987654321"
}
}
]
}

Usage:

curl http://localhost:8080/call/lists

Terminate Call

Endpoint: POST /call/kill/{id}

Description: Terminate a specific active call.

Parameters:

  • id (path parameter, string): Session ID of the call to terminate

Response:

true

Usage:

curl -X POST http://localhost:8080/call/kill/session123

Get ICE Servers

Endpoint: GET /iceservers

Description: Returns ICE server configuration for WebRTC connections.

Response:

[
{
"urls": ["stun:restsend.com:3478"],
"username": null,
"credential": null
},
{
"urls": ["turn:restsend.com:3478"],
"username": "username",
"credential": "password"
}
]

Usage:

curl http://localhost:8080/iceservers

Error Handling

All endpoints return appropriate HTTP status codes:

  • 200 OK: Success
  • 400 Bad Request: Invalid parameters
  • 404 Not Found: Resource not found
  • 500 Internal Server Error: Server error

Notes

  • All WebSocket endpoints support real-time bidirectional communication
  • When WebSocket connection closes, call sessions are automatically cleaned up
  • Event dumping can be disabled by setting the dump=false parameter
  • ICE servers are automatically configured based on environment variables
  • Audio codecs are automatically negotiated based on functionality
  • VAD (Voice Activity Detection) events are used for speech detection
  • ASR (Automatic Speech Recognition) provides real-time transcription
  • TTS (Text-to-Speech) supports streaming synthesis
  • All timestamps are in milliseconds
  • trackId is used to identify which Track generated the event
  • playId prevents interrupting previous TTS playback when using the same ID. For TTS commands, playId is the specified identifier; for Play commands, playId is the URL
  • autoHangup automatically ends the call after TTS/Play completes