sip-lab 1.30.0 → 1.31.0
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/index.js +1 -0
- package/package.json +2 -2
- package/prebuilds/linux-x64/node.abi102.node +0 -0
- package/prebuilds/linux-x64/node.abi108.node +0 -0
- package/prebuilds/linux-x64/node.abi111.node +0 -0
- package/prebuilds/linux-x64/node.abi115.node +0 -0
- package/prebuilds/linux-x64/node.abi120.node +0 -0
- package/prebuilds/linux-x64/node.abi88.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/samples/custom_call_id.js +219 -0
- package/samples/custom_call_id_and_from_tag.js.future +224 -0
- package/samples/media_fields.js +190 -0
- package/samples/mrcp_and_audio.js +0 -12
- package/samples/session_expires.update.js.future +268 -0
- package/samples/session_expires.update.with_sipjs-lab.js +312 -0
- package/src/addon.cpp +35 -0
- package/src/sip.cpp +140 -34
- package/src/sip.hpp +2 -0
package/index.js
CHANGED
|
@@ -60,6 +60,7 @@ addon.call = {
|
|
|
60
60
|
send_dtmf: (c_id, params) => { return addon.call_send_dtmf(c_id, JSON.stringify(params)) },
|
|
61
61
|
send_bfsk: (c_id, params) => { return addon.call_send_bfsk(c_id, JSON.stringify(params)) },
|
|
62
62
|
reinvite: (c_id, params) => { return addon.call_reinvite(c_id, JSON.stringify(params ? params : {})) },
|
|
63
|
+
update: (c_id, params) => { return addon.call_update(c_id, JSON.stringify(params ? params : {})) },
|
|
63
64
|
send_request: (c_id, params) => { return addon.call_send_request(c_id, JSON.stringify(params)) },
|
|
64
65
|
start_record_wav: (c_id, params) => { return addon.call_start_record_wav(c_id, JSON.stringify(params)) },
|
|
65
66
|
start_play_wav: (c_id, params) => { return addon.call_start_play_wav(c_id, JSON.stringify(params)) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sip-lab",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"node-gyp-build": "^4.5.0",
|
|
30
30
|
"sdp-matching": "^1.3.2",
|
|
31
31
|
"sip-matching": "^1.3.14",
|
|
32
|
-
"sipjs-lab": "^1.
|
|
32
|
+
"sipjs-lab": "^1.3.13"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"prebuildify": "^5.0.1",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const sip = require ('../index.js')
|
|
2
|
+
const Zeq = require('@mayama/zeq')
|
|
3
|
+
const m = require('data-matching')
|
|
4
|
+
const sip_msg = require('sip-matching')
|
|
5
|
+
const uuid = require('uuid')
|
|
6
|
+
|
|
7
|
+
// here we create our Zeq instance
|
|
8
|
+
var z = new Zeq()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async function test() {
|
|
12
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
13
|
+
var e = evt.args[0]
|
|
14
|
+
return e
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
|
|
18
|
+
|
|
19
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
20
|
+
|
|
21
|
+
const t1 = sip.transport.create({address: "127.0.0.1"})
|
|
22
|
+
const t2 = sip.transport.create({address: "127.0.0.1"})
|
|
23
|
+
|
|
24
|
+
console.log("t1", t1)
|
|
25
|
+
console.log("t2", t2)
|
|
26
|
+
|
|
27
|
+
const call_id = uuid.v4()
|
|
28
|
+
|
|
29
|
+
var oc = sip.call.create(t1.id, {
|
|
30
|
+
from_uri: 'sip:alice@test.com',
|
|
31
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
32
|
+
headers: {
|
|
33
|
+
'Call-ID': call_id,
|
|
34
|
+
'Supported': 'timer',
|
|
35
|
+
'Min-SE': '180',
|
|
36
|
+
'Session-Expires': '180',
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
await z.wait([
|
|
41
|
+
{
|
|
42
|
+
event: "incoming_call",
|
|
43
|
+
call_id: m.collect("call_id"),
|
|
44
|
+
transport_id: t2.id,
|
|
45
|
+
msg: sip_msg({
|
|
46
|
+
$rU: 'bob',
|
|
47
|
+
$fU: 'alice',
|
|
48
|
+
$tU: 'bob',
|
|
49
|
+
$fd: 'test.com',
|
|
50
|
+
hdr_supported: 'timer',
|
|
51
|
+
hdr_min_se: '180',
|
|
52
|
+
hdr_session_expires: '180',
|
|
53
|
+
$ci: call_id,
|
|
54
|
+
})
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
event: 'response',
|
|
58
|
+
call_id: oc.id,
|
|
59
|
+
method: 'INVITE',
|
|
60
|
+
msg: sip_msg({
|
|
61
|
+
$rs: '100',
|
|
62
|
+
$rr: 'Trying',
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
], 1000)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var ic = {
|
|
69
|
+
id: z.store.call_id,
|
|
70
|
+
sip_call_id: z.store.sip_call_id,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
sip.call.respond(ic.id, {
|
|
74
|
+
code: 422,
|
|
75
|
+
reason: 'Session Timer Too Small',
|
|
76
|
+
headers: {
|
|
77
|
+
'Supported': 'timer',
|
|
78
|
+
'Min-SE': '300',
|
|
79
|
+
'Session-Expires': '300;refresher=uac',
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
await z.wait([
|
|
84
|
+
{
|
|
85
|
+
event: 'call_ended',
|
|
86
|
+
call_id: ic.id,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
event: 'call_ended',
|
|
90
|
+
call_id: oc.id,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
event: 'response',
|
|
94
|
+
call_id: 0,
|
|
95
|
+
method: 'INVITE',
|
|
96
|
+
msg: sip_msg({
|
|
97
|
+
$rs: '422',
|
|
98
|
+
$rr: 'Session Timer Too Small',
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
], 1000)
|
|
102
|
+
|
|
103
|
+
oc = sip.call.create(t1.id, {
|
|
104
|
+
from_uri: 'sip:alice@test.com;tag=1c619456422',
|
|
105
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
106
|
+
headers: {
|
|
107
|
+
'Call-ID': call_id,
|
|
108
|
+
'Supported': 'timer',
|
|
109
|
+
'Min-SE': '300',
|
|
110
|
+
'Session-Expires': '300',
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
delete z.store.call_id
|
|
115
|
+
|
|
116
|
+
await z.wait([
|
|
117
|
+
{
|
|
118
|
+
event: "incoming_call",
|
|
119
|
+
call_id: m.collect("call_id"),
|
|
120
|
+
transport_id: t2.id,
|
|
121
|
+
msg: sip_msg({
|
|
122
|
+
$rU: 'bob',
|
|
123
|
+
$fU: 'alice',
|
|
124
|
+
$tU: 'bob',
|
|
125
|
+
$fd: 'test.com',
|
|
126
|
+
hdr_supported: 'timer',
|
|
127
|
+
hdr_min_se: '300',
|
|
128
|
+
hdr_session_expires: '300',
|
|
129
|
+
$ci: call_id,
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
event: 'response',
|
|
134
|
+
call_id: oc.id,
|
|
135
|
+
method: 'INVITE',
|
|
136
|
+
msg: sip_msg({
|
|
137
|
+
$rs: '100',
|
|
138
|
+
$rr: 'Trying',
|
|
139
|
+
}),
|
|
140
|
+
},
|
|
141
|
+
], 1000)
|
|
142
|
+
|
|
143
|
+
ic = {
|
|
144
|
+
id: z.store.call_id,
|
|
145
|
+
sip_call_id: z.store.sip_call_id,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
sip.call.respond(ic.id, {
|
|
149
|
+
code: 200,
|
|
150
|
+
reason: 'OK',
|
|
151
|
+
headers: {
|
|
152
|
+
'Supported': 'timer',
|
|
153
|
+
'Min-SE': '300',
|
|
154
|
+
'Session-Expires': '300;refresher=uac',
|
|
155
|
+
},
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
await z.wait([
|
|
159
|
+
{
|
|
160
|
+
event: 'response',
|
|
161
|
+
call_id: oc.id,
|
|
162
|
+
method: 'INVITE',
|
|
163
|
+
msg: sip_msg({
|
|
164
|
+
$rs: '200',
|
|
165
|
+
$rr: 'OK',
|
|
166
|
+
hdr_supported: 'timer',
|
|
167
|
+
hdr_min_se: '300',
|
|
168
|
+
hdr_session_expires: '300;refresher=uac',
|
|
169
|
+
}),
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
event: 'media_update',
|
|
173
|
+
call_id: oc.id,
|
|
174
|
+
status: 'ok',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
event: 'media_update',
|
|
178
|
+
call_id: ic.id,
|
|
179
|
+
status: 'ok',
|
|
180
|
+
},
|
|
181
|
+
], 1000)
|
|
182
|
+
|
|
183
|
+
await z.sleep(5000)
|
|
184
|
+
|
|
185
|
+
sip.call.terminate(oc.id)
|
|
186
|
+
|
|
187
|
+
// and wait for termination events
|
|
188
|
+
await z.wait([
|
|
189
|
+
{
|
|
190
|
+
event: 'response',
|
|
191
|
+
call_id: oc.id,
|
|
192
|
+
method: 'BYE',
|
|
193
|
+
msg: sip_msg({
|
|
194
|
+
$rs: '200',
|
|
195
|
+
$rr: 'OK',
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
event: 'call_ended',
|
|
200
|
+
call_id: oc.id,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
event: 'call_ended',
|
|
204
|
+
call_id: ic.id,
|
|
205
|
+
},
|
|
206
|
+
], 1000)
|
|
207
|
+
|
|
208
|
+
console.log("Success")
|
|
209
|
+
|
|
210
|
+
sip.stop()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
test()
|
|
215
|
+
.catch(e => {
|
|
216
|
+
console.error(e)
|
|
217
|
+
process.exit(1)
|
|
218
|
+
})
|
|
219
|
+
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
const sip = require ('../index.js')
|
|
2
|
+
const Zeq = require('@mayama/zeq')
|
|
3
|
+
const m = require('data-matching')
|
|
4
|
+
const sip_msg = require('sip-matching')
|
|
5
|
+
const uuid = require('uuid')
|
|
6
|
+
|
|
7
|
+
// here we create our Zeq instance
|
|
8
|
+
var z = new Zeq()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async function test() {
|
|
12
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
13
|
+
var e = evt.args[0]
|
|
14
|
+
return e
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
|
|
18
|
+
|
|
19
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
20
|
+
|
|
21
|
+
const t1 = sip.transport.create({address: "127.0.0.1"})
|
|
22
|
+
const t2 = sip.transport.create({address: "127.0.0.1"})
|
|
23
|
+
|
|
24
|
+
console.log("t1", t1)
|
|
25
|
+
console.log("t2", t2)
|
|
26
|
+
|
|
27
|
+
const call_id = uuid.v4()
|
|
28
|
+
const from_tag = "my_fake_from_tag"
|
|
29
|
+
|
|
30
|
+
var oc = sip.call.create(t1.id, {
|
|
31
|
+
from_uri: 'sip:alice@test.com',
|
|
32
|
+
from_tag,
|
|
33
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
34
|
+
headers: {
|
|
35
|
+
'Call-ID': call_id,
|
|
36
|
+
'Supported': 'timer',
|
|
37
|
+
'Min-SE': '180',
|
|
38
|
+
'Session-Expires': '180',
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
await z.wait([
|
|
43
|
+
{
|
|
44
|
+
event: "incoming_call",
|
|
45
|
+
call_id: m.collect("call_id"),
|
|
46
|
+
transport_id: t2.id,
|
|
47
|
+
msg: sip_msg({
|
|
48
|
+
$rU: 'bob',
|
|
49
|
+
$fU: 'alice',
|
|
50
|
+
// $ft: from_tag, -- not working. bug in sip-parsing
|
|
51
|
+
$tU: 'bob',
|
|
52
|
+
$fd: 'test.com',
|
|
53
|
+
hdr_supported: 'timer',
|
|
54
|
+
hdr_min_se: '180',
|
|
55
|
+
hdr_session_expires: '180',
|
|
56
|
+
$ci: call_id,
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
event: 'response',
|
|
61
|
+
call_id: oc.id,
|
|
62
|
+
method: 'INVITE',
|
|
63
|
+
msg: sip_msg({
|
|
64
|
+
$rs: '100',
|
|
65
|
+
$rr: 'Trying',
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
], 1000)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
var ic = {
|
|
72
|
+
id: z.store.call_id,
|
|
73
|
+
sip_call_id: z.store.sip_call_id,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
sip.call.respond(ic.id, {
|
|
77
|
+
code: 422,
|
|
78
|
+
reason: 'Session Timer Too Small',
|
|
79
|
+
headers: {
|
|
80
|
+
'Supported': 'timer',
|
|
81
|
+
'Min-SE': '300',
|
|
82
|
+
'Session-Expires': '300;refresher=uac',
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
await z.wait([
|
|
87
|
+
{
|
|
88
|
+
event: 'call_ended',
|
|
89
|
+
call_id: ic.id,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
event: 'call_ended',
|
|
93
|
+
call_id: oc.id,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
event: 'response',
|
|
97
|
+
call_id: 0,
|
|
98
|
+
method: 'INVITE',
|
|
99
|
+
msg: sip_msg({
|
|
100
|
+
$rs: '422',
|
|
101
|
+
$rr: 'Session Timer Too Small',
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
], 1000)
|
|
105
|
+
|
|
106
|
+
oc = sip.call.create(t1.id, {
|
|
107
|
+
from_uri: 'sip:alice@test.com;tag=1c619456422',
|
|
108
|
+
from_tag,
|
|
109
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
110
|
+
headers: {
|
|
111
|
+
'Call-ID': call_id,
|
|
112
|
+
'Supported': 'timer',
|
|
113
|
+
'Min-SE': '300',
|
|
114
|
+
'Session-Expires': '300',
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
delete z.store.call_id
|
|
119
|
+
|
|
120
|
+
await z.wait([
|
|
121
|
+
{
|
|
122
|
+
event: "incoming_call",
|
|
123
|
+
call_id: m.collect("call_id"),
|
|
124
|
+
transport_id: t2.id,
|
|
125
|
+
msg: sip_msg({
|
|
126
|
+
$rU: 'bob',
|
|
127
|
+
$fU: 'alice',
|
|
128
|
+
// $ft: from_tag, -- not working. bug in sip-parsing
|
|
129
|
+
$tU: 'bob',
|
|
130
|
+
$fd: 'test.com',
|
|
131
|
+
hdr_supported: 'timer',
|
|
132
|
+
hdr_min_se: '300',
|
|
133
|
+
hdr_session_expires: '300',
|
|
134
|
+
$ci: call_id,
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
event: 'response',
|
|
139
|
+
call_id: oc.id,
|
|
140
|
+
method: 'INVITE',
|
|
141
|
+
msg: sip_msg({
|
|
142
|
+
$rs: '100',
|
|
143
|
+
$rr: 'Trying',
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
146
|
+
], 1000)
|
|
147
|
+
|
|
148
|
+
ic = {
|
|
149
|
+
id: z.store.call_id,
|
|
150
|
+
sip_call_id: z.store.sip_call_id,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
sip.call.respond(ic.id, {
|
|
154
|
+
code: 200,
|
|
155
|
+
reason: 'OK',
|
|
156
|
+
headers: {
|
|
157
|
+
'Supported': 'timer',
|
|
158
|
+
'Min-SE': '300',
|
|
159
|
+
'Session-Expires': '300;refresher=uac',
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
await z.wait([
|
|
164
|
+
{
|
|
165
|
+
event: 'response',
|
|
166
|
+
call_id: oc.id,
|
|
167
|
+
method: 'INVITE',
|
|
168
|
+
msg: sip_msg({
|
|
169
|
+
$rs: '200',
|
|
170
|
+
$rr: 'OK',
|
|
171
|
+
hdr_supported: 'timer',
|
|
172
|
+
hdr_min_se: '300',
|
|
173
|
+
hdr_session_expires: '300;refresher=uac',
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
event: 'media_update',
|
|
178
|
+
call_id: oc.id,
|
|
179
|
+
status: 'ok',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
event: 'media_update',
|
|
183
|
+
call_id: ic.id,
|
|
184
|
+
status: 'ok',
|
|
185
|
+
},
|
|
186
|
+
], 1000)
|
|
187
|
+
|
|
188
|
+
await z.sleep(1000)
|
|
189
|
+
|
|
190
|
+
sip.call.terminate(oc.id)
|
|
191
|
+
|
|
192
|
+
// and wait for termination events
|
|
193
|
+
await z.wait([
|
|
194
|
+
{
|
|
195
|
+
event: 'response',
|
|
196
|
+
call_id: oc.id,
|
|
197
|
+
method: 'BYE',
|
|
198
|
+
msg: sip_msg({
|
|
199
|
+
$rs: '200',
|
|
200
|
+
$rr: 'OK',
|
|
201
|
+
}),
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
event: 'call_ended',
|
|
205
|
+
call_id: oc.id,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
event: 'call_ended',
|
|
209
|
+
call_id: ic.id,
|
|
210
|
+
},
|
|
211
|
+
], 1000)
|
|
212
|
+
|
|
213
|
+
console.log("Success")
|
|
214
|
+
|
|
215
|
+
sip.stop()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
test()
|
|
220
|
+
.catch(e => {
|
|
221
|
+
console.error(e)
|
|
222
|
+
process.exit(1)
|
|
223
|
+
})
|
|
224
|
+
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
// here we set our Zeq instance to trap events generated by sip-lab event_source
|
|
14
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
15
|
+
var e = evt.args[0]
|
|
16
|
+
return e
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
|
|
20
|
+
|
|
21
|
+
// here we start sip-lab
|
|
22
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
23
|
+
|
|
24
|
+
// Here we create the SIP endpoints (transports).
|
|
25
|
+
// Since we don't specify the port, an available port will be allocated.
|
|
26
|
+
// Since we don't specify the type ('udp' or 'tcp' or 'tls'), 'udp' will be used by default.
|
|
27
|
+
const t1 = sip.transport.create({address: "127.0.0.1"})
|
|
28
|
+
const t2 = sip.transport.create({address: "127.0.0.1"})
|
|
29
|
+
|
|
30
|
+
// here we just print the transports
|
|
31
|
+
console.log("t1", t1)
|
|
32
|
+
console.log("t2", t2)
|
|
33
|
+
|
|
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
|
+
media: [
|
|
43
|
+
{
|
|
44
|
+
type: 'audio',
|
|
45
|
+
fields: [
|
|
46
|
+
'a=bla bla',
|
|
47
|
+
'a=fmtp:120 0-16',
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Here we will wait for the call to arrive at t2 with the custom headers
|
|
54
|
+
// We will also get a '100 Trying' that is sent by sip-lab automatically
|
|
55
|
+
// 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.
|
|
56
|
+
await z.wait([
|
|
57
|
+
{
|
|
58
|
+
event: "incoming_call",
|
|
59
|
+
call_id: m.collect("call_id"),
|
|
60
|
+
transport_id: t2.id,
|
|
61
|
+
msg: sip_msg({
|
|
62
|
+
$rU: 'bob',
|
|
63
|
+
$fU: 'alice',
|
|
64
|
+
$tU: 'bob',
|
|
65
|
+
$fd: 'test.com',
|
|
66
|
+
'$hdr(X-MyHeader1)': 'abc',
|
|
67
|
+
hdr_x_myheader2: 'def',
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
event: 'response',
|
|
72
|
+
call_id: oc.id,
|
|
73
|
+
method: 'INVITE',
|
|
74
|
+
msg: sip_msg({
|
|
75
|
+
$rs: '100',
|
|
76
|
+
$rr: 'Trying',
|
|
77
|
+
'$(hdrcnt(via))': 1,
|
|
78
|
+
'$hdr(call-id)': m.collect('sip_call_id'),
|
|
79
|
+
$fU: 'alice',
|
|
80
|
+
$fd: 'test.com',
|
|
81
|
+
$tU: 'bob',
|
|
82
|
+
'$hdr(l)': '0',
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
], 1000)
|
|
86
|
+
// Details about zeq wait(list_of_events_to_wait_for, timeout_in_ms):
|
|
87
|
+
// The order of events in the list is irrelevant.
|
|
88
|
+
// What matters is that all events arrive within the specified timeout.
|
|
89
|
+
// When specifying events, you can be as detailed or succinct as you need.
|
|
90
|
+
// For example, the above event 'response' is waiting for a SIP '100 Trying' to arrive,
|
|
91
|
+
// but we are specifying several things to match just to show that we can be very detailed when performing a match.
|
|
92
|
+
// But it could have been just like this:
|
|
93
|
+
//
|
|
94
|
+
// {
|
|
95
|
+
// event: 'response',
|
|
96
|
+
// call_id: oc.id,
|
|
97
|
+
// method: 'INVITE',
|
|
98
|
+
// msg: sip_msg({
|
|
99
|
+
// $rs: '100',
|
|
100
|
+
// }),
|
|
101
|
+
// }
|
|
102
|
+
// Regarding the function sip_msg(), this is a special matching function provided by https://github.com/MayamaTakeshi/sip-matching that makes it
|
|
103
|
+
// easy to match a SIP message using openser/kamailio/opensips pseudo-variables syntax.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// Here we store data for the incoming call
|
|
107
|
+
// just to organize our code (not really needed)
|
|
108
|
+
const ic = {
|
|
109
|
+
id: z.store.call_id,
|
|
110
|
+
sip_call_id: z.store.sip_call_id,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Now we answer the call at t2 side sending custom headers.
|
|
114
|
+
sip.call.respond(ic.id, {
|
|
115
|
+
code: 200,
|
|
116
|
+
reason: 'OK',
|
|
117
|
+
headers: {
|
|
118
|
+
'X-MyHeader3': 'ABC',
|
|
119
|
+
'X-MyHeader4': 'DEF',
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// Then we wait for the '200 OK' at the t1 side with the custom headers.
|
|
124
|
+
// We will also get event 'media_update' for both sides indicating media streams (RTP) were set up successfully
|
|
125
|
+
await z.wait([
|
|
126
|
+
{
|
|
127
|
+
event: 'response',
|
|
128
|
+
call_id: oc.id,
|
|
129
|
+
method: 'INVITE',
|
|
130
|
+
msg: sip_msg({
|
|
131
|
+
$rs: '200',
|
|
132
|
+
$rr: 'OK',
|
|
133
|
+
'$(hdrcnt(VIA))': 1,
|
|
134
|
+
$fU: 'alice',
|
|
135
|
+
$fd: 'test.com',
|
|
136
|
+
$tU: 'bob',
|
|
137
|
+
'$hdr(content-type)': 'application/sdp',
|
|
138
|
+
$rb: '!{_}a=sendrecv',
|
|
139
|
+
'$hdr(X-MyHeader3)': 'ABC',
|
|
140
|
+
hdr_x_myheader4: 'DEF',
|
|
141
|
+
}),
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
event: 'media_update',
|
|
145
|
+
call_id: oc.id,
|
|
146
|
+
status: 'ok',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
event: 'media_update',
|
|
150
|
+
call_id: ic.id,
|
|
151
|
+
status: 'ok',
|
|
152
|
+
},
|
|
153
|
+
], 1000)
|
|
154
|
+
|
|
155
|
+
// now we terminate the call from t1 side
|
|
156
|
+
sip.call.terminate(oc.id)
|
|
157
|
+
|
|
158
|
+
// and wait for termination events
|
|
159
|
+
await z.wait([
|
|
160
|
+
{
|
|
161
|
+
event: 'response',
|
|
162
|
+
call_id: oc.id,
|
|
163
|
+
method: 'BYE',
|
|
164
|
+
msg: sip_msg({
|
|
165
|
+
$rs: '200',
|
|
166
|
+
$rr: 'OK',
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
event: 'call_ended',
|
|
171
|
+
call_id: oc.id,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
event: 'call_ended',
|
|
175
|
+
call_id: ic.id,
|
|
176
|
+
},
|
|
177
|
+
], 1000)
|
|
178
|
+
|
|
179
|
+
console.log("Success")
|
|
180
|
+
|
|
181
|
+
sip.stop()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
test()
|
|
186
|
+
.catch(e => {
|
|
187
|
+
console.error(e)
|
|
188
|
+
process.exit(1)
|
|
189
|
+
})
|
|
190
|
+
|