The `drachtio-srf` package, currently at version 5.0.22, is a Node.js framework for building Signaling Resource Function (SRF) applications, primarily for SIP (Session Initiation Protocol) servers. It provides a high-level API for handling SIP signaling, allowing developers to create complex SIP applications such as proxies, Back-to-Back User Agents (B2BUAs), and custom routing logic. The framework abstracts much of the complexity of the SIP protocol, leveraging a network connection to a separate `drachtio-server` process which handles the underlying SIP transaction processing. It requires Node.js version 18.x or higher and ships with TypeScript types, facilitating modern JavaScript and TypeScript development for real-time communication services.
npm install drachtio-srfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic Back-to-Back User Agent (B2BUA) with `drachtio-srf`. It connects to a `drachtio-server`, listens for incoming SIP INVITEs, and attempts to establish a call to a specified URI, relaying media and signaling between the two call legs. It includes error handling and proper cleanup on call termination.
Ensure your `drachtio-server` process is running version 0.9.0 or later. Check the drachtio-server GitHub releases for the latest compatible version.
Modify headers like `From` and `To` to use placeholders:
```typescript
headers: {
'From': '<sip:user@placeholder>',
'To': '<sip:target@placeholder>'
}
```Always check the status code in the `response` event handler for INVITEs and call the `ack` function for 200 OK responses:
```typescript
srf.request('sip:target@domain.com', { method: 'INVITE', /* ... */ }, (err, req) => {
req.on('response', (res, ack) => {
if (res.status === 200) {
ack(); // Send the ACK for 200 OK
}
});
});
```Ensure the `drachtio-server` process is running and configured to listen on the host and port specified in `srf.connect()`. Verify network connectivity and firewall rules.
If your project uses ESM, ensure you use `import` statements. If your project is CommonJS and you need to load an ESM-only dependency, you may need to convert your project to ESM by adding `"type": "module"` to your `package.json` and adjusting imports/exports, or use dynamic `import()` for the specific module.
Examine the `status` code and `reason` phrase returned in the error object. This indicates a SIP protocol error (e.g., 404 Not Found, 486 Busy Here). Debug the SIP URI, headers, and routing logic. Use SIP trace tools to analyze the full SIP message flow.