sip-lab 1.12.1 → 1.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +1 -1
- package/samples/send_and_receive_fax.js +7 -7
- package/samples/simple.js +72 -33
package/README.md
CHANGED
|
@@ -35,6 +35,10 @@ Then install sip-lab by doing:
|
|
|
35
35
|
npm install sip-lab
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
Be patient because we will need to download pjproject and build it.
|
|
39
|
+
|
|
40
|
+
We will also download rapidjson.
|
|
41
|
+
|
|
38
42
|
To test from within this repo just build and install by doing:
|
|
39
43
|
```
|
|
40
44
|
npm install -g node-gyp
|
|
@@ -44,6 +48,8 @@ And run some sample script from subfolder samples:
|
|
|
44
48
|
```
|
|
45
49
|
node samples/simple.js
|
|
46
50
|
```
|
|
51
|
+
The above script has detailed comments.
|
|
52
|
+
Please read it to undestand how to write your own test scripts.
|
|
47
53
|
|
|
48
54
|
The module is known to work properly in Ubuntu 18.04.4, Ubuntu 20.04.4, Debian 8 and Debian 10 (and it is expected to work in Debian 9).
|
|
49
55
|
It was originally developed with node v.10 and tested with v.12 and v16.13.1 and it is expected to work with latest versions of node.
|
|
@@ -65,4 +71,9 @@ But if you do so, you will need to set NODE_PATH for node to find it by doing:
|
|
|
65
71
|
export NODE_PATH=$(npm root --quiet -g)
|
|
66
72
|
```
|
|
67
73
|
|
|
74
|
+
### About the code
|
|
75
|
+
|
|
76
|
+
Although the code in written in *.cpp/*.hpp named files, this is not actually a C++ project.
|
|
77
|
+
|
|
78
|
+
It is mostly written in C using some C++ facilities.
|
|
68
79
|
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ async function test() {
|
|
|
21
21
|
console.log("t1", t1)
|
|
22
22
|
console.log("t2", t2)
|
|
23
23
|
|
|
24
|
-
oc = sip.call.create(t1.id, {from_uri: 'sip:
|
|
24
|
+
oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
|
|
25
25
|
|
|
26
26
|
await z.wait([
|
|
27
27
|
{
|
|
@@ -37,9 +37,9 @@ async function test() {
|
|
|
37
37
|
$rr: 'Trying',
|
|
38
38
|
'$(hdrcnt(via))': 1,
|
|
39
39
|
'$hdr(call-id)': m.collect('sip_call_id'),
|
|
40
|
-
$fU: '
|
|
41
|
-
$fd: '
|
|
42
|
-
$tU: '
|
|
40
|
+
$fU: 'alice',
|
|
41
|
+
$fd: 'test.com',
|
|
42
|
+
$tU: 'bob',
|
|
43
43
|
'$hdr(l)': '0',
|
|
44
44
|
}),
|
|
45
45
|
},
|
|
@@ -75,9 +75,9 @@ async function test() {
|
|
|
75
75
|
$rs: '200',
|
|
76
76
|
$rr: 'OK',
|
|
77
77
|
'$(hdrcnt(VIA))': 1,
|
|
78
|
-
$fU: '
|
|
79
|
-
$fd: '
|
|
80
|
-
$tU: '
|
|
78
|
+
$fU: 'alice',
|
|
79
|
+
$fd: 'test.com',
|
|
80
|
+
$tU: 'bob',
|
|
81
81
|
'$hdr(content-type)': 'application/sdp',
|
|
82
82
|
$rb: '!{_}a=sendrecv',
|
|
83
83
|
}),
|
package/samples/simple.js
CHANGED
|
@@ -1,32 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// This test creates 2 UDP SIP endpoints, makes a call between them and disconeects.
|
|
2
|
+
|
|
3
|
+
const sip = require ('../index.js')
|
|
4
|
+
const Zester = require('zester')
|
|
5
|
+
const m = require('data-matching')
|
|
6
|
+
const sip_msg = require('sip-matching')
|
|
7
|
+
|
|
8
|
+
// here we create our Zester instance
|
|
3
9
|
var z = new Zester()
|
|
4
|
-
var m = require('data-matching')
|
|
5
|
-
var sip_msg = require('sip-matching')
|
|
6
10
|
|
|
7
|
-
async function test() {
|
|
8
|
-
//sip.set_log_level(6)
|
|
9
|
-
sip.dtmf_aggregation_on(500)
|
|
10
11
|
|
|
12
|
+
async function test() {
|
|
13
|
+
// here we set our zester instance to trap events generated by sip-lab event_source
|
|
11
14
|
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
12
15
|
var e = evt.args[0]
|
|
13
16
|
return e
|
|
14
17
|
})
|
|
15
18
|
|
|
19
|
+
// here we start sip-lab
|
|
16
20
|
console.log(sip.start((data) => { console.log(data)} ))
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
// Here we create the SIP endpoints (transports).
|
|
23
|
+
// Since we don't specify the port, an available port will be allocated.
|
|
24
|
+
// Since we don't specify the type ('udp' or 'tcp' or 'tls'), 'udp' will be used by default.
|
|
25
|
+
const t1 = sip.transport.create({address: "127.0.0.1"})
|
|
26
|
+
const t2 = sip.transport.create({address: "127.0.0.1"})
|
|
20
27
|
|
|
28
|
+
// here we just print the transports
|
|
21
29
|
console.log("t1", t1)
|
|
22
30
|
console.log("t2", t2)
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
// make the call from t1 to t2
|
|
33
|
+
const oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
|
|
25
34
|
|
|
35
|
+
// Here we will wait for the call to arrive at t2
|
|
36
|
+
// We will also get a '100 Trying' that is sent by sip-lab automatically
|
|
37
|
+
// We will wait for at most 1000ms. If all events don't arrive within 1000ms, an exception will be thrown and the test will fail due to timeout.
|
|
26
38
|
await z.wait([
|
|
27
39
|
{
|
|
28
40
|
event: "incoming_call",
|
|
29
41
|
call_id: m.collect("call_id"),
|
|
42
|
+
transport_id: t2.id,
|
|
30
43
|
},
|
|
31
44
|
{
|
|
32
45
|
event: 'response',
|
|
@@ -44,29 +57,39 @@ async function test() {
|
|
|
44
57
|
}),
|
|
45
58
|
},
|
|
46
59
|
], 1000)
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
// Details about zester wait(list_of_events_to_wait_for, timeout_in_ms):
|
|
61
|
+
// The order of events in the list is irrelevant.
|
|
62
|
+
// What matters is that all events arrive within the specified timeout.
|
|
63
|
+
// When specifying events, you can be as detailed or succinct as you need.
|
|
64
|
+
// For example, the above event 'response' is waiting for a SIP '100 Trying' to arrive,
|
|
65
|
+
// but we are specifying things to match just to show that we can be very detailed when performing a match.
|
|
66
|
+
// But it could have been just like this:
|
|
67
|
+
//
|
|
68
|
+
// {
|
|
69
|
+
// event: 'response',
|
|
70
|
+
// call_id: oc.id,
|
|
71
|
+
// method: 'INVITE',
|
|
72
|
+
// msg: sip_msg({
|
|
73
|
+
// $rs: '100',
|
|
74
|
+
// }),
|
|
75
|
+
// }
|
|
76
|
+
// Regarding the function sip_msg() this is a special matching function provided by https://github.com/MayamaTakeshi/sip-matching that makes it
|
|
77
|
+
// easy to match a SIP message using openser/kamailio/opensips pseudo-variables syntax.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// Here we store data for the incoming call
|
|
81
|
+
// just to organize our code (not really needed)
|
|
82
|
+
const ic = {
|
|
49
83
|
id: z.store.call_id,
|
|
50
84
|
sip_call_id: z.store.sip_call_id,
|
|
51
85
|
}
|
|
52
86
|
|
|
87
|
+
// Now we answer the call at t2 side
|
|
53
88
|
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
54
89
|
|
|
90
|
+
// Then we wait for the '200 OK' at the t1 side
|
|
91
|
+
// We will also get event 'media_status' for both sides indicating media streams (RTP) were set up successfully
|
|
55
92
|
await z.wait([
|
|
56
|
-
{
|
|
57
|
-
event: 'media_status',
|
|
58
|
-
call_id: oc.id,
|
|
59
|
-
status: 'setup_ok',
|
|
60
|
-
local_mode: 'sendrecv',
|
|
61
|
-
remote_mode: 'sendrecv',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
event: 'media_status',
|
|
65
|
-
call_id: ic.id,
|
|
66
|
-
status: 'setup_ok',
|
|
67
|
-
local_mode: 'sendrecv',
|
|
68
|
-
remote_mode: 'sendrecv',
|
|
69
|
-
},
|
|
70
93
|
{
|
|
71
94
|
event: 'response',
|
|
72
95
|
call_id: oc.id,
|
|
@@ -82,19 +105,27 @@ async function test() {
|
|
|
82
105
|
$rb: '!{_}a=sendrecv',
|
|
83
106
|
}),
|
|
84
107
|
},
|
|
85
|
-
], 1000)
|
|
86
|
-
|
|
87
|
-
sip.call.terminate(oc.id)
|
|
88
|
-
|
|
89
|
-
await z.wait([
|
|
90
108
|
{
|
|
91
|
-
event: '
|
|
109
|
+
event: 'media_status',
|
|
92
110
|
call_id: oc.id,
|
|
111
|
+
status: 'setup_ok',
|
|
112
|
+
local_mode: 'sendrecv',
|
|
113
|
+
remote_mode: 'sendrecv',
|
|
93
114
|
},
|
|
94
115
|
{
|
|
95
|
-
event: '
|
|
116
|
+
event: 'media_status',
|
|
96
117
|
call_id: ic.id,
|
|
118
|
+
status: 'setup_ok',
|
|
119
|
+
local_mode: 'sendrecv',
|
|
120
|
+
remote_mode: 'sendrecv',
|
|
97
121
|
},
|
|
122
|
+
], 1000)
|
|
123
|
+
|
|
124
|
+
// now we terminate the call from t1 side
|
|
125
|
+
sip.call.terminate(oc.id)
|
|
126
|
+
|
|
127
|
+
// and wait for termination events
|
|
128
|
+
await z.wait([
|
|
98
129
|
{
|
|
99
130
|
event: 'response',
|
|
100
131
|
call_id: oc.id,
|
|
@@ -104,6 +135,14 @@ async function test() {
|
|
|
104
135
|
$rr: 'OK',
|
|
105
136
|
}),
|
|
106
137
|
},
|
|
138
|
+
{
|
|
139
|
+
event: 'call_ended',
|
|
140
|
+
call_id: oc.id,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
event: 'call_ended',
|
|
144
|
+
call_id: ic.id,
|
|
145
|
+
},
|
|
107
146
|
], 1000)
|
|
108
147
|
|
|
109
148
|
console.log("Success")
|