1 | # drachtio-srf [![Build Status](https://secure.travis-ci.org/davehorton/drachtio-srf.png)](http://travis-ci.org/davehorton/drachtio-srf) [![NPM version](https://badge.fury.io/js/drachtio-srf.svg)](http://badge.fury.io/js/drachtio-srf)
|
2 |
|
3 | [![drachtio logo](http://davehorton.github.io/drachtio-srf/img/definition-only-cropped.png)](https://drachtio.org)
|
4 |
|
5 | Welcome to the Drachtio Signaling Resource framework (drachtio-srf), the Node.js framework for SIP Server applications.
|
6 |
|
7 | Please visit [drachtio.org](https://drachtio.org) for getting started instructions, API documentation, sample apps and more!
|
8 |
|
9 | *Example proxy*
|
10 | ```js
|
11 | const Srf = require('drachtio-srf');
|
12 | const srf = new Srf();
|
13 |
|
14 | srf.connect({
|
15 | host: '192.168.32.5',
|
16 | port: 9022,
|
17 | secret: 'cymru'
|
18 | }) ;
|
19 |
|
20 | srf.invite((req, res) => {
|
21 | srf.proxyRequest(req, ['sip.example1.com', 'sip.example2.com'], {
|
22 | recordRoute: true,
|
23 | followRedirects: true,
|
24 | provisionalTimeout: '2s'
|
25 | }).then((results) => {
|
26 | console.log(JSON.stringify(result));
|
27 | // {finalStatus: 200, finalResponse:{..}, responses: [..]}
|
28 | });
|
29 | });
|
30 | ```
|
31 | *Example Back-to-back user agent*
|
32 | ```js
|
33 | const Srf = require('drachtio-srf');
|
34 | const srf = new Srf();
|
35 |
|
36 | srf.connect({
|
37 | host: '192.168.32.5',
|
38 | port: 9022,
|
39 | secret: 'cymru'
|
40 | }) ;
|
41 | const Srf = require('drachtio-srf');
|
42 | const srf = new Srf();
|
43 |
|
44 | srf.invite((req, res) => {
|
45 | srf.createB2BUA('sip:1234@10.10.100.1', req, res, {localSdpB: req.body})
|
46 | .then(({uas, uac}) => {
|
47 | console.log('call connected');
|
48 |
|
49 | // when one side terminates, hang up the other
|
50 | uas.on('destroy', () => { uac.destroy(); });
|
51 | uac.on('destroy', () => { uas.destroy(); });
|
52 | return;
|
53 | })
|
54 | .catch((err) => {
|
55 | console.log(`call failed to connect: ${err}`);
|
56 | });
|
57 | });
|
58 | ```
|
59 | *Example sending a request (OPTIONS ping)*
|
60 | ```js
|
61 | const Srf = require('drachtio-srf');
|
62 | const srf = new Srf();
|
63 |
|
64 | srf.connect({host: '127.0.0.1', port: 9022, secret: 'cymru'});
|
65 |
|
66 | srf.on('connect', (err, hp) => {
|
67 | if (err) return console.log(`Error connecting: ${err}`);
|
68 | console.log(`connected to server listening on ${hp}`);
|
69 |
|
70 | setInterval(optionsPing, 10000);
|
71 | });
|
72 |
|
73 | function optionsPing() {
|
74 | srf.request('sip:tighthead.drachtio.org', {
|
75 | method: 'OPTIONS',
|
76 | headers: {
|
77 | 'Subject': 'OPTIONS Ping'
|
78 | }
|
79 | }, (err, req) => {
|
80 | if (err) return console.log(`Error sending OPTIONS: ${err}`);
|
81 | req.on('response', (res) => {
|
82 | console.log(`Response to OPTIONS ping: ${res.status}`);
|
83 | });
|
84 | });
|
85 | }
|
86 | ```
|
87 |
|
\ | No newline at end of file |