sip-lab 1.28.1 → 1.28.3
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 +1 -1
- package/package.json +5 -5
- package/samples/100_calls.js +0 -6
- package/samples/16_audio_streams.js +0 -31
- package/samples/183_session_progress.js +0 -12
- package/samples/artifacts/tls/cacert.pem +32 -0
- package/samples/artifacts/tls/cakey.pem +52 -0
- package/samples/delayed_media.js +0 -7
- package/samples/four_audio_streams_two_refused.js +0 -6
- package/samples/g729.js +0 -10
- package/samples/ic.wav +0 -0
- package/samples/mrcp_and_audio.js +0 -9
- package/samples/mrcp_and_audio.simplified_media.js +0 -9
- package/samples/multiple_audio_streams.js +0 -30
- package/samples/oc.wav +0 -0
- package/samples/pcma.js +0 -11
- package/samples/play_wav_and_speech_recog.bad_transcript.pcmu8000.js +0 -23
- package/samples/refer.js +0 -30
- package/samples/refuse_telephone_event.js +0 -11
- package/samples/reinvite_and_dtmf.js +0 -11
- package/samples/reinvite_audio_audio.js +0 -11
- package/samples/reinvite_with_hold_unhold.js +0 -11
- package/samples/rtp_and_srtp.js +0 -6
- package/samples/rtp_and_srtp.rtp_refused.js +0 -6
- package/samples/send_and_receive_fax.js +0 -11
- package/samples/simple.js +32 -8
- package/samples/sip_cancel.js +0 -9
- package/samples/speech_synth_and_recog.speex16000.js +2 -23
- package/samples/srtp.js +0 -6
- package/samples/start_play_wav_with_end_of_file_event.js +0 -23
- package/samples/start_play_wav_with_no_loop.js +0 -23
- package/samples/{tcp_and_extra_headers.js → tcp.js} +0 -23
- package/samples/text_to_speech.js +0 -23
- package/samples/tls.js +128 -0
- package/samples/two_audio_streams.js +0 -5
- package/samples/two_audio_streams.port_zero.js +0 -5
- package/samples_extra/ws_speech_server.dtmf.js +0 -24
- package/samples_extra/ws_speech_server.google.js +0 -24
- package/src/addon.cpp +35 -0
- package/src/sip.cpp +26 -9
package/samples/simple.js
CHANGED
|
@@ -31,10 +31,17 @@ async function test() {
|
|
|
31
31
|
console.log("t1", t1)
|
|
32
32
|
console.log("t2", t2)
|
|
33
33
|
|
|
34
|
-
// make the call from t1 to t2
|
|
35
|
-
const oc = sip.call.create(t1.id, {
|
|
34
|
+
// make the call from t1 to t2 with some custom heaaders
|
|
35
|
+
const oc = sip.call.create(t1.id, {
|
|
36
|
+
from_uri: 'sip:alice@test.com',
|
|
37
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
38
|
+
headers: {
|
|
39
|
+
'X-MyHeader1': 'abc',
|
|
40
|
+
'X-MyHeader2': 'def',
|
|
41
|
+
},
|
|
42
|
+
})
|
|
36
43
|
|
|
37
|
-
// Here we will wait for the call to arrive at t2
|
|
44
|
+
// Here we will wait for the call to arrive at t2 with the custom headers
|
|
38
45
|
// We will also get a '100 Trying' that is sent by sip-lab automatically
|
|
39
46
|
// 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.
|
|
40
47
|
await z.wait([
|
|
@@ -42,6 +49,14 @@ async function test() {
|
|
|
42
49
|
event: "incoming_call",
|
|
43
50
|
call_id: m.collect("call_id"),
|
|
44
51
|
transport_id: t2.id,
|
|
52
|
+
msg: sip_msg({
|
|
53
|
+
$rU: 'bob',
|
|
54
|
+
$fU: 'alice',
|
|
55
|
+
$tU: 'bob',
|
|
56
|
+
$fd: 'test.com',
|
|
57
|
+
'$hdr(X-MyHeader1)': 'abc',
|
|
58
|
+
hdr_x_myheader2: 'def',
|
|
59
|
+
})
|
|
45
60
|
},
|
|
46
61
|
{
|
|
47
62
|
event: 'response',
|
|
@@ -64,7 +79,7 @@ async function test() {
|
|
|
64
79
|
// What matters is that all events arrive within the specified timeout.
|
|
65
80
|
// When specifying events, you can be as detailed or succinct as you need.
|
|
66
81
|
// For example, the above event 'response' is waiting for a SIP '100 Trying' to arrive,
|
|
67
|
-
// but we are specifying things to match just to show that we can be very detailed when performing a match.
|
|
82
|
+
// but we are specifying several things to match just to show that we can be very detailed when performing a match.
|
|
68
83
|
// But it could have been just like this:
|
|
69
84
|
//
|
|
70
85
|
// {
|
|
@@ -75,7 +90,7 @@ async function test() {
|
|
|
75
90
|
// $rs: '100',
|
|
76
91
|
// }),
|
|
77
92
|
// }
|
|
78
|
-
// Regarding the function sip_msg() this is a special matching function provided by https://github.com/MayamaTakeshi/sip-matching that makes it
|
|
93
|
+
// Regarding the function sip_msg(), this is a special matching function provided by https://github.com/MayamaTakeshi/sip-matching that makes it
|
|
79
94
|
// easy to match a SIP message using openser/kamailio/opensips pseudo-variables syntax.
|
|
80
95
|
|
|
81
96
|
|
|
@@ -86,10 +101,17 @@ async function test() {
|
|
|
86
101
|
sip_call_id: z.store.sip_call_id,
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
// Now we answer the call at t2 side
|
|
90
|
-
sip.call.respond(ic.id, {
|
|
104
|
+
// Now we answer the call at t2 side sending custom headers.
|
|
105
|
+
sip.call.respond(ic.id, {
|
|
106
|
+
code: 200,
|
|
107
|
+
reason: 'OK',
|
|
108
|
+
headers: {
|
|
109
|
+
'X-MyHeader3': 'ABC',
|
|
110
|
+
'X-MyHeader4': 'DEF',
|
|
111
|
+
},
|
|
112
|
+
})
|
|
91
113
|
|
|
92
|
-
// Then we wait for the '200 OK' at the t1 side
|
|
114
|
+
// Then we wait for the '200 OK' at the t1 side with the custom headers.
|
|
93
115
|
// We will also get event 'media_update' for both sides indicating media streams (RTP) were set up successfully
|
|
94
116
|
await z.wait([
|
|
95
117
|
{
|
|
@@ -105,6 +127,8 @@ async function test() {
|
|
|
105
127
|
$tU: 'bob',
|
|
106
128
|
'$hdr(content-type)': 'application/sdp',
|
|
107
129
|
$rb: '!{_}a=sendrecv',
|
|
130
|
+
'$hdr(X-MyHeader3)': 'ABC',
|
|
131
|
+
hdr_x_myheader4: 'DEF',
|
|
108
132
|
}),
|
|
109
133
|
},
|
|
110
134
|
{
|
package/samples/sip_cancel.js
CHANGED
|
@@ -36,12 +36,7 @@ async function test() {
|
|
|
36
36
|
msg: sip_msg({
|
|
37
37
|
$rs: '100',
|
|
38
38
|
$rr: 'Trying',
|
|
39
|
-
'$(hdrcnt(via))': 1,
|
|
40
39
|
'$hdr(call-id)': m.collect('sip_call_id'),
|
|
41
|
-
$fU: 'alice',
|
|
42
|
-
$fd: 'test.com',
|
|
43
|
-
$tU: 'bob',
|
|
44
|
-
'$hdr(l)': '0',
|
|
45
40
|
}),
|
|
46
41
|
},
|
|
47
42
|
], 1000)
|
|
@@ -61,10 +56,6 @@ async function test() {
|
|
|
61
56
|
msg: sip_msg({
|
|
62
57
|
$rs: '180',
|
|
63
58
|
$rr: 'Ringing',
|
|
64
|
-
'$(hdrcnt(VIA))': 1,
|
|
65
|
-
$fU: 'alice',
|
|
66
|
-
$fd: 'test.com',
|
|
67
|
-
$tU: 'bob',
|
|
68
59
|
}),
|
|
69
60
|
},
|
|
70
61
|
], 1000)
|
|
@@ -27,10 +27,6 @@ async function test() {
|
|
|
27
27
|
oc = sip.call.create(t1.id, {
|
|
28
28
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
29
29
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
30
|
-
headers: {
|
|
31
|
-
'X-MyHeader1': 'abc',
|
|
32
|
-
'X-MyHeader2': 'def',
|
|
33
|
-
},
|
|
34
30
|
})
|
|
35
31
|
|
|
36
32
|
await z.wait([
|
|
@@ -42,8 +38,6 @@ async function test() {
|
|
|
42
38
|
$fU: 'alice',
|
|
43
39
|
$fd: 'test.com',
|
|
44
40
|
$tU: 'bob',
|
|
45
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
46
|
-
'hdr_x_myheader2': 'def',
|
|
47
41
|
}),
|
|
48
42
|
},
|
|
49
43
|
{
|
|
@@ -53,12 +47,7 @@ async function test() {
|
|
|
53
47
|
msg: sip_msg({
|
|
54
48
|
$rs: '100',
|
|
55
49
|
$rr: 'Trying',
|
|
56
|
-
'$(hdrcnt(via))': 1,
|
|
57
50
|
'hdr_call_id': m.collect('sip_call_id'),
|
|
58
|
-
$fU: 'alice',
|
|
59
|
-
$fd: 'test.com',
|
|
60
|
-
$tU: 'bob',
|
|
61
|
-
'$hdr(l)': '0',
|
|
62
51
|
}),
|
|
63
52
|
},
|
|
64
53
|
], 1000)
|
|
@@ -71,10 +60,6 @@ async function test() {
|
|
|
71
60
|
sip.call.respond(ic.id, {
|
|
72
61
|
code: 200,
|
|
73
62
|
reason:'OK',
|
|
74
|
-
headers: {
|
|
75
|
-
'X-MyHeader3': 'ghi',
|
|
76
|
-
'X-MyHeader4': 'jkl',
|
|
77
|
-
},
|
|
78
63
|
})
|
|
79
64
|
|
|
80
65
|
await z.wait([
|
|
@@ -95,14 +80,6 @@ async function test() {
|
|
|
95
80
|
msg: sip_msg({
|
|
96
81
|
$rs: '200',
|
|
97
82
|
$rr: 'OK',
|
|
98
|
-
'$(hdrcnt(v))': 1,
|
|
99
|
-
$fU: 'alice',
|
|
100
|
-
$fd: 'test.com',
|
|
101
|
-
$tU: 'bob',
|
|
102
|
-
'$hdr(content-type)': 'application/sdp',
|
|
103
|
-
$rb: '!{_}a=sendrecv',
|
|
104
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
105
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
106
83
|
}),
|
|
107
84
|
},
|
|
108
85
|
], 1000)
|
|
@@ -144,6 +121,8 @@ async function test() {
|
|
|
144
121
|
sip.call.stop_speech_synth(oc.id) // this is not actually necessary. It is used just to confirm the command works
|
|
145
122
|
sip.call.stop_speech_synth(ic.id) // this is not actually necessary. It is used just to confirm the command works
|
|
146
123
|
|
|
124
|
+
sip.call.stop_speech_recog(oc.id) // this is not actually necessary. It is used just to confirm the command works
|
|
125
|
+
sip.call.stop_speech_recog(ic.id) // this is not actually necessary. It is used just to confirm the command works
|
|
147
126
|
|
|
148
127
|
sip.call.stop_record_wav(oc.id)
|
|
149
128
|
sip.call.stop_record_wav(ic.id)
|
package/samples/srtp.js
CHANGED
|
@@ -25,10 +25,6 @@ async function test() {
|
|
|
25
25
|
oc = sip.call.create(t1.id, {
|
|
26
26
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
27
27
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
28
|
-
headers: {
|
|
29
|
-
'X-MyHeader1': 'abc',
|
|
30
|
-
'X-MyHeader2': 'def',
|
|
31
|
-
},
|
|
32
28
|
})
|
|
33
29
|
|
|
34
30
|
await z.wait([
|
|
@@ -40,8 +36,6 @@ async function test() {
|
|
|
40
36
|
$fU: 'alice',
|
|
41
37
|
$fd: 'test.com',
|
|
42
38
|
$tU: 'bob',
|
|
43
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
44
|
-
'hdr_x_myheader2': 'def',
|
|
45
39
|
}),
|
|
46
40
|
},
|
|
47
41
|
{
|
|
@@ -51,12 +45,7 @@ async function test() {
|
|
|
51
45
|
msg: sip_msg({
|
|
52
46
|
$rs: '100',
|
|
53
47
|
$rr: 'Trying',
|
|
54
|
-
'$(hdrcnt(via))': 1,
|
|
55
48
|
'hdr_call_id': m.collect('sip_call_id'),
|
|
56
|
-
$fU: 'alice',
|
|
57
|
-
$fd: 'test.com',
|
|
58
|
-
$tU: 'bob',
|
|
59
|
-
'$hdr(l)': '0',
|
|
60
49
|
}),
|
|
61
50
|
},
|
|
62
51
|
], 1000)
|
|
@@ -69,10 +58,6 @@ async function test() {
|
|
|
69
58
|
sip.call.respond(ic.id, {
|
|
70
59
|
code: 200,
|
|
71
60
|
reason:'OK',
|
|
72
|
-
headers: {
|
|
73
|
-
'X-MyHeader3': 'ghi',
|
|
74
|
-
'X-MyHeader4': 'jkl',
|
|
75
|
-
},
|
|
76
61
|
})
|
|
77
62
|
|
|
78
63
|
await z.wait([
|
|
@@ -93,14 +78,6 @@ async function test() {
|
|
|
93
78
|
msg: sip_msg({
|
|
94
79
|
$rs: '200',
|
|
95
80
|
$rr: 'OK',
|
|
96
|
-
'$(hdrcnt(v))': 1,
|
|
97
|
-
$fU: 'alice',
|
|
98
|
-
$fd: 'test.com',
|
|
99
|
-
$tU: 'bob',
|
|
100
|
-
'$hdr(content-type)': 'application/sdp',
|
|
101
|
-
$rb: '!{_}a=sendrecv',
|
|
102
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
103
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
104
81
|
}),
|
|
105
82
|
},
|
|
106
83
|
], 1000)
|
|
@@ -25,10 +25,6 @@ async function test() {
|
|
|
25
25
|
oc = sip.call.create(t1.id, {
|
|
26
26
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
27
27
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
28
|
-
headers: {
|
|
29
|
-
'X-MyHeader1': 'abc',
|
|
30
|
-
'X-MyHeader2': 'def',
|
|
31
|
-
},
|
|
32
28
|
})
|
|
33
29
|
|
|
34
30
|
await z.wait([
|
|
@@ -40,8 +36,6 @@ async function test() {
|
|
|
40
36
|
$fU: 'alice',
|
|
41
37
|
$fd: 'test.com',
|
|
42
38
|
$tU: 'bob',
|
|
43
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
44
|
-
'hdr_x_myheader2': 'def',
|
|
45
39
|
}),
|
|
46
40
|
},
|
|
47
41
|
{
|
|
@@ -51,12 +45,7 @@ async function test() {
|
|
|
51
45
|
msg: sip_msg({
|
|
52
46
|
$rs: '100',
|
|
53
47
|
$rr: 'Trying',
|
|
54
|
-
'$(hdrcnt(via))': 1,
|
|
55
48
|
'hdr_call_id': m.collect('sip_call_id'),
|
|
56
|
-
$fU: 'alice',
|
|
57
|
-
$fd: 'test.com',
|
|
58
|
-
$tU: 'bob',
|
|
59
|
-
'$hdr(l)': '0',
|
|
60
49
|
}),
|
|
61
50
|
},
|
|
62
51
|
], 1000)
|
|
@@ -69,10 +58,6 @@ async function test() {
|
|
|
69
58
|
sip.call.respond(ic.id, {
|
|
70
59
|
code: 200,
|
|
71
60
|
reason:'OK',
|
|
72
|
-
headers: {
|
|
73
|
-
'X-MyHeader3': 'ghi',
|
|
74
|
-
'X-MyHeader4': 'jkl',
|
|
75
|
-
},
|
|
76
61
|
})
|
|
77
62
|
|
|
78
63
|
await z.wait([
|
|
@@ -93,14 +78,6 @@ async function test() {
|
|
|
93
78
|
msg: sip_msg({
|
|
94
79
|
$rs: '200',
|
|
95
80
|
$rr: 'OK',
|
|
96
|
-
'$(hdrcnt(v))': 1,
|
|
97
|
-
$fU: 'alice',
|
|
98
|
-
$fd: 'test.com',
|
|
99
|
-
$tU: 'bob',
|
|
100
|
-
'$hdr(content-type)': 'application/sdp',
|
|
101
|
-
$rb: '!{_}a=sendrecv',
|
|
102
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
103
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
104
81
|
}),
|
|
105
82
|
},
|
|
106
83
|
], 1000)
|
|
@@ -25,10 +25,6 @@ async function test() {
|
|
|
25
25
|
oc = sip.call.create(t1.id, {
|
|
26
26
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
27
27
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
28
|
-
headers: {
|
|
29
|
-
'X-MyHeader1': 'abc',
|
|
30
|
-
'X-MyHeader2': 'def',
|
|
31
|
-
},
|
|
32
28
|
})
|
|
33
29
|
|
|
34
30
|
await z.wait([
|
|
@@ -40,8 +36,6 @@ async function test() {
|
|
|
40
36
|
$fU: 'alice',
|
|
41
37
|
$fd: 'test.com',
|
|
42
38
|
$tU: 'bob',
|
|
43
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
44
|
-
'hdr_x_myheader2': 'def',
|
|
45
39
|
}),
|
|
46
40
|
},
|
|
47
41
|
{
|
|
@@ -51,12 +45,7 @@ async function test() {
|
|
|
51
45
|
msg: sip_msg({
|
|
52
46
|
$rs: '100',
|
|
53
47
|
$rr: 'Trying',
|
|
54
|
-
'$(hdrcnt(via))': 1,
|
|
55
48
|
'hdr_call_id': m.collect('sip_call_id'),
|
|
56
|
-
$fU: 'alice',
|
|
57
|
-
$fd: 'test.com',
|
|
58
|
-
$tU: 'bob',
|
|
59
|
-
'$hdr(l)': '0',
|
|
60
49
|
}),
|
|
61
50
|
},
|
|
62
51
|
], 1000)
|
|
@@ -69,10 +58,6 @@ async function test() {
|
|
|
69
58
|
sip.call.respond(ic.id, {
|
|
70
59
|
code: 200,
|
|
71
60
|
reason:'OK',
|
|
72
|
-
headers: {
|
|
73
|
-
'X-MyHeader3': 'ghi',
|
|
74
|
-
'X-MyHeader4': 'jkl',
|
|
75
|
-
},
|
|
76
61
|
})
|
|
77
62
|
|
|
78
63
|
await z.wait([
|
|
@@ -93,14 +78,6 @@ async function test() {
|
|
|
93
78
|
msg: sip_msg({
|
|
94
79
|
$rs: '200',
|
|
95
80
|
$rr: 'OK',
|
|
96
|
-
'$(hdrcnt(v))': 1,
|
|
97
|
-
$fU: 'alice',
|
|
98
|
-
$fd: 'test.com',
|
|
99
|
-
$tU: 'bob',
|
|
100
|
-
'$hdr(content-type)': 'application/sdp',
|
|
101
|
-
$rb: '!{_}a=sendrecv',
|
|
102
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
103
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
104
81
|
}),
|
|
105
82
|
},
|
|
106
83
|
], 1000)
|
|
@@ -25,10 +25,6 @@ async function test() {
|
|
|
25
25
|
oc = sip.call.create(t1.id, {
|
|
26
26
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
27
27
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
28
|
-
headers: {
|
|
29
|
-
'X-MyHeader1': 'abc',
|
|
30
|
-
'X-MyHeader2': 'def',
|
|
31
|
-
},
|
|
32
28
|
})
|
|
33
29
|
|
|
34
30
|
await z.wait([
|
|
@@ -40,8 +36,6 @@ async function test() {
|
|
|
40
36
|
$fU: 'alice',
|
|
41
37
|
$fd: 'test.com',
|
|
42
38
|
$tU: 'bob',
|
|
43
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
44
|
-
'hdr_x_myheader2': 'def',
|
|
45
39
|
}),
|
|
46
40
|
},
|
|
47
41
|
{
|
|
@@ -51,12 +45,7 @@ async function test() {
|
|
|
51
45
|
msg: sip_msg({
|
|
52
46
|
$rs: '100',
|
|
53
47
|
$rr: 'Trying',
|
|
54
|
-
'$(hdrcnt(via))': 1,
|
|
55
48
|
'hdr_call_id': m.collect('sip_call_id'),
|
|
56
|
-
$fU: 'alice',
|
|
57
|
-
$fd: 'test.com',
|
|
58
|
-
$tU: 'bob',
|
|
59
|
-
'$hdr(l)': '0',
|
|
60
49
|
}),
|
|
61
50
|
},
|
|
62
51
|
], 1000)
|
|
@@ -69,10 +58,6 @@ async function test() {
|
|
|
69
58
|
sip.call.respond(ic.id, {
|
|
70
59
|
code: 200,
|
|
71
60
|
reason:'OK',
|
|
72
|
-
headers: {
|
|
73
|
-
'X-MyHeader3': 'ghi',
|
|
74
|
-
'X-MyHeader4': 'jkl',
|
|
75
|
-
},
|
|
76
61
|
})
|
|
77
62
|
|
|
78
63
|
await z.wait([
|
|
@@ -93,14 +78,6 @@ async function test() {
|
|
|
93
78
|
msg: sip_msg({
|
|
94
79
|
$rs: '200',
|
|
95
80
|
$rr: 'OK',
|
|
96
|
-
'$(hdrcnt(v))': 1,
|
|
97
|
-
$fU: 'alice',
|
|
98
|
-
$fd: 'test.com',
|
|
99
|
-
$tU: 'bob',
|
|
100
|
-
'$hdr(content-type)': 'application/sdp',
|
|
101
|
-
$rb: '!{_}a=sendrecv',
|
|
102
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
103
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
104
81
|
}),
|
|
105
82
|
},
|
|
106
83
|
], 1000)
|
package/samples/tls.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// This test creates 2 UDP SIP endpoints, makes a call between them and disconeects.
|
|
2
|
+
|
|
3
|
+
const sip = require ('../index.js')
|
|
4
|
+
const Zeq = require('@mayama/zeq')
|
|
5
|
+
const m = require('data-matching')
|
|
6
|
+
const sip_msg = require('sip-matching')
|
|
7
|
+
|
|
8
|
+
// here we create our Zeq instance
|
|
9
|
+
var z = new Zeq()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async function test() {
|
|
13
|
+
sip.set_log_level(6)
|
|
14
|
+
|
|
15
|
+
// here we set our Zeq instance to trap events generated by sip-lab event_source
|
|
16
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
17
|
+
var e = evt.args[0]
|
|
18
|
+
return e
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
|
|
22
|
+
|
|
23
|
+
// here we start sip-lab
|
|
24
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
25
|
+
|
|
26
|
+
// Here we create the SIP endpoints (transports).
|
|
27
|
+
// Since we don't specify the port, an available port will be allocated.
|
|
28
|
+
// Since we don't specify the type ('udp' or 'tcp' or 'tls'), 'udp' will be used by default.
|
|
29
|
+
const t1 = sip.transport.create({address: "127.0.0.1", port: 6060, type: 'tls', cert_file: 'samples/artifacts/tls/cacert.pem', key_file: 'samples/artifacts/tls/cakey.pem'})
|
|
30
|
+
const t2 = sip.transport.create({address: "127.0.0.1", port: 6061, type: 'tls', cert_file: 'samples/artifacts/tls/cacert.pem', key_file: 'samples/artifacts/tls/cakey.pem'})
|
|
31
|
+
|
|
32
|
+
// here we just print the transports
|
|
33
|
+
console.log("t1", t1)
|
|
34
|
+
console.log("t2", t2)
|
|
35
|
+
|
|
36
|
+
// make the call from t1 to t2
|
|
37
|
+
const oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port};transport=tls`})
|
|
38
|
+
|
|
39
|
+
// Here we will wait for the call to arrive at t2
|
|
40
|
+
// We will also get a '100 Trying' that is sent by sip-lab automatically
|
|
41
|
+
// 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.
|
|
42
|
+
await z.wait([
|
|
43
|
+
{
|
|
44
|
+
event: "incoming_call",
|
|
45
|
+
call_id: m.collect("call_id"),
|
|
46
|
+
transport_id: t2.id,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
event: 'response',
|
|
50
|
+
call_id: oc.id,
|
|
51
|
+
method: 'INVITE',
|
|
52
|
+
msg: sip_msg({
|
|
53
|
+
$rs: '100',
|
|
54
|
+
$rr: 'Trying',
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
], 1000)
|
|
58
|
+
|
|
59
|
+
// Here we store data for the incoming call
|
|
60
|
+
// just to organize our code (not really needed)
|
|
61
|
+
const ic = {
|
|
62
|
+
id: z.store.call_id,
|
|
63
|
+
sip_call_id: z.store.sip_call_id,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Now we answer the call at t2 side
|
|
67
|
+
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
68
|
+
|
|
69
|
+
// Then we wait for the '200 OK' at the t1 side
|
|
70
|
+
// We will also get event 'media_update' for both sides indicating media streams (RTP) were set up successfully
|
|
71
|
+
await z.wait([
|
|
72
|
+
{
|
|
73
|
+
event: 'response',
|
|
74
|
+
call_id: oc.id,
|
|
75
|
+
method: 'INVITE',
|
|
76
|
+
msg: sip_msg({
|
|
77
|
+
$rs: '200',
|
|
78
|
+
$rr: 'OK',
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
event: 'media_update',
|
|
83
|
+
call_id: oc.id,
|
|
84
|
+
status: 'ok',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
event: 'media_update',
|
|
88
|
+
call_id: ic.id,
|
|
89
|
+
status: 'ok',
|
|
90
|
+
},
|
|
91
|
+
], 1000)
|
|
92
|
+
|
|
93
|
+
// now we terminate the call from t1 side
|
|
94
|
+
sip.call.terminate(oc.id)
|
|
95
|
+
|
|
96
|
+
// and wait for termination events
|
|
97
|
+
await z.wait([
|
|
98
|
+
{
|
|
99
|
+
event: 'response',
|
|
100
|
+
call_id: oc.id,
|
|
101
|
+
method: 'BYE',
|
|
102
|
+
msg: sip_msg({
|
|
103
|
+
$rs: '200',
|
|
104
|
+
$rr: 'OK',
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
event: 'call_ended',
|
|
109
|
+
call_id: oc.id,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
event: 'call_ended',
|
|
113
|
+
call_id: ic.id,
|
|
114
|
+
},
|
|
115
|
+
], 1000)
|
|
116
|
+
|
|
117
|
+
console.log("Success")
|
|
118
|
+
|
|
119
|
+
sip.stop()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
test()
|
|
124
|
+
.catch(e => {
|
|
125
|
+
console.error(e)
|
|
126
|
+
process.exit(1)
|
|
127
|
+
})
|
|
128
|
+
|
|
@@ -56,11 +56,6 @@ async function test() {
|
|
|
56
56
|
msg: sip_msg({
|
|
57
57
|
$rs: '200',
|
|
58
58
|
$rr: 'OK',
|
|
59
|
-
'$(hdrcnt(VIA))': 1,
|
|
60
|
-
$fU: 'alice',
|
|
61
|
-
$fd: 'test.com',
|
|
62
|
-
$tU: 'bob',
|
|
63
|
-
'$hdr(content-type)': 'application/sdp',
|
|
64
59
|
$rb: sdp.jsonpath_matcher({
|
|
65
60
|
'$.media.length': [2],
|
|
66
61
|
'$.media[*].desc.type': ['audio','audio'],
|
|
@@ -56,11 +56,6 @@ async function test() {
|
|
|
56
56
|
msg: sip_msg({
|
|
57
57
|
$rs: '200',
|
|
58
58
|
$rr: 'OK',
|
|
59
|
-
'$(hdrcnt(VIA))': 1,
|
|
60
|
-
$fU: 'alice',
|
|
61
|
-
$fd: 'test.com',
|
|
62
|
-
$tU: 'bob',
|
|
63
|
-
'$hdr(content-type)': 'application/sdp',
|
|
64
59
|
$rb: sdp.jsonpath_matcher({
|
|
65
60
|
'$.media.length': [2],
|
|
66
61
|
'$.media[*].desc.type': ['audio','audio'],
|
|
@@ -27,10 +27,6 @@ async function test() {
|
|
|
27
27
|
oc = sip.call.create(t1.id, {
|
|
28
28
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
29
29
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
30
|
-
headers: {
|
|
31
|
-
'X-MyHeader1': 'abc',
|
|
32
|
-
'X-MyHeader2': 'def',
|
|
33
|
-
},
|
|
34
30
|
})
|
|
35
31
|
|
|
36
32
|
await z.wait([
|
|
@@ -42,8 +38,6 @@ async function test() {
|
|
|
42
38
|
$fU: 'alice',
|
|
43
39
|
$fd: 'test.com',
|
|
44
40
|
$tU: 'bob',
|
|
45
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
46
|
-
'hdr_x_myheader2': 'def',
|
|
47
41
|
}),
|
|
48
42
|
},
|
|
49
43
|
{
|
|
@@ -53,12 +47,6 @@ async function test() {
|
|
|
53
47
|
msg: sip_msg({
|
|
54
48
|
$rs: '100',
|
|
55
49
|
$rr: 'Trying',
|
|
56
|
-
'$(hdrcnt(via))': 1,
|
|
57
|
-
'hdr_call_id': m.collect('sip_call_id'),
|
|
58
|
-
$fU: 'alice',
|
|
59
|
-
$fd: 'test.com',
|
|
60
|
-
$tU: 'bob',
|
|
61
|
-
'$hdr(l)': '0',
|
|
62
50
|
}),
|
|
63
51
|
},
|
|
64
52
|
], 1000)
|
|
@@ -71,10 +59,6 @@ async function test() {
|
|
|
71
59
|
sip.call.respond(ic.id, {
|
|
72
60
|
code: 200,
|
|
73
61
|
reason:'OK',
|
|
74
|
-
headers: {
|
|
75
|
-
'X-MyHeader3': 'ghi',
|
|
76
|
-
'X-MyHeader4': 'jkl',
|
|
77
|
-
},
|
|
78
62
|
})
|
|
79
63
|
|
|
80
64
|
await z.wait([
|
|
@@ -95,14 +79,6 @@ async function test() {
|
|
|
95
79
|
msg: sip_msg({
|
|
96
80
|
$rs: '200',
|
|
97
81
|
$rr: 'OK',
|
|
98
|
-
'$(hdrcnt(v))': 1,
|
|
99
|
-
$fU: 'alice',
|
|
100
|
-
$fd: 'test.com',
|
|
101
|
-
$tU: 'bob',
|
|
102
|
-
'$hdr(content-type)': 'application/sdp',
|
|
103
|
-
$rb: '!{_}a=sendrecv',
|
|
104
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
105
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
106
82
|
}),
|
|
107
83
|
},
|
|
108
84
|
], 1000)
|
|
@@ -27,10 +27,6 @@ async function test() {
|
|
|
27
27
|
oc = sip.call.create(t1.id, {
|
|
28
28
|
from_uri: '"abc"<sip:alice@test.com>',
|
|
29
29
|
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
30
|
-
headers: {
|
|
31
|
-
'X-MyHeader1': 'abc',
|
|
32
|
-
'X-MyHeader2': 'def',
|
|
33
|
-
},
|
|
34
30
|
})
|
|
35
31
|
|
|
36
32
|
await z.wait([
|
|
@@ -42,8 +38,6 @@ async function test() {
|
|
|
42
38
|
$fU: 'alice',
|
|
43
39
|
$fd: 'test.com',
|
|
44
40
|
$tU: 'bob',
|
|
45
|
-
'$hdr(X-MyHeader1)': 'abc',
|
|
46
|
-
'hdr_x_myheader2': 'def',
|
|
47
41
|
}),
|
|
48
42
|
},
|
|
49
43
|
{
|
|
@@ -53,12 +47,6 @@ async function test() {
|
|
|
53
47
|
msg: sip_msg({
|
|
54
48
|
$rs: '100',
|
|
55
49
|
$rr: 'Trying',
|
|
56
|
-
'$(hdrcnt(via))': 1,
|
|
57
|
-
'hdr_call_id': m.collect('sip_call_id'),
|
|
58
|
-
$fU: 'alice',
|
|
59
|
-
$fd: 'test.com',
|
|
60
|
-
$tU: 'bob',
|
|
61
|
-
'$hdr(l)': '0',
|
|
62
50
|
}),
|
|
63
51
|
},
|
|
64
52
|
], 1000)
|
|
@@ -71,10 +59,6 @@ async function test() {
|
|
|
71
59
|
sip.call.respond(ic.id, {
|
|
72
60
|
code: 200,
|
|
73
61
|
reason:'OK',
|
|
74
|
-
headers: {
|
|
75
|
-
'X-MyHeader3': 'ghi',
|
|
76
|
-
'X-MyHeader4': 'jkl',
|
|
77
|
-
},
|
|
78
62
|
})
|
|
79
63
|
|
|
80
64
|
await z.wait([
|
|
@@ -95,14 +79,6 @@ async function test() {
|
|
|
95
79
|
msg: sip_msg({
|
|
96
80
|
$rs: '200',
|
|
97
81
|
$rr: 'OK',
|
|
98
|
-
'$(hdrcnt(v))': 1,
|
|
99
|
-
$fU: 'alice',
|
|
100
|
-
$fd: 'test.com',
|
|
101
|
-
$tU: 'bob',
|
|
102
|
-
'$hdr(content-type)': 'application/sdp',
|
|
103
|
-
$rb: '!{_}a=sendrecv',
|
|
104
|
-
'$hdr(X-MyHeader3)': 'ghi',
|
|
105
|
-
'$hdr(X-MyHeader4)': 'jkl',
|
|
106
82
|
}),
|
|
107
83
|
},
|
|
108
84
|
], 1000)
|