sip-lab 1.13.1 → 1.15.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.
@@ -3,9 +3,9 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var mrcp = require('mrcp')
7
8
  var mrcp_msg = require('mrcp-matching')
8
- var sdp_msg = require('sdp-matching')
9
9
 
10
10
  async function test() {
11
11
  sip.set_log_level(9)
@@ -115,7 +115,7 @@ async function test() {
115
115
  $fd: 'test.com',
116
116
  $tU: 'bob',
117
117
  '$hdr(content-type)': 'application/sdp',
118
- $rb: sdp_msg({
118
+ $rb: sdp.jsonpath_matcher({
119
119
  '$.media[?(@.desc.type=="application")].val_attrs.channel': [m.collect('mrcp_channel')],
120
120
  }),
121
121
  }),
@@ -407,8 +407,6 @@ async function test() {
407
407
  },
408
408
  ], 500)
409
409
 
410
- await z.sleep(1000) // we need this delay otherwise, frequently the app will crash after this point.
411
-
412
410
  sip.call.terminate(oc.id)
413
411
 
414
412
  await z.wait([
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  sip.set_log_level(9)
@@ -235,8 +236,6 @@ async function test() {
235
236
  //await z.sleep(100)
236
237
  }
237
238
 
238
- await z.sleep(1000) // we need this delay otherwise, frequently the app will crash after this point.
239
-
240
239
  sip.call.terminate(oc.id)
241
240
 
242
241
  await z.wait([
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(6)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  sip.set_log_level(6)
@@ -0,0 +1,346 @@
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
+ const sdp = require('sdp-matching')
8
+
9
+ // here we create our Zeq instance
10
+ var z = new Zeq()
11
+
12
+ async function test() {
13
+ sip.dtmf_aggregation_on(500)
14
+
15
+ z.trap_events(sip.event_source, 'event', (evt) => {
16
+ var e = evt.args[0]
17
+ return e
18
+ })
19
+
20
+ // Let's ignore '100 Trying'
21
+ z.add_event_filter({
22
+ event: 'response',
23
+ msg: sip_msg({
24
+ $rs: '100',
25
+ }),
26
+ })
27
+
28
+ console.log(sip.start((data) => { console.log(data)} ))
29
+
30
+ const t1 = sip.transport.create({address: "127.0.0.1"})
31
+ const t2 = sip.transport.create({address: "127.0.0.1"})
32
+
33
+ console.log("t1", t1)
34
+ console.log("t2", t2)
35
+
36
+ const oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`,
37
+ media: [
38
+ {
39
+ type: 'audio',
40
+ secure: true,
41
+ },
42
+ ]})
43
+
44
+ await z.wait([
45
+ {
46
+ event: "incoming_call",
47
+ call_id: m.collect("call_id"),
48
+ transport_id: t2.id,
49
+ },
50
+ ], 1000)
51
+
52
+ const ic = {
53
+ id: z.store.call_id,
54
+ sip_call_id: z.store.sip_call_id,
55
+ }
56
+
57
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: [
58
+ {
59
+ type: 'audio',
60
+ secure: true,
61
+ },
62
+ ]})
63
+
64
+ await z.wait([
65
+ {
66
+ event: 'response',
67
+ call_id: oc.id,
68
+ method: 'INVITE',
69
+ msg: sip_msg({
70
+ $rs: '200',
71
+ $rr: 'OK',
72
+ '$(hdrcnt(VIA))': 1,
73
+ $fU: 'alice',
74
+ $fd: 'test.com',
75
+ $tU: 'bob',
76
+ '$hdr(content-type)': 'application/sdp',
77
+ $rb: '!{_}a=sendrecv',
78
+ }),
79
+ },
80
+ {
81
+ event: 'media_update',
82
+ call_id: oc.id,
83
+ status: 'ok',
84
+ },
85
+ {
86
+ event: 'media_update',
87
+ call_id: ic.id,
88
+ status: 'ok',
89
+ },
90
+ ], 1000)
91
+
92
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 1})
93
+ sip.call.send_dtmf(ic.id, {digits: '1234', mode: 1})
94
+
95
+ await z.wait([
96
+ {
97
+ event: 'dtmf',
98
+ call_id: ic.id,
99
+ digits: '1234',
100
+ mode: 1,
101
+ media_id: 0,
102
+ },
103
+ {
104
+ event: 'dtmf',
105
+ call_id: oc.id,
106
+ digits: '1234',
107
+ mode: 1,
108
+ media_id: 0,
109
+ },
110
+ ], 2000)
111
+
112
+ sip.call.reinvite(oc.id, {media: [
113
+ {
114
+ type: 'audio',
115
+ secure: true,
116
+ },
117
+ ]})
118
+
119
+ await z.wait([
120
+ {
121
+ event: 'reinvite',
122
+ call_id: ic.id,
123
+ },
124
+ ], 500)
125
+
126
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: [
127
+ {
128
+ type: 'audio',
129
+ secure: true,
130
+ },
131
+ ]})
132
+
133
+ await z.wait([
134
+ {
135
+ event: 'response',
136
+ call_id: oc.id,
137
+ method: 'INVITE',
138
+ msg: sip_msg({
139
+ $rs: '200',
140
+ $rb: sdp.jsonpath_matcher({
141
+ '$.media.length': [1],
142
+ '$.media[*].desc.type': ['audio'],
143
+ '$.media[*].desc.port': [m.nonzero],
144
+ '$.media[*].desc.protocol': ['RTP/SAVP'],
145
+ }),
146
+ }),
147
+ },
148
+ {
149
+ event: 'media_update',
150
+ call_id: ic.id,
151
+ status: 'ok',
152
+ media: m.fm([
153
+ m.pm({
154
+ type: 'audio',
155
+ transport: 'RTP/SAVP',
156
+ local: {
157
+ mode: 'sendrecv'
158
+ },
159
+ remote: {
160
+ mode: 'sendrecv'
161
+ },
162
+ fmt: [
163
+ '0 PCMU/8000',
164
+ '120 telephone-event/8000'
165
+ ]
166
+ }),
167
+ ]),
168
+ },
169
+ {
170
+ event: 'media_update',
171
+ call_id: oc.id,
172
+ status: 'ok',
173
+ media: m.fm([
174
+ m.pm({
175
+ type: 'audio',
176
+ transport: 'RTP/SAVP',
177
+ local: {
178
+ mode: 'sendrecv'
179
+ },
180
+ remote: {
181
+ mode: 'sendrecv'
182
+ },
183
+ fmt: [
184
+ '0 PCMU/8000',
185
+ '120 telephone-event/8000'
186
+ ]
187
+ }),
188
+ ]),
189
+ },
190
+ ], 1000)
191
+
192
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 1})
193
+ sip.call.send_dtmf(ic.id, {digits: '1234', mode: 1})
194
+
195
+ await z.wait([
196
+ {
197
+ event: 'dtmf',
198
+ call_id: ic.id,
199
+ digits: '1234',
200
+ mode: 1,
201
+ media_id: 0,
202
+ },
203
+ {
204
+ event: 'dtmf',
205
+ call_id: oc.id,
206
+ digits: '1234',
207
+ mode: 1,
208
+ media_id: 0,
209
+ },
210
+ ], 2000)
211
+
212
+
213
+ sip.call.reinvite(ic.id, {media: [
214
+ {
215
+ type: 'audio',
216
+ secure: true,
217
+ },
218
+ ]})
219
+
220
+ await z.wait([
221
+ {
222
+ event: 'reinvite',
223
+ call_id: oc.id,
224
+ },
225
+ ], 500)
226
+
227
+ sip.call.respond(oc.id, {code: 200, reason: 'OK', media: [
228
+ {
229
+ type: 'audio',
230
+ secure: true,
231
+ },
232
+ ]})
233
+
234
+ await z.wait([
235
+ {
236
+ event: 'response',
237
+ call_id: ic.id,
238
+ method: 'INVITE',
239
+ msg: sip_msg({
240
+ $rs: '200',
241
+ $rb: sdp.jsonpath_matcher({
242
+ '$.media.length': [1],
243
+ '$.media[*].desc.type': ['audio'],
244
+ '$.media[*].desc.port': [m.nonzero],
245
+ '$.media[*].desc.protocol': ['RTP/SAVP'],
246
+ }),
247
+ }),
248
+ },
249
+ {
250
+ event: 'media_update',
251
+ call_id: oc.id,
252
+ status: 'ok',
253
+ media: m.fm([
254
+ m.pm({
255
+ type: 'audio',
256
+ transport: 'RTP/SAVP',
257
+ local: {
258
+ mode: 'sendrecv'
259
+ },
260
+ remote: {
261
+ mode: 'sendrecv'
262
+ },
263
+ fmt: [
264
+ '0 PCMU/8000',
265
+ '120 telephone-event/8000'
266
+ ]
267
+ }),
268
+ ]),
269
+ },
270
+ {
271
+ event: 'media_update',
272
+ call_id: ic.id,
273
+ status: 'ok',
274
+ media: m.fm([
275
+ m.pm({
276
+ type: 'audio',
277
+ transport: 'RTP/SAVP',
278
+ local: {
279
+ mode: 'sendrecv'
280
+ },
281
+ remote: {
282
+ mode: 'sendrecv'
283
+ },
284
+ fmt: [
285
+ '0 PCMU/8000',
286
+ '120 telephone-event/8000'
287
+ ]
288
+ }),
289
+ ]),
290
+ },
291
+ ], 1000)
292
+
293
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 1})
294
+ sip.call.send_dtmf(ic.id, {digits: '1234', mode: 1})
295
+
296
+ await z.wait([
297
+ {
298
+ event: 'dtmf',
299
+ call_id: ic.id,
300
+ digits: '1234',
301
+ mode: 1,
302
+ media_id: 0,
303
+ },
304
+ {
305
+ event: 'dtmf',
306
+ call_id: oc.id,
307
+ digits: '1234',
308
+ mode: 1,
309
+ media_id: 0,
310
+ },
311
+ ], 2000)
312
+
313
+ sip.call.terminate(oc.id)
314
+
315
+ await z.wait([
316
+ {
317
+ event: 'response',
318
+ call_id: oc.id,
319
+ method: 'BYE',
320
+ msg: sip_msg({
321
+ $rs: '200',
322
+ $rr: 'OK',
323
+ }),
324
+ },
325
+ {
326
+ event: 'call_ended',
327
+ call_id: oc.id,
328
+ },
329
+ {
330
+ event: 'call_ended',
331
+ call_id: ic.id,
332
+ },
333
+ ], 1000)
334
+
335
+ console.log("Success")
336
+
337
+ sip.stop()
338
+ }
339
+
340
+
341
+ test()
342
+ .catch(e => {
343
+ console.error(e)
344
+ process.exit(1)
345
+ })
346
+
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(6)