sip-lab 1.30.0 → 1.32.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.
Files changed (60) hide show
  1. package/index.js +5 -5
  2. package/package.json +2 -2
  3. package/prebuilds/linux-x64/node.abi102.node +0 -0
  4. package/prebuilds/linux-x64/node.abi108.node +0 -0
  5. package/prebuilds/linux-x64/node.abi111.node +0 -0
  6. package/prebuilds/linux-x64/node.abi115.node +0 -0
  7. package/prebuilds/linux-x64/node.abi120.node +0 -0
  8. package/prebuilds/linux-x64/node.abi88.node +0 -0
  9. package/prebuilds/linux-x64/node.abi93.node +0 -0
  10. package/samples/100_calls.js +1 -0
  11. package/samples/16_audio_streams.js +1 -0
  12. package/samples/183_session_progress.js +1 -0
  13. package/samples/custom_call_id.js +220 -0
  14. package/samples/custom_call_id_and_from_tag.js.future +224 -0
  15. package/samples/delayed_media.js +1 -0
  16. package/samples/four_audio_streams_two_refused.js +1 -0
  17. package/samples/g729.js +1 -0
  18. package/samples/media_fields.js +191 -0
  19. package/samples/mrcp_and_audio.js +1 -12
  20. package/samples/mrcp_and_audio.simplified_media.js +1 -0
  21. package/samples/multiple_audio_streams.js +1 -0
  22. package/samples/options.js +1 -0
  23. package/samples/pcma.js +1 -0
  24. package/samples/play_wav_and_speech_recog.bad_transcript.pcmu8000.js +1 -0
  25. package/samples/refer.js +1 -0
  26. package/samples/refuse_telephone_event.js +1 -0
  27. package/samples/register_no_expires.js +1 -0
  28. package/samples/register_subscribe.js +1 -0
  29. package/samples/reinvite_and_dtmf.js +1 -0
  30. package/samples/reinvite_audio_audio.js +1 -0
  31. package/samples/reinvite_with_hold_unhold.js +1 -0
  32. package/samples/rtp_and_srtp.js +1 -0
  33. package/samples/rtp_and_srtp.rtp_refused.js +1 -0
  34. package/samples/rtp_and_srtp.unbalanced_sdp_answer.js.future +1 -0
  35. package/samples/send_and_receive_bfsk.js.future +1 -0
  36. package/samples/send_and_receive_fax.js +1 -0
  37. package/samples/session_expires.update.js.future +269 -0
  38. package/samples/session_expires.update.with_sipjs-lab.js +329 -0
  39. package/samples/simple.js +1 -0
  40. package/samples/sip_cancel.js +1 -0
  41. package/samples/speech_synth_and_recog.speex16000.js +1 -0
  42. package/samples/srtp.js +1 -0
  43. package/samples/start_play_wav_with_end_of_file_event.js +1 -0
  44. package/samples/start_play_wav_with_no_loop.js +1 -0
  45. package/samples/stop_with_cleanup.js +127 -0
  46. package/samples/tcp.js +1 -0
  47. package/samples/text_to_speech.js +1 -0
  48. package/samples/tls.js +1 -0
  49. package/samples/two_audio_streams.js +1 -0
  50. package/samples/two_audio_streams.port_zero.js +1 -0
  51. package/samples_extra/ws_speech_server.bfsk.js +1 -0
  52. package/samples_extra/ws_speech_server.dtmf.js +1 -0
  53. package/samples_extra/ws_speech_server.google.js +1 -0
  54. package/samples_extra/ws_speech_server.send_bfsk.js +1 -0
  55. package/samples_extra/ws_speech_server.start_bfsk_detection.js.future +1 -0
  56. package/src/addon.cpp +44 -1
  57. package/src/idmanager.cpp +4 -0
  58. package/src/idmanager.hpp +1 -0
  59. package/src/sip.cpp +253 -141
  60. package/src/sip.hpp +3 -1
@@ -0,0 +1,191 @@
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
+ process.exit(0)
183
+ }
184
+
185
+
186
+ test()
187
+ .catch(e => {
188
+ console.error(e)
189
+ process.exit(1)
190
+ })
191
+
@@ -128,11 +128,9 @@ async function test() {
128
128
  {
129
129
  type: 'audio',
130
130
  local: {
131
- port: 10000,
132
131
  mode: 'recvonly'
133
132
  },
134
133
  remote: {
135
- port: 10002,
136
134
  mode: 'sendonly'
137
135
  }
138
136
  }
@@ -155,11 +153,9 @@ async function test() {
155
153
  {
156
154
  type: 'audio',
157
155
  local: {
158
- port: 10002,
159
156
  mode: 'sendonly'
160
157
  },
161
158
  remote: {
162
- port: 10000,
163
159
  mode: 'recvonly'
164
160
  }
165
161
  }
@@ -273,11 +269,9 @@ async function test() {
273
269
  {
274
270
  type: 'audio',
275
271
  local: {
276
- port: 10000,
277
272
  mode: 'recvonly'
278
273
  },
279
274
  remote: {
280
- port: 10002,
281
275
  mode: 'sendonly'
282
276
  }
283
277
  }
@@ -300,11 +294,9 @@ async function test() {
300
294
  {
301
295
  type: 'audio',
302
296
  local: {
303
- port: 10002,
304
297
  mode: 'sendonly'
305
298
  },
306
299
  remote: {
307
- port: 10000,
308
300
  mode: 'recvonly'
309
301
  }
310
302
  }
@@ -359,11 +351,9 @@ async function test() {
359
351
  {
360
352
  type: 'audio',
361
353
  local: {
362
- port: 10000,
363
354
  mode: 'recvonly'
364
355
  },
365
356
  remote: {
366
- port: 10002,
367
357
  mode: 'sendonly'
368
358
  }
369
359
  }
@@ -386,11 +376,9 @@ async function test() {
386
376
  {
387
377
  type: 'audio',
388
378
  local: {
389
- port: 10002,
390
379
  mode: 'sendonly'
391
380
  },
392
381
  remote: {
393
- port: 10000,
394
382
  mode: 'recvonly'
395
383
  }
396
384
  }
@@ -423,6 +411,7 @@ async function test() {
423
411
  console.log("Success")
424
412
 
425
413
  sip.stop()
414
+ process.exit(0)
426
415
  }
427
416
 
428
417
 
@@ -254,6 +254,7 @@ async function test() {
254
254
  console.log("Success")
255
255
 
256
256
  sip.stop()
257
+ process.exit(0)
257
258
  }
258
259
 
259
260
 
@@ -144,6 +144,7 @@ async function test() {
144
144
  console.log("Success")
145
145
 
146
146
  sip.stop()
147
+ process.exit(0)
147
148
  }
148
149
 
149
150
 
@@ -72,6 +72,7 @@ async function test() {
72
72
  console.log("Success")
73
73
 
74
74
  sip.stop()
75
+ process.exit(0)
75
76
  }
76
77
 
77
78
 
package/samples/pcma.js CHANGED
@@ -197,6 +197,7 @@ async function test() {
197
197
  console.log("Success")
198
198
 
199
199
  sip.stop()
200
+ process.exit(0)
200
201
  }
201
202
 
202
203
  test()
@@ -148,6 +148,7 @@ async function test() {
148
148
  console.log("Success")
149
149
 
150
150
  sip.stop()
151
+ process.exit(0)
151
152
  }
152
153
 
153
154
 
package/samples/refer.js CHANGED
@@ -206,6 +206,7 @@ async function test() {
206
206
  console.log("Success")
207
207
 
208
208
  sip.stop()
209
+ process.exit(0)
209
210
  }
210
211
 
211
212
 
@@ -148,6 +148,7 @@ async function test() {
148
148
  console.log("Success")
149
149
 
150
150
  sip.stop()
151
+ process.exit(0)
151
152
  }
152
153
 
153
154
 
@@ -72,6 +72,7 @@ async function test() {
72
72
  console.log("Success")
73
73
 
74
74
  sip.stop()
75
+ process.exit(0)
75
76
  }
76
77
 
77
78
 
@@ -189,6 +189,7 @@ async function test() {
189
189
  console.log("Success")
190
190
 
191
191
  sip.stop()
192
+ process.exit(0)
192
193
  }
193
194
 
194
195
 
@@ -435,6 +435,7 @@ async function test() {
435
435
  console.log("Success")
436
436
 
437
437
  sip.stop()
438
+ process.exit(0)
438
439
  }
439
440
 
440
441
 
@@ -301,6 +301,7 @@ async function test() {
301
301
  console.log("Success")
302
302
 
303
303
  sip.stop()
304
+ process.exit(0)
304
305
  }
305
306
 
306
307
 
@@ -393,6 +393,7 @@ async function test() {
393
393
  console.log("Success")
394
394
 
395
395
  sip.stop()
396
+ process.exit(0)
396
397
  }
397
398
 
398
399
 
@@ -452,6 +452,7 @@ async function test() {
452
452
  console.log("Success")
453
453
 
454
454
  sip.stop()
455
+ process.exit(0)
455
456
  }
456
457
 
457
458
 
@@ -416,6 +416,7 @@ async function test() {
416
416
  console.log("Success")
417
417
 
418
418
  sip.stop()
419
+ process.exit(0)
419
420
  }
420
421
 
421
422
 
@@ -178,6 +178,7 @@ a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:s6nwVuVNxwupG0Cls+/4X4L46Mx/fqoEMolllU
178
178
  console.log("Success")
179
179
 
180
180
  sip.stop()
181
+ process.exit(0)
181
182
  }
182
183
 
183
184
 
@@ -160,6 +160,7 @@ async function test() {
160
160
  console.log("Success")
161
161
 
162
162
  sip.stop()
163
+ process.exit(0)
163
164
  }
164
165
 
165
166
 
@@ -117,6 +117,7 @@ async function test() {
117
117
  console.log(`Success. Fax file ${in_file} was transmitted and received as ${out_file}`)
118
118
 
119
119
  sip.stop()
120
+ process.exit(0)
120
121
  }
121
122
 
122
123
 
@@ -0,0 +1,269 @@
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
+ $ci: call_id,
51
+ hdr_supported: 'timer',
52
+ hdr_min_se: '180',
53
+ hdr_session_expires: '180',
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
+ hdr_supported: 'timer',
100
+ hdr_min_se: '300',
101
+ hdr_session_expires: '300;refresher=uac',
102
+ }),
103
+ },
104
+ ], 1000)
105
+
106
+ oc = sip.call.create(t1.id, {
107
+ from_uri: 'sip:alice@test.com',
108
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
109
+ headers: {
110
+ 'Call-ID': call_id,
111
+ 'Supported': 'timer',
112
+ 'Min-SE': '300',
113
+ 'Session-Expires': '300',
114
+ },
115
+ })
116
+
117
+ delete z.store.call_id
118
+
119
+ await z.wait([
120
+ {
121
+ event: "incoming_call",
122
+ call_id: m.collect("call_id"),
123
+ transport_id: t2.id,
124
+ msg: sip_msg({
125
+ $rU: 'bob',
126
+ $fU: 'alice',
127
+ $tU: 'bob',
128
+ $fd: 'test.com',
129
+ $ci: call_id,
130
+ hdr_supported: 'timer',
131
+ hdr_min_se: '300',
132
+ hdr_session_expires: '300',
133
+ })
134
+ },
135
+ {
136
+ event: 'response',
137
+ call_id: oc.id,
138
+ method: 'INVITE',
139
+ msg: sip_msg({
140
+ $rs: '100',
141
+ $rr: 'Trying',
142
+ }),
143
+ },
144
+ ], 1000)
145
+
146
+ ic = {
147
+ id: z.store.call_id,
148
+ sip_call_id: z.store.sip_call_id,
149
+ }
150
+
151
+ sip.call.respond(ic.id, {
152
+ code: 200,
153
+ reason: 'OK',
154
+ headers: {
155
+ 'Supported': 'timer',
156
+ 'Min-SE': '300',
157
+ 'Session-Expires': '300;refresher=uac',
158
+ },
159
+ })
160
+
161
+ await z.wait([
162
+ {
163
+ event: 'response',
164
+ call_id: oc.id,
165
+ method: 'INVITE',
166
+ msg: sip_msg({
167
+ $rs: '200',
168
+ $rr: 'OK',
169
+ hdr_supported: 'timer',
170
+ hdr_min_se: '300',
171
+ hdr_session_expires: '300;refresher=uac',
172
+ }),
173
+ },
174
+ {
175
+ event: 'media_update',
176
+ call_id: oc.id,
177
+ status: 'ok',
178
+ },
179
+ {
180
+ event: 'media_update',
181
+ call_id: ic.id,
182
+ status: 'ok',
183
+ },
184
+ ], 1000)
185
+
186
+ await z.sleep(1000)
187
+
188
+ sip.call.update(oc.id, {
189
+ headers: {
190
+ 'Supported': 'timer',
191
+ 'Min-SE': '300',
192
+ 'Session-Expires': '300',
193
+ },
194
+ })
195
+
196
+ await z.wait([
197
+ {
198
+ event: 'request',
199
+ call_id: ic.id,
200
+ msg: sip_msg({
201
+ $rm: 'UPDATE',
202
+ hdr_supported: 'timer',
203
+ hdr_min_se: '300',
204
+ hdr_session_expires: '300',
205
+ }),
206
+ },
207
+ ], 1000)
208
+
209
+ sip.call.respond(ic.id, {
210
+ code: 200,
211
+ reason: 'OK',
212
+ headers: {
213
+ 'Supported': 'timer',
214
+ 'Min-SE': '300',
215
+ 'Session-Expires': '300;refresher=uac',
216
+ },
217
+ })
218
+
219
+ await z.wait([
220
+ {
221
+ event: 'response',
222
+ call_id: oc.id,
223
+ msg: sip_msg({
224
+ $rm: 'UPDATE',
225
+ $rs: '200',
226
+ $rr: 'OK',
227
+ hdr_supported: 'timer',
228
+ hdr_min_se: '300',
229
+ hdr_session_expires: '300;refresher=uac',
230
+ }),
231
+ },
232
+ ], 1000)
233
+
234
+ sip.call.terminate(oc.id)
235
+
236
+ // and wait for termination events
237
+ await z.wait([
238
+ {
239
+ event: 'response',
240
+ call_id: oc.id,
241
+ method: 'BYE',
242
+ msg: sip_msg({
243
+ $rs: '200',
244
+ $rr: 'OK',
245
+ }),
246
+ },
247
+ {
248
+ event: 'call_ended',
249
+ call_id: oc.id,
250
+ },
251
+ {
252
+ event: 'call_ended',
253
+ call_id: ic.id,
254
+ },
255
+ ], 1000)
256
+
257
+ console.log("Success")
258
+
259
+ sip.stop()
260
+ process.exit(0)
261
+ }
262
+
263
+
264
+ test()
265
+ .catch(e => {
266
+ console.error(e)
267
+ process.exit(1)
268
+ })
269
+