sip-lab 1.12.39 → 1.13.1

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.
Files changed (40) hide show
  1. package/DEV.md +19 -3
  2. package/README.md +8 -4
  3. package/binding.gyp +97 -86
  4. package/build_deps.sh +3 -2
  5. package/index.js +14 -7
  6. package/package.json +7 -2
  7. package/prebuilds/linux-x64/node.abi102.node +0 -0
  8. package/prebuilds/linux-x64/node.abi108.node +0 -0
  9. package/prebuilds/linux-x64/node.abi88.node +0 -0
  10. package/prebuilds/linux-x64/node.abi93.node +0 -0
  11. package/samples/16_audio_streams.js +179 -0
  12. package/samples/delayed_media.js +117 -81
  13. package/samples/g729.js +50 -28
  14. package/samples/mrcp_and_audio.js +445 -0
  15. package/samples/mrcp_and_audio.simplified_media.js +273 -0
  16. package/samples/mrcp_and_audio.switching_order.js +273 -0
  17. package/samples/options.js +82 -0
  18. package/samples/refer.js +247 -0
  19. package/samples/refuse_telephone_event.js +166 -0
  20. package/samples/register_no_expires.js +82 -0
  21. package/samples/register_subscribe.js +36 -4
  22. package/samples/reinvite_and_dtmf.js +236 -161
  23. package/samples/reinvite_audio_audio.js +320 -0
  24. package/samples/reinvite_with_hold_unhold.js +412 -0
  25. package/samples/send_and_receive_fax.js +4 -8
  26. package/samples/simple.js +5 -9
  27. package/samples/sip_cancel.js +4 -6
  28. package/samples/tcp_and_extra_headers.js +98 -45
  29. package/samples/two_audio_media.js +497 -0
  30. package/src/addon.cpp +488 -268
  31. package/src/event_templates.cpp +84 -35
  32. package/src/event_templates.hpp +22 -12
  33. package/src/idmanager.cpp +58 -57
  34. package/src/idmanager.hpp +10 -10
  35. package/src/log.cpp +9 -11
  36. package/src/log.hpp +4 -4
  37. package/src/sip.cpp +6841 -5040
  38. package/src/sip.hpp +26 -34
  39. package/src/packetdumper.cpp +0 -234
  40. package/src/packetdumper.hpp +0 -67
@@ -0,0 +1,497 @@
1
+ var sip = require ('../index.js')
2
+ var Zeq = require('@mayama/zeq')
3
+ var z = new Zeq()
4
+ var m = require('data-matching')
5
+ var sip_msg = require('sip-matching')
6
+
7
+ async function test() {
8
+ sip.set_log_level(9)
9
+
10
+ //sip.set_log_level(6)
11
+ sip.dtmf_aggregation_on(500)
12
+
13
+ // Let's ignore '100 Trying'
14
+ z.add_event_filter({
15
+ event: 'response',
16
+ msg: sip_msg({
17
+ $rs: '100',
18
+ }),
19
+ })
20
+
21
+ z.trap_events(sip.event_source, 'event', (evt) => {
22
+ var e = evt.args[0]
23
+ return e
24
+ })
25
+
26
+ console.log(sip.start((data) => { console.log(data)} ))
27
+
28
+ t1 = sip.transport.create({address: "127.0.0.1", port: 5090, type: 'udp'})
29
+ t2 = sip.transport.create({address: "127.0.0.1", port: 5092, type: 'udp'})
30
+
31
+ console.log("t1", t1)
32
+ console.log("t2", t2)
33
+
34
+ oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`, media: "audio,audio"})
35
+
36
+ await z.wait([
37
+ {
38
+ event: "incoming_call",
39
+ call_id: m.collect("call_id"),
40
+ },
41
+ ], 1000)
42
+
43
+ ic = {
44
+ id: z.store.call_id,
45
+ sip_call_id: z.store.sip_call_id,
46
+ }
47
+
48
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio,audio"})
49
+
50
+ await z.wait([
51
+ {
52
+ event: 'response',
53
+ call_id: oc.id,
54
+ method: 'INVITE',
55
+ msg: sip_msg({
56
+ $rs: '200',
57
+ $rr: 'OK',
58
+ '$(hdrcnt(VIA))': 1,
59
+ $fU: 'alice',
60
+ $fd: 'test.com',
61
+ $tU: 'bob',
62
+ '$hdr(content-type)': 'application/sdp',
63
+ $rb: '!{_}a=sendrecv',
64
+ }),
65
+ },
66
+ {
67
+ event: 'media_update',
68
+ call_id: oc.id,
69
+ status: 'ok',
70
+ media: [
71
+ {
72
+ type: 'audio',
73
+ },
74
+ {
75
+ type: 'audio',
76
+ }
77
+ ],
78
+ },
79
+ {
80
+ event: 'media_update',
81
+ call_id: ic.id,
82
+ status: 'ok',
83
+ media: [
84
+ {
85
+ type: 'audio',
86
+ },
87
+ {
88
+ type: 'audio',
89
+ }
90
+ ],
91
+ },
92
+ ], 1000)
93
+
94
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
95
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
96
+
97
+ await z.wait([
98
+ {
99
+ event: 'dtmf',
100
+ call_id: ic.id,
101
+ digits: '1234',
102
+ mode: 0,
103
+ media_id: 0
104
+ },
105
+ {
106
+ event: 'dtmf',
107
+ call_id: oc.id,
108
+ digits: '4321',
109
+ mode: 1,
110
+ media_id: 0
111
+ },
112
+ {
113
+ event: 'dtmf',
114
+ call_id: ic.id,
115
+ digits: '1234',
116
+ mode: 0,
117
+ media_id: 1
118
+ },
119
+ {
120
+ event: 'dtmf',
121
+ call_id: oc.id,
122
+ digits: '4321',
123
+ mode: 1,
124
+ media_id: 1
125
+ },
126
+ ], 2000)
127
+
128
+ sip.call.reinvite(oc.id, {media: "audio,audio"})
129
+
130
+ await z.wait([
131
+ {
132
+ event: 'reinvite',
133
+ call_id: ic.id,
134
+ },
135
+ ], 1000)
136
+
137
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio,audio"})
138
+
139
+ await z.wait([
140
+ {
141
+ event: 'response',
142
+ call_id: oc.id,
143
+ method: 'INVITE',
144
+ msg: sip_msg({
145
+ $rs: '200',
146
+ }),
147
+ },
148
+ {
149
+ event: 'media_update',
150
+ call_id: ic.id,
151
+ status: 'ok',
152
+ media: [
153
+ {
154
+ type: 'audio',
155
+ local: {
156
+ addr: '127.0.0.1',
157
+ port: 10004,
158
+ mode: 'sendrecv'
159
+ },
160
+ remote: {
161
+ addr: '127.0.0.1',
162
+ port: 10000,
163
+ mode: 'sendrecv'
164
+ },
165
+ fmt: [
166
+ '0 PCMU/8000',
167
+ '120 telephone-event/8000'
168
+ ]
169
+ },
170
+ {
171
+ type: 'audio',
172
+ local: {
173
+ addr: '127.0.0.1',
174
+ port: 10006,
175
+ mode: 'sendrecv'
176
+ },
177
+ remote: {
178
+ addr: '127.0.0.1',
179
+ port: 10002,
180
+ mode: 'sendrecv'
181
+ },
182
+ fmt: [
183
+ '0 PCMU/8000',
184
+ '120 telephone-event/8000'
185
+ ]
186
+ }
187
+ ]
188
+ },
189
+ {
190
+ event: 'media_update',
191
+ call_id: oc.id,
192
+ status: 'ok',
193
+ media: [
194
+ {
195
+ type: 'audio',
196
+ local: {
197
+ addr: '127.0.0.1',
198
+ port: 10000,
199
+ mode: 'sendrecv'
200
+ },
201
+ remote: {
202
+ addr: '127.0.0.1',
203
+ port: 10004,
204
+ mode: 'sendrecv'
205
+ },
206
+ fmt: [
207
+ '0 PCMU/8000',
208
+ '120 telephone-event/8000'
209
+ ]
210
+ },
211
+ {
212
+ type: 'audio',
213
+ local: {
214
+ addr: '127.0.0.1',
215
+ port: 10002,
216
+ mode: 'sendrecv'
217
+ },
218
+ remote: {
219
+ addr: '127.0.0.1',
220
+ port: 10006,
221
+ mode: 'sendrecv'
222
+ },
223
+ fmt: [
224
+ '0 PCMU/8000',
225
+ '120 telephone-event/8000'
226
+ ]
227
+ }
228
+ ]
229
+ },
230
+ ], 1000)
231
+
232
+ await z.sleep(100)
233
+
234
+ // Now change to single media
235
+ sip.call.reinvite(oc.id, {media: "audio"})
236
+
237
+ await z.wait([
238
+ {
239
+ event: 'reinvite',
240
+ call_id: ic.id,
241
+ },
242
+ ], 1000)
243
+
244
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio,audio"})
245
+
246
+ await z.wait([
247
+ {
248
+ event: 'response',
249
+ call_id: oc.id,
250
+ method: 'INVITE',
251
+ msg: sip_msg({
252
+ $rs: '200',
253
+ }),
254
+ },
255
+ {
256
+ event: 'media_update',
257
+ call_id: ic.id,
258
+ status: 'ok',
259
+ media: [
260
+ {
261
+ type: 'audio',
262
+ local: {
263
+ addr: '127.0.0.1',
264
+ port: 10004,
265
+ mode: 'sendrecv'
266
+ },
267
+ remote: {
268
+ addr: '127.0.0.1',
269
+ port: 10000,
270
+ mode: 'sendrecv'
271
+ },
272
+ fmt: [
273
+ '0 PCMU/8000',
274
+ '120 telephone-event/8000'
275
+ ]
276
+ },
277
+ ]
278
+ },
279
+ {
280
+ event: 'media_update',
281
+ call_id: oc.id,
282
+ status: 'ok',
283
+ media: [
284
+ {
285
+ type: 'audio',
286
+ local: {
287
+ addr: '127.0.0.1',
288
+ port: 10000,
289
+ mode: 'sendrecv'
290
+ },
291
+ remote: {
292
+ addr: '127.0.0.1',
293
+ port: 10004,
294
+ mode: 'sendrecv'
295
+ },
296
+ fmt: [
297
+ '0 PCMU/8000',
298
+ '120 telephone-event/8000'
299
+ ]
300
+ },
301
+ ]
302
+ },
303
+ ], 1000)
304
+
305
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
306
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
307
+
308
+ await z.wait([
309
+ {
310
+ event: 'dtmf',
311
+ call_id: ic.id,
312
+ digits: '1234',
313
+ mode: 0,
314
+ media_id: 0
315
+ },
316
+ {
317
+ event: 'dtmf',
318
+ call_id: oc.id,
319
+ digits: '4321',
320
+ mode: 1,
321
+ media_id: 0
322
+ },
323
+ ], 1500)
324
+
325
+ // now switch back to two media
326
+ sip.call.reinvite(oc.id, {media: "audio,audio"})
327
+
328
+ await z.wait([
329
+ {
330
+ event: 'reinvite',
331
+ call_id: ic.id,
332
+ },
333
+ ], 1000)
334
+
335
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio,audio"})
336
+
337
+ await z.wait([
338
+ {
339
+ event: 'response',
340
+ call_id: oc.id,
341
+ method: 'INVITE',
342
+ msg: sip_msg({
343
+ $rs: '200',
344
+ }),
345
+ },
346
+ {
347
+ event: 'media_update',
348
+ call_id: ic.id,
349
+ status: 'ok',
350
+ media: [
351
+ {
352
+ type: 'audio',
353
+ local: {
354
+ addr: '127.0.0.1',
355
+ port: 10004,
356
+ mode: 'sendrecv'
357
+ },
358
+ remote: {
359
+ addr: '127.0.0.1',
360
+ port: 10000,
361
+ mode: 'sendrecv'
362
+ },
363
+ fmt: [
364
+ '0 PCMU/8000',
365
+ '120 telephone-event/8000'
366
+ ]
367
+ },
368
+ {
369
+ type: 'audio',
370
+ local: {
371
+ addr: '127.0.0.1',
372
+ port: 10006,
373
+ mode: 'sendrecv'
374
+ },
375
+ remote: {
376
+ addr: '127.0.0.1',
377
+ port: 10002,
378
+ mode: 'sendrecv'
379
+ },
380
+ fmt: [
381
+ '0 PCMU/8000',
382
+ '120 telephone-event/8000'
383
+ ]
384
+ }
385
+ ]
386
+ },
387
+ {
388
+ event: 'media_update',
389
+ call_id: oc.id,
390
+ status: 'ok',
391
+ media: [
392
+ {
393
+ type: 'audio',
394
+ local: {
395
+ addr: '127.0.0.1',
396
+ port: 10000,
397
+ mode: 'sendrecv'
398
+ },
399
+ remote: {
400
+ addr: '127.0.0.1',
401
+ port: 10004,
402
+ mode: 'sendrecv'
403
+ },
404
+ fmt: [
405
+ '0 PCMU/8000',
406
+ '120 telephone-event/8000'
407
+ ]
408
+ },
409
+ {
410
+ type: 'audio',
411
+ local: {
412
+ addr: '127.0.0.1',
413
+ port: 10002,
414
+ mode: 'sendrecv'
415
+ },
416
+ remote: {
417
+ addr: '127.0.0.1',
418
+ port: 10006,
419
+ mode: 'sendrecv'
420
+ },
421
+ fmt: [
422
+ '0 PCMU/8000',
423
+ '120 telephone-event/8000'
424
+ ]
425
+ }
426
+ ]
427
+ },
428
+ ], 1000)
429
+
430
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
431
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
432
+
433
+ await z.wait([
434
+ {
435
+ event: 'dtmf',
436
+ call_id: ic.id,
437
+ digits: '1234',
438
+ mode: 0,
439
+ media_id: 0
440
+ },
441
+ {
442
+ event: 'dtmf',
443
+ call_id: oc.id,
444
+ digits: '4321',
445
+ mode: 1,
446
+ media_id: 0
447
+ },
448
+ {
449
+ event: 'dtmf',
450
+ call_id: ic.id,
451
+ digits: '1234',
452
+ mode: 0,
453
+ media_id: 1
454
+ },
455
+ {
456
+ event: 'dtmf',
457
+ call_id: oc.id,
458
+ digits: '4321',
459
+ mode: 1,
460
+ media_id: 1
461
+ },
462
+ ], 2000)
463
+
464
+ sip.call.terminate(oc.id)
465
+
466
+ await z.wait([
467
+ {
468
+ event: 'call_ended',
469
+ call_id: oc.id,
470
+ },
471
+ {
472
+ event: 'call_ended',
473
+ call_id: ic.id,
474
+ },
475
+ {
476
+ event: 'response',
477
+ call_id: oc.id,
478
+ method: 'BYE',
479
+ msg: sip_msg({
480
+ $rs: '200',
481
+ $rr: 'OK',
482
+ }),
483
+ },
484
+ ], 1000)
485
+
486
+ console.log("Success")
487
+
488
+ sip.stop()
489
+ }
490
+
491
+
492
+ test()
493
+ .catch(e => {
494
+ console.error(e)
495
+ process.exit(1)
496
+ })
497
+