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,329 @@
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
+ const sipjs = require('sipjs-lab')
8
+ const {endpoint, dialog, sip_msg: sipjs_sip_msg} = require('sipjs-lab')
9
+
10
+ // here we create our Zeq instance
11
+
12
+ var z = new Zeq()
13
+
14
+ async function test() {
15
+ z.trap_events(sip.event_source, 'event', (evt) => {
16
+ var e = evt.args[0]
17
+ return e
18
+ })
19
+
20
+ z.trap_events(sipjs.event_source, 'event', (evt) => {
21
+ var e = evt.args[0]
22
+ return e
23
+ })
24
+
25
+ sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
26
+
27
+ console.log(sip.start((data) => { console.log(data)} ))
28
+
29
+ const address = "127.0.0.1"
30
+
31
+ const e1_port = 7070
32
+ const e1 = endpoint.create({
33
+ address,
34
+ port: e1_port,
35
+ publicAddress: address
36
+ })
37
+
38
+ // hack to not lose first INVITE
39
+ await z.sleep(0)
40
+
41
+ const t1 = sip.transport.create({address})
42
+
43
+ const sip_call_id = uuid.v4()
44
+
45
+ var oc = sip.call.create(t1.id, {
46
+ from_uri: 'sip:alice@test.com',
47
+ to_uri: `sip:bob@${address}:${e1_port}`,
48
+ headers: {
49
+ 'Call-ID': sip_call_id,
50
+ 'Supported': 'timer',
51
+ 'Min-SE': '180',
52
+ 'Session-Expires': '180;refresher=uac',
53
+ },
54
+ })
55
+
56
+ await z.wait([
57
+ {
58
+ source: 'sip_endpoint',
59
+ req: m.collect('req', sipjs_sip_msg({
60
+ $rm: 'INVITE',
61
+ hdr_supported: 'timer',
62
+ hdr_min_se: '180',
63
+ hdr_session_expires: '180;refresher=uac',
64
+ })),
65
+ event: 'dialog_offer',
66
+ dialog_id: m.collect('dialog_id'),
67
+ },
68
+ ], 1000)
69
+
70
+ dialog.send_reply(
71
+ z.store.dialog_id,
72
+ z.store.req,
73
+ {
74
+ status: 422,
75
+ reason: 'Session Timer Too Small',
76
+ headers: {
77
+ 'Min-SE': '300',
78
+ 'Server': 'TBSIP',
79
+ },
80
+ }
81
+ )
82
+
83
+ await z.wait([
84
+ {
85
+ event: 'response',
86
+ call_id: oc.id,
87
+ method: 'INVITE',
88
+ msg: sip_msg({
89
+ $rs: '422',
90
+ $rr: 'Session Timer Too Small',
91
+ hdr_min_se: '300',
92
+ }),
93
+ },
94
+ {
95
+ event: 'call_ended',
96
+ call_id: oc.id,
97
+ }
98
+ ], 1000)
99
+
100
+ dialog.destroy(z.store.dialog_id)
101
+
102
+ delete z.store.dialog_id
103
+
104
+ oc = sip.call.create(t1.id, {
105
+ from_uri: 'sip:alice@test.com',
106
+ to_uri: `sip:bob@${address}:${e1_port}`,
107
+ headers: {
108
+ 'Call-ID': sip_call_id,
109
+ 'Supported': 'timer',
110
+ 'Min-SE': '300',
111
+ 'Session-Expires': '300;refresher=uac',
112
+ },
113
+ })
114
+
115
+ delete z.store.req
116
+
117
+ await z.wait([
118
+ {
119
+ source: 'sip_endpoint',
120
+ req: m.collect('req', sipjs_sip_msg({
121
+ $rm: 'INVITE',
122
+ hdr_supported: 'timer',
123
+ hdr_min_se: '300',
124
+ hdr_session_expires: '300;refresher=uac'
125
+ })),
126
+ event: 'dialog_offer',
127
+ dialog_id: m.collect('dialog_id'),
128
+ },
129
+ ], 1000)
130
+
131
+ const sdp_answer =`v=0
132
+ o=- 3933986675 3933986676 IN IP4 0.0.0.0
133
+ s=-
134
+ c=IN IP4 ${address}
135
+ t=0 0
136
+ m=audio 20000 RTP/AVP 0 101
137
+ a=sendrecv
138
+ a=rtpmap:0 PCMU/8000
139
+ a=rtpmap:101 telephone-event/8000
140
+ a=fmtp:101 0-15
141
+ a=ptime:20`.replace(/\n/g, "\r\n")
142
+
143
+ dialog.send_reply(
144
+ z.store.dialog_id,
145
+ z.store.req,
146
+ {
147
+ status: 183,
148
+ reason: 'Session Progress',
149
+ headers: {
150
+ 'content-type': 'application/sdp',
151
+ },
152
+ content: sdp_answer,
153
+ }
154
+ )
155
+
156
+ await z.wait([
157
+ {
158
+ event: 'response',
159
+ call_id: oc.id,
160
+ method: 'INVITE',
161
+ msg: sip_msg({
162
+ $rs: '183',
163
+ $rr: 'Session Progress',
164
+ }),
165
+ },
166
+ {
167
+ event: 'media_update',
168
+ call_id: oc.id,
169
+ status: 'ok',
170
+ },
171
+ ], 1000)
172
+
173
+ dialog.send_reply(
174
+ z.store.dialog_id,
175
+ z.store.req,
176
+ {
177
+ status: 200,
178
+ reason: 'OK',
179
+ headers: {
180
+ 'Supported': 'timer',
181
+ 'Min-SE': '300',
182
+ 'Session-Expires': '300;refresher=uac',
183
+ 'content-type': 'application/sdp',
184
+ },
185
+ content: sdp_answer,
186
+ }
187
+ )
188
+
189
+ await z.wait([
190
+ {
191
+ event: 'response',
192
+ call_id: oc.id,
193
+ method: 'INVITE',
194
+ msg: sip_msg({
195
+ $rs: '200',
196
+ $rr: 'OK',
197
+ hdr_supported: 'timer',
198
+ hdr_min_se: '300',
199
+ hdr_session_expires: '300;refresher=uac',
200
+ }),
201
+ },
202
+ {
203
+ event: 'media_update',
204
+ call_id: oc.id,
205
+ status: 'ok',
206
+ },
207
+ {
208
+ source: 'sip_endpoint',
209
+ endpoint_id: z.store.endpoint_id,
210
+ req: {
211
+ method: 'ACK',
212
+ },
213
+ event: 'in_dialog_request',
214
+ dialog_id: z.store.dialog_id
215
+ },
216
+ ], 1000)
217
+
218
+ for(var i=0 ; i<5 ; i++) {
219
+
220
+ // sleep here as much as you like
221
+ await z.sleep(0)
222
+
223
+ sip.call.update(oc.id, {
224
+ headers: {
225
+ 'Supported': 'timer',
226
+ 'Min-SE': '300',
227
+ 'Session-Expires': '300;refresher=uac',
228
+ },
229
+ })
230
+
231
+ delete z.store.req
232
+
233
+ await z.wait([
234
+ {
235
+ source: 'sip_endpoint',
236
+ req: m.collect('req', sipjs_sip_msg({
237
+ $rm: 'UPDATE',
238
+ hdr_supported: 'timer',
239
+ hdr_min_se: '300',
240
+ hdr_session_expires: '300;refresher=uac'
241
+ })),
242
+ event: 'in_dialog_request',
243
+ dialog_id: z.store.dialog_id
244
+ },
245
+ ], 1000)
246
+
247
+ dialog.send_reply(
248
+ z.store.dialog_id,
249
+ z.store.req,
250
+ {
251
+ status: 200,
252
+ reason: 'OK',
253
+ headers: {
254
+ 'Supported': 'timer',
255
+ 'Min-SE': '300',
256
+ 'Session-Expires': '300;refresher=uac',
257
+ },
258
+ }
259
+ )
260
+
261
+ await z.wait([
262
+ {
263
+ event: 'response',
264
+ call_id: oc.id,
265
+ method: 'UPDATE',
266
+ msg: sip_msg({
267
+ $rs: '200',
268
+ $rr: 'OK',
269
+ hdr_supported: 'timer',
270
+ hdr_min_se: '300',
271
+ hdr_session_expires: '300;refresher=uac',
272
+ }),
273
+ },
274
+ ], 1000)
275
+
276
+ }
277
+
278
+ sip.call.terminate(oc.id)
279
+
280
+ delete z.store.req
281
+
282
+ await z.wait([
283
+ {
284
+ source: 'sip_endpoint',
285
+ req: m.collect('req', sipjs_sip_msg({
286
+ $rm: 'BYE',
287
+ })),
288
+ },
289
+ ], 1000)
290
+
291
+ dialog.send_reply(
292
+ z.store.dialog_id,
293
+ z.store.req,
294
+ {
295
+ status: 200,
296
+ reason: 'OK',
297
+ }
298
+ )
299
+
300
+ await z.wait([
301
+ {
302
+ event: 'response',
303
+ call_id: oc.id,
304
+ method: 'BYE',
305
+ msg: sip_msg({
306
+ $rs: '200',
307
+ $rr: 'OK',
308
+ }),
309
+ },
310
+ {
311
+ event: 'call_ended',
312
+ call_id: oc.id,
313
+ },
314
+ ], 1000)
315
+
316
+ await z.sleep(100) // wait for any unexpected events
317
+
318
+ console.log("Success")
319
+
320
+ sip.stop()
321
+ process.exit(0)
322
+ }
323
+
324
+ test()
325
+ .catch(e => {
326
+ console.error(e)
327
+ process.exit(1)
328
+ })
329
+
package/samples/simple.js CHANGED
@@ -170,6 +170,7 @@ async function test() {
170
170
  console.log("Success")
171
171
 
172
172
  sip.stop()
173
+ process.exit(0)
173
174
  }
174
175
 
175
176
 
@@ -104,6 +104,7 @@ async function test() {
104
104
  console.log("Success")
105
105
 
106
106
  sip.stop()
107
+ process.exit(0)
107
108
  }
108
109
 
109
110
  test()
@@ -154,6 +154,7 @@ async function test() {
154
154
  console.log("Success")
155
155
 
156
156
  sip.stop()
157
+ process.exit(0)
157
158
  }
158
159
 
159
160
 
package/samples/srtp.js CHANGED
@@ -330,6 +330,7 @@ async function test() {
330
330
  console.log("Success")
331
331
 
332
332
  sip.stop()
333
+ process.exit(0)
333
334
  }
334
335
 
335
336
 
@@ -235,6 +235,7 @@ async function test() {
235
235
  console.log("Success")
236
236
 
237
237
  sip.stop()
238
+ process.exit(0)
238
239
  }
239
240
 
240
241
 
@@ -223,6 +223,7 @@ async function test() {
223
223
  console.log("Success")
224
224
 
225
225
  sip.stop()
226
+ process.exit(0)
226
227
  }
227
228
 
228
229
 
@@ -0,0 +1,127 @@
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
+
6
+ // here we create our Zeq instance
7
+ var z = new Zeq()
8
+
9
+
10
+ async function test() {
11
+ z.trap_events(sip.event_source, 'event', (evt) => {
12
+ var e = evt.args[0]
13
+ return e
14
+ })
15
+
16
+ console.log(sip.start((data) => { console.log(data)} ))
17
+
18
+ const t1 = sip.transport.create({address: "127.0.0.1"})
19
+ const t2 = sip.transport.create({address: "127.0.0.1"})
20
+
21
+ const oc = sip.call.create(t1.id, {
22
+ from_uri: 'sip:alice@test.com',
23
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
24
+ headers: {
25
+ 'X-MyHeader1': 'abc',
26
+ 'X-MyHeader2': 'def',
27
+ },
28
+ })
29
+
30
+ await z.wait([
31
+ {
32
+ event: "incoming_call",
33
+ call_id: m.collect("call_id"),
34
+ transport_id: t2.id,
35
+ msg: sip_msg({
36
+ $rU: 'bob',
37
+ $fU: 'alice',
38
+ $tU: 'bob',
39
+ $fd: 'test.com',
40
+ })
41
+ },
42
+ {
43
+ event: 'response',
44
+ call_id: oc.id,
45
+ method: 'INVITE',
46
+ msg: sip_msg({
47
+ $rs: '100',
48
+ $rr: 'Trying',
49
+ }),
50
+ },
51
+ ], 1000)
52
+
53
+ const ic = {
54
+ id: z.store.call_id,
55
+ sip_call_id: z.store.sip_call_id,
56
+ }
57
+
58
+ sip.call.respond(ic.id, {
59
+ code: 200,
60
+ reason: 'OK',
61
+ })
62
+
63
+ await z.wait([
64
+ {
65
+ event: 'response',
66
+ call_id: oc.id,
67
+ method: 'INVITE',
68
+ msg: sip_msg({
69
+ $rs: '200',
70
+ $rr: 'OK',
71
+ }),
72
+ },
73
+ {
74
+ event: 'media_update',
75
+ call_id: oc.id,
76
+ status: 'ok',
77
+ },
78
+ {
79
+ event: 'media_update',
80
+ call_id: ic.id,
81
+ status: 'ok',
82
+ },
83
+ ], 1000)
84
+
85
+ // Now force an error in the script.
86
+ // This will be catched by exception handler at the end of the script where
87
+ // sip.stop(true) will be called (true: terminate all remaining calls, registrations and subscriptions)
88
+
89
+ throw "SOME ERROR"
90
+
91
+ sip.call.terminate(oc.id)
92
+
93
+ // and wait for termination events
94
+ await z.wait([
95
+ {
96
+ event: 'response',
97
+ call_id: oc.id,
98
+ method: 'BYE',
99
+ msg: sip_msg({
100
+ $rs: '200',
101
+ $rr: 'OK',
102
+ }),
103
+ },
104
+ {
105
+ event: 'call_ended',
106
+ call_id: oc.id,
107
+ },
108
+ {
109
+ event: 'call_ended',
110
+ call_id: ic.id,
111
+ },
112
+ ], 1000)
113
+
114
+ console.log("Success")
115
+
116
+ sip.stop()
117
+ process.exit(0)
118
+ }
119
+
120
+
121
+ test()
122
+ .catch(e => {
123
+ console.error(e)
124
+ sip.stop(true)
125
+ process.exit(0)
126
+ })
127
+
package/samples/tcp.js CHANGED
@@ -401,6 +401,7 @@ async function test() {
401
401
  console.log("Success")
402
402
 
403
403
  sip.stop()
404
+ process.exit(0)
404
405
  }
405
406
 
406
407
 
@@ -157,6 +157,7 @@ async function test() {
157
157
  console.log("Success")
158
158
 
159
159
  sip.stop()
160
+ process.exit(0)
160
161
  }
161
162
 
162
163
 
package/samples/tls.js CHANGED
@@ -117,6 +117,7 @@ async function test() {
117
117
  console.log("Success")
118
118
 
119
119
  sip.stop()
120
+ process.exit(0)
120
121
  }
121
122
 
122
123
 
@@ -477,6 +477,7 @@ async function test() {
477
477
  console.log("Success")
478
478
 
479
479
  sip.stop()
480
+ process.exit(0)
480
481
  }
481
482
 
482
483
 
@@ -489,6 +489,7 @@ async function test() {
489
489
  console.log("Success")
490
490
 
491
491
  sip.stop()
492
+ process.exit(0)
492
493
  }
493
494
 
494
495
 
@@ -143,6 +143,7 @@ async function test() {
143
143
  console.log("Success")
144
144
 
145
145
  sip.stop()
146
+ process.exit(0)
146
147
  }
147
148
 
148
149
 
@@ -143,6 +143,7 @@ async function test() {
143
143
  console.log("Success")
144
144
 
145
145
  sip.stop()
146
+ process.exit(0)
146
147
  }
147
148
 
148
149
 
@@ -153,6 +153,7 @@ async function test() {
153
153
  console.log("Success")
154
154
 
155
155
  sip.stop()
156
+ process.exit(0)
156
157
  }
157
158
 
158
159
 
@@ -145,6 +145,7 @@ async function test() {
145
145
  console.log("Success")
146
146
 
147
147
  sip.stop()
148
+ process.exit(0)
148
149
  }
149
150
 
150
151
 
@@ -153,6 +153,7 @@ async function test() {
153
153
  console.log("Success")
154
154
 
155
155
  sip.stop()
156
+ process.exit(0)
156
157
  }
157
158
 
158
159
 
package/src/addon.cpp CHANGED
@@ -467,6 +467,40 @@ Napi::Value call_reinvite(const Napi::CallbackInfo &info) {
467
467
  return env.Null();
468
468
  }
469
469
 
470
+ Napi::Value call_update(const Napi::CallbackInfo &info) {
471
+ Napi::Env env = info.Env();
472
+
473
+ if (info.Length() != 2) {
474
+ Napi::Error::New(env,
475
+ "Wrong number of arguments. Expected: call_id, params.")
476
+ .ThrowAsJavaScriptException();
477
+ return env.Null();
478
+ }
479
+
480
+ if (!info[0].IsNumber()) {
481
+ Napi::TypeError::New(env, "call_id must be number.")
482
+ .ThrowAsJavaScriptException();
483
+ return env.Null();
484
+ }
485
+ int call_id = info[0].As<Napi::Number>().Int32Value();
486
+
487
+ if (!info[1].IsString()) {
488
+ Napi::TypeError::New(env, "params must be a JSON string.")
489
+ .ThrowAsJavaScriptException();
490
+ return env.Null();
491
+ }
492
+ const string json = info[1].As<Napi::String>().Utf8Value();
493
+
494
+ int res = pjw_call_update(call_id, json.c_str());
495
+
496
+ if (res != 0) {
497
+ Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
498
+ return env.Null();
499
+ }
500
+
501
+ return env.Null();
502
+ }
503
+
470
504
  Napi::Value call_send_request(const Napi::CallbackInfo &info) {
471
505
  Napi::Env env = info.Env();
472
506
 
@@ -1534,7 +1568,15 @@ Napi::Value do_poll(const Napi::CallbackInfo &info) {
1534
1568
  Napi::Value shutdown_(const Napi::CallbackInfo &info) {
1535
1569
  Napi::Env env = info.Env();
1536
1570
 
1537
- int res = __pjw_shutdown();
1571
+ if (info.Length() != 1) {
1572
+ Napi::Error::New(
1573
+ env, "Wrong number of arguments. Expected: clean_up")
1574
+ .ThrowAsJavaScriptException();
1575
+ return env.Null();
1576
+ }
1577
+ int clean_up = info[0].As<Napi::Number>().Int32Value();
1578
+
1579
+ int res = __pjw_shutdown(clean_up);
1538
1580
 
1539
1581
  if (res != 0) {
1540
1582
  Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
@@ -1566,6 +1608,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
1566
1608
  exports.Set("call_send_dtmf", Napi::Function::New(env, call_send_dtmf));
1567
1609
  exports.Set("call_send_bfsk", Napi::Function::New(env, call_send_bfsk));
1568
1610
  exports.Set("call_reinvite", Napi::Function::New(env, call_reinvite));
1611
+ exports.Set("call_update", Napi::Function::New(env, call_update));
1569
1612
  exports.Set("call_send_request", Napi::Function::New(env, call_send_request));
1570
1613
 
1571
1614
  exports.Set("call_start_record_wav", Napi::Function::New(env, call_start_record_wav));
package/src/idmanager.cpp CHANGED
@@ -75,3 +75,7 @@ void IdManager::iterate(void (*f)(long id, long val)) {
75
75
  ++pos;
76
76
  }
77
77
  }
78
+
79
+ int IdManager::size() {
80
+ return ids.size();
81
+ }
package/src/idmanager.hpp CHANGED
@@ -17,6 +17,7 @@ public:
17
17
  bool get(long id, long &val);
18
18
  bool get_id(long val, long &id);
19
19
  void iterate(void (*f)(long id, long val));
20
+ int size();
20
21
 
21
22
  map<long, long> id_map; // hack to test tcpdumper
22
23
  private: