eager-pager-29628
12/02/2025, 1:44 PMtall-airline-16756
12/02/2025, 1:44 PMtall-airline-16756
12/02/2025, 1:45 PMcreateSipParticipant returns when waitUntilAnswered: true.
When waitUntilAnswered is true, the call waits until the outbound call is answered before resolving. On success the function returns an SIPParticipantInfo object describing the created SIP participant, and the participant's sip.callStatus becomes active. If the call fails to connect or isn't answered within the ringing timeout (max 80 seconds), the request throws an error.
Example:
const participant = await sipClient.createSipParticipant(
trunkId,
phoneNumber,
roomName,
{ waitUntilAnswered: true }
);
console.log('Participant created:', participant); // runs only after answered
Would you like the exact shape of SIPParticipantInfo or example error handling code?
Sources: Make outbound calls | LiveKit docs | SIP APIs | LiveKit docseager-pager-29628
12/02/2025, 1:46 PMtall-airline-16756
12/02/2025, 1:47 PMcreateSipParticipant with waitUntilAnswered: true and returns HTTP 200 on success or other appropriate statuses on failure. It includes basic error classification you can expand.
Service (sipService.ts)
import { Request } from 'express';
// Replace these types with your SDK's actual types
type SIPParticipantInfo = any;
type SipClient = {
createSipParticipant: (
trunkId: string,
phoneNumber: string,
roomName: string,
opts?: { waitUntilAnswered?: boolean }
) => Promise<SIPParticipantInfo>;
};
export class SipService {
constructor(private sipClient: SipClient) {}
async createAndWait(
trunkId: string,
phoneNumber: string,
roomName: string
): Promise<{ ok: true; participant: SIPParticipantInfo } | { ok: false; code: number; message: string }> {
try {
const participant = await this.sipClient.createSipParticipant(trunkId, phoneNumber, roomName, {
waitUntilAnswered: true,
});
// At this point the call was answered and participant.sip.callStatus should be 'active'
return { ok: true, participant };
} catch (err: any) {
// Basic error classification — extend based on actual SDK errors
if (err?.code === 'CALL_FAILED' || err?.status === 488 || err?.status === 480) {
return { ok: false, code: 502, message: 'SIP call failed or unreachable' };
}
if (err?.message?.includes('timeout') || err?.status === 408) {
return { ok: false, code: 504, message: 'SIP call timed out (not answered)' };
}
// Fallback / unknown error
return { ok: false, code: 500, message: err?.message ?? 'Unknown error creating SIP participant' };
}
}
}
Controller (sipController.ts)
import { Request, Response } from 'express';
import { SipService } from './sipService';
export class SipController {
constructor(private sipService: SipService) {}
// POST /sip/call
async createCall(req: Request, res: Response) {
const { trunkId, phoneNumber, roomName } = req.body;
if (!trunkId || !phoneNumber || !roomName) {
return res.status(400).json({ error: 'trunkId, phoneNumber and roomName are required' });
}
const result = await this.sipService.createAndWait(trunkId, phoneNumber, roomName);
if (result.ok) {
// Successful answered call
return res.status(200).json({ participant: result.participant });
}
// Map service error.code to HTTP response
return res.status(result.code).json({ error: result.message });
}
}
Minimal Express wiring example
import express from 'express';
import { SipController } from './sipController';
import { SipService } from './sipService';
import someSdk from './sipSdkClient'; // initialize your sip client here
const app = express();
app.use(express.json());
const sipService = new SipService(someSdk);
const sipController = new SipController(sipService);
app.post('/sip/call', (req, res) => sipController.createCall(req, res));
app.listen(3000);
Notes you may want:
• Expand error mapping using the actual error shapes/codes from your SIP SDK.
• Add timeouts/cancellation handling if you want to abort long waits.
• Validate and sanitize phone numbers and inputs before calling the SDK.
• Log attempts and errors for troubleshooting.
Would you like this adapted to plain JavaScript or include concrete error codes from your SIP SDK?