sip-lab 1.31.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 (59) hide show
  1. package/index.js +4 -5
  2. package/package.json +1 -1
  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 +1 -0
  14. package/samples/delayed_media.js +1 -0
  15. package/samples/four_audio_streams_two_refused.js +1 -0
  16. package/samples/g729.js +1 -0
  17. package/samples/media_fields.js +1 -0
  18. package/samples/mrcp_and_audio.js +1 -0
  19. package/samples/mrcp_and_audio.simplified_media.js +1 -0
  20. package/samples/multiple_audio_streams.js +1 -0
  21. package/samples/options.js +1 -0
  22. package/samples/pcma.js +1 -0
  23. package/samples/play_wav_and_speech_recog.bad_transcript.pcmu8000.js +1 -0
  24. package/samples/refer.js +1 -0
  25. package/samples/refuse_telephone_event.js +1 -0
  26. package/samples/register_no_expires.js +1 -0
  27. package/samples/register_subscribe.js +1 -0
  28. package/samples/reinvite_and_dtmf.js +1 -0
  29. package/samples/reinvite_audio_audio.js +1 -0
  30. package/samples/reinvite_with_hold_unhold.js +1 -0
  31. package/samples/rtp_and_srtp.js +1 -0
  32. package/samples/rtp_and_srtp.rtp_refused.js +1 -0
  33. package/samples/rtp_and_srtp.unbalanced_sdp_answer.js.future +1 -0
  34. package/samples/send_and_receive_bfsk.js.future +1 -0
  35. package/samples/send_and_receive_fax.js +1 -0
  36. package/samples/session_expires.update.js.future +1 -0
  37. package/samples/session_expires.update.with_sipjs-lab.js +64 -47
  38. package/samples/simple.js +1 -0
  39. package/samples/sip_cancel.js +1 -0
  40. package/samples/speech_synth_and_recog.speex16000.js +1 -0
  41. package/samples/srtp.js +1 -0
  42. package/samples/start_play_wav_with_end_of_file_event.js +1 -0
  43. package/samples/start_play_wav_with_no_loop.js +1 -0
  44. package/samples/stop_with_cleanup.js +127 -0
  45. package/samples/tcp.js +1 -0
  46. package/samples/text_to_speech.js +1 -0
  47. package/samples/tls.js +1 -0
  48. package/samples/two_audio_streams.js +1 -0
  49. package/samples/two_audio_streams.port_zero.js +1 -0
  50. package/samples_extra/ws_speech_server.bfsk.js +1 -0
  51. package/samples_extra/ws_speech_server.dtmf.js +1 -0
  52. package/samples_extra/ws_speech_server.google.js +1 -0
  53. package/samples_extra/ws_speech_server.send_bfsk.js +1 -0
  54. package/samples_extra/ws_speech_server.start_bfsk_detection.js.future +1 -0
  55. package/src/addon.cpp +9 -1
  56. package/src/idmanager.cpp +4 -0
  57. package/src/idmanager.hpp +1 -0
  58. package/src/sip.cpp +113 -107
  59. package/src/sip.hpp +1 -1
package/index.js CHANGED
@@ -6,8 +6,8 @@ var eventEmitter = new events.EventEmitter();
6
6
 
7
7
  process.on('SIGINT', function() {
8
8
  console.log("SIGINT");
9
- var res = addon.shutdown()
10
- process.exit(0)
9
+ var res = addon.shutdown(1)
10
+ process.exit(1)
11
11
  });
12
12
 
13
13
  addon.event_source = eventEmitter
@@ -32,10 +32,9 @@ var timerId = setInterval(() => {
32
32
  }
33
33
  }, 50)
34
34
 
35
- addon.stop = () => {
35
+ addon.stop = (clean_up = false) => {
36
36
  clearInterval(timerId)
37
- var res = addon.shutdown()
38
- process.exit(0)
37
+ var res = addon.shutdown(clean_up ? 1 : 0)
39
38
  }
40
39
 
41
40
  addon.transport = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-lab",
3
- "version": "1.31.0",
3
+ "version": "1.32.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
Binary file
Binary file
@@ -139,6 +139,7 @@ async function test() {
139
139
  console.log("Success")
140
140
 
141
141
  sip.stop()
142
+ process.exit(0)
142
143
  }
143
144
 
144
145
 
@@ -139,6 +139,7 @@ async function test() {
139
139
  console.log("Success")
140
140
 
141
141
  sip.stop()
142
+ process.exit(0)
142
143
  }
143
144
 
144
145
 
@@ -374,6 +374,7 @@ async function test() {
374
374
  console.log("Success")
375
375
 
376
376
  sip.stop()
377
+ process.exit(0)
377
378
  }
378
379
 
379
380
 
@@ -208,6 +208,7 @@ async function test() {
208
208
  console.log("Success")
209
209
 
210
210
  sip.stop()
211
+ process.exit(0)
211
212
  }
212
213
 
213
214
 
@@ -315,6 +315,7 @@ async function test() {
315
315
  console.log("Success")
316
316
 
317
317
  sip.stop()
318
+ process.exit(0)
318
319
  }
319
320
 
320
321
  test()
@@ -314,6 +314,7 @@ async function test() {
314
314
  console.log("Success")
315
315
 
316
316
  sip.stop()
317
+ process.exit(0)
317
318
  }
318
319
 
319
320
 
package/samples/g729.js CHANGED
@@ -198,6 +198,7 @@ async function test() {
198
198
  console.log("Success")
199
199
 
200
200
  sip.stop()
201
+ process.exit(0)
201
202
  }
202
203
 
203
204
  test()
@@ -179,6 +179,7 @@ async function test() {
179
179
  console.log("Success")
180
180
 
181
181
  sip.stop()
182
+ process.exit(0)
182
183
  }
183
184
 
184
185
 
@@ -411,6 +411,7 @@ async function test() {
411
411
  console.log("Success")
412
412
 
413
413
  sip.stop()
414
+ process.exit(0)
414
415
  }
415
416
 
416
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
 
@@ -257,6 +257,7 @@ async function test() {
257
257
  console.log("Success")
258
258
 
259
259
  sip.stop()
260
+ process.exit(0)
260
261
  }
261
262
 
262
263
 
@@ -5,7 +5,7 @@ const sip_msg = require('sip-matching')
5
5
  const uuid = require('uuid')
6
6
 
7
7
  const sipjs = require('sipjs-lab')
8
- const {endpoint, dialog} = require('sipjs-lab')
8
+ const {endpoint, dialog, sip_msg: sipjs_sip_msg} = require('sipjs-lab')
9
9
 
10
10
  // here we create our Zeq instance
11
11
 
@@ -28,8 +28,6 @@ async function test() {
28
28
 
29
29
  const address = "127.0.0.1"
30
30
 
31
- const t1 = sip.transport.create({address})
32
-
33
31
  const e1_port = 7070
34
32
  const e1 = endpoint.create({
35
33
  address,
@@ -37,6 +35,11 @@ async function test() {
37
35
  publicAddress: address
38
36
  })
39
37
 
38
+ // hack to not lose first INVITE
39
+ await z.sleep(0)
40
+
41
+ const t1 = sip.transport.create({address})
42
+
40
43
  const sip_call_id = uuid.v4()
41
44
 
42
45
  var oc = sip.call.create(t1.id, {
@@ -46,28 +49,19 @@ async function test() {
46
49
  'Call-ID': sip_call_id,
47
50
  'Supported': 'timer',
48
51
  'Min-SE': '180',
49
- 'Session-Expires': '180',
52
+ 'Session-Expires': '180;refresher=uac',
50
53
  },
51
54
  })
52
55
 
53
56
  await z.wait([
54
57
  {
55
58
  source: 'sip_endpoint',
56
- req: m.collect('req', {
57
- method: 'INVITE',
58
- uri: `sip:bob@${address}:${e1_port}`,
59
- headers: {
60
- from: {
61
- uri: 'sip:alice@test.com',
62
- },
63
- to: {
64
- uri: `sip:bob@${address}`,
65
- },
66
- supported: 'timer',
67
- 'min-se': '180',
68
- 'session-expires': '180',
69
- },
70
- }),
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
+ })),
71
65
  event: 'dialog_offer',
72
66
  dialog_id: m.collect('dialog_id'),
73
67
  },
@@ -107,8 +101,6 @@ async function test() {
107
101
 
108
102
  delete z.store.dialog_id
109
103
 
110
- await z.sleep(1000)
111
-
112
104
  oc = sip.call.create(t1.id, {
113
105
  from_uri: 'sip:alice@test.com',
114
106
  to_uri: `sip:bob@${address}:${e1_port}`,
@@ -116,7 +108,7 @@ async function test() {
116
108
  'Call-ID': sip_call_id,
117
109
  'Supported': 'timer',
118
110
  'Min-SE': '300',
119
- 'Session-Expires': '300',
111
+ 'Session-Expires': '300;refresher=uac',
120
112
  },
121
113
  })
122
114
 
@@ -125,18 +117,12 @@ async function test() {
125
117
  await z.wait([
126
118
  {
127
119
  source: 'sip_endpoint',
128
- req: m.collect('req', {
129
- method: 'INVITE',
130
- uri: `sip:bob@${address}:${e1_port}`,
131
- headers: {
132
- from: {
133
- uri: 'sip:alice@test.com',
134
- },
135
- to: {
136
- uri: `sip:bob@${address}`,
137
- },
138
- },
139
- }),
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
+ })),
140
126
  event: 'dialog_offer',
141
127
  dialog_id: m.collect('dialog_id'),
142
128
  },
@@ -154,6 +140,36 @@ a=rtpmap:101 telephone-event/8000
154
140
  a=fmtp:101 0-15
155
141
  a=ptime:20`.replace(/\n/g, "\r\n")
156
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
+
157
173
  dialog.send_reply(
158
174
  z.store.dialog_id,
159
175
  z.store.req,
@@ -199,14 +215,16 @@ a=ptime:20`.replace(/\n/g, "\r\n")
199
215
  },
200
216
  ], 1000)
201
217
 
202
-
203
218
  for(var i=0 ; i<5 ; i++) {
204
219
 
220
+ // sleep here as much as you like
221
+ await z.sleep(0)
222
+
205
223
  sip.call.update(oc.id, {
206
224
  headers: {
207
225
  'Supported': 'timer',
208
226
  'Min-SE': '300',
209
- 'Session-Expires': '300',
227
+ 'Session-Expires': '300;refresher=uac',
210
228
  },
211
229
  })
212
230
 
@@ -215,14 +233,12 @@ a=ptime:20`.replace(/\n/g, "\r\n")
215
233
  await z.wait([
216
234
  {
217
235
  source: 'sip_endpoint',
218
- req: m.collect('req', {
219
- method: 'UPDATE',
220
- headers: {
221
- 'supported': 'timer',
222
- 'min-se': '300',
223
- 'session-expires': '300',
224
- },
225
- }),
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
+ })),
226
242
  event: 'in_dialog_request',
227
243
  dialog_id: z.store.dialog_id
228
244
  },
@@ -266,9 +282,9 @@ a=ptime:20`.replace(/\n/g, "\r\n")
266
282
  await z.wait([
267
283
  {
268
284
  source: 'sip_endpoint',
269
- req: m.collect('req', {
270
- method: 'BYE',
271
- }),
285
+ req: m.collect('req', sipjs_sip_msg({
286
+ $rm: 'BYE',
287
+ })),
272
288
  },
273
289
  ], 1000)
274
290
 
@@ -302,6 +318,7 @@ a=ptime:20`.replace(/\n/g, "\r\n")
302
318
  console.log("Success")
303
319
 
304
320
  sip.stop()
321
+ process.exit(0)
305
322
  }
306
323
 
307
324
  test()
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
@@ -1568,7 +1568,15 @@ Napi::Value do_poll(const Napi::CallbackInfo &info) {
1568
1568
  Napi::Value shutdown_(const Napi::CallbackInfo &info) {
1569
1569
  Napi::Env env = info.Env();
1570
1570
 
1571
- 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);
1572
1580
 
1573
1581
  if (res != 0) {
1574
1582
  Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
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:
package/src/sip.cpp CHANGED
@@ -6641,120 +6641,126 @@ int pjw_enable_telephone_event() {
6641
6641
  return 0;
6642
6642
  }
6643
6643
 
6644
- int __pjw_shutdown() {
6645
- // addon_log(L_DBG, "pjw_shutdown thread_id=%i\n", syscall(SYS_gettid));
6646
- PJW_LOCK();
6647
-
6648
- g_shutting_down = true;
6649
-
6650
- // disable auto cleanup
6651
-
6652
- /*
6653
- map<long, long>::iterator iter;
6654
- iter = g_call_ids.id_map.begin();
6655
- while(iter != g_call_ids.id_map.end()){
6656
- Call *call = (Call*)iter->second;
6657
-
6658
- addon_log(L_DBG, "Terminating call %d\n", iter->first);
6659
-
6660
- pjsip_tx_data *tdata;
6661
- pj_status_t status;
6662
- status = pjsip_inv_end_session(call->inv,
6663
- 603,
6664
- NULL,
6665
- &tdata); //Copied from pjsua
6666
- if(status != PJ_SUCCESS){
6667
- //ignore
6668
- char err[256];
6669
- pj_strerror(status, err, sizeof(err));
6670
- addon_log(L_DBG, "pjsip_inv_end_session failed statut=%i
6671
- (%s)\n", status, err);
6672
- ++iter;
6673
- continue;
6674
- }
6675
-
6676
- if(!tdata)
6677
- {
6678
- //if tdata was not set by pjsip_inv_end_session, it means
6679
- we didn't receive any response yet (100 Trying) and we cannot send CANCEL
6680
- in this situation. So we just can return here without calling
6681
- pjsip_inv_send_msg.
6682
- ++iter;
6683
- addon_log(L_DBG, "no tdata\n");
6684
- continue;
6685
- }
6686
-
6687
- status = pjsip_inv_send_msg(call->inv, tdata);
6688
- if(status != PJ_SUCCESS){
6689
- addon_log(L_DBG, "pjsip_inv_send_msg failed\n");
6690
- }
6691
- ++iter;
6692
- }
6693
-
6694
- iter = g_account_ids.id_map.begin();
6695
- while(iter != g_account_ids.id_map.end()){
6696
- pjsip_regc *regc = (pjsip_regc*)iter->second;
6697
-
6698
- addon_log(L_DBG, "Unregistering account %d\n", iter->first);
6699
-
6700
- pjsip_tx_data *tdata;
6701
- pj_status_t status;
6702
-
6703
- status = pjsip_regc_unregister(regc, &tdata);
6704
- if(status != PJ_SUCCESS)
6705
- {
6706
- addon_log(L_DBG, "pjsip_regc_unregister failed\n");
6707
- }
6708
-
6709
- status = pjsip_regc_send(regc, tdata);
6710
- if(status != PJ_SUCCESS)
6711
- {
6712
- addon_log(L_DBG, "pjsip_regc_send failed\n");
6713
- }
6714
- ++iter;
6715
- }
6644
+ int __pjw_shutdown(int clean_up) {
6645
+ addon_log(L_DBG, "pjw_shutdown thread_id=%i\n", syscall(SYS_gettid));
6716
6646
 
6717
- Subscription *subscription;
6718
- iter = g_subscription_ids.id_map.begin();
6719
- while(iter != g_subscription_ids.id_map.end()){
6720
- addon_log(L_DBG, "Unsubscribing subscription %d\n", iter->first);
6647
+ g_shutting_down = true;
6721
6648
 
6722
- subscription = (Subscription*)iter->second;
6723
- if(!subscription_subscribe(subscription, 0, NULL)) {
6724
- addon_log(L_DBG, "Unsubscription failed failed\n");
6725
- }
6726
- ++iter;
6727
- }
6728
-
6729
- PJW_UNLOCK();
6730
-
6731
- //uint32_t wait = 100000 * (g_call_ids.id_map.size() +
6732
- g_account_ids.id_map.size()));
6733
- //wait += 1000000; //Wait one whole second to permit packet capture to get
6734
- any final packets
6735
-
6736
- timeval tv_start;
6737
- timeval tv_end;
6738
- gettimeofday(&tv_start, NULL);
6739
- gettimeofday(&tv_end, NULL);
6649
+ if(!clean_up) {
6650
+ return 0;
6651
+ }
6740
6652
 
6741
- unsigned int start = tv_start.tv_sec * 1000 + (tv_start.tv_usec / 1000);
6742
- unsigned int end = tv_end.tv_sec * 1000 + (tv_end.tv_usec / 1000);
6653
+ addon_log(L_DBG, "INITIATING CLEANUP\n");
6743
6654
 
6744
- int DELAY = 2000; // 1000 ms delay
6745
- while(end - start < DELAY) {
6746
- pj_time_val tv = {0, 500};
6747
- pj_status_t status;
6748
- status = pjsip_endpt_handle_events(g_sip_endpt, &tv);
6655
+ PJW_LOCK();
6749
6656
 
6750
- gettimeofday(&tv_end, NULL);
6751
- end = tv_end.tv_sec * 1000 + (tv_end.tv_usec / 1000);
6752
- //time(&end);
6753
- }
6657
+ map<long, long>::iterator iter;
6658
+ iter = g_call_ids.id_map.begin();
6659
+ while(iter != g_call_ids.id_map.end()){
6660
+ Call *call = (Call*)iter->second;
6661
+
6662
+ addon_log(L_DBG, "Terminating call %d\n", iter->first);
6663
+
6664
+ pjsip_tx_data *tdata;
6665
+ pj_status_t status;
6666
+ status = pjsip_inv_end_session(call->inv,
6667
+ 603,
6668
+ NULL,
6669
+ &tdata); //Copied from pjsua
6670
+ if(status != PJ_SUCCESS){
6671
+ //ignore
6672
+ char err[256];
6673
+ pj_strerror(status, err, sizeof(err));
6674
+ addon_log(L_DBG, "pjsip_inv_end_session failed statut=%i (%s)\n", status, err);
6675
+ ++iter;
6676
+ continue;
6677
+ }
6678
+
6679
+ if(!tdata)
6680
+ {
6681
+ //if tdata was not set by pjsip_inv_end_session, it means we didn't receive any response yet (100 Trying) and we cannot send CANCEL in this situation. So we just can return here without calling pjsip_inv_send_msg.
6682
+ ++iter;
6683
+ addon_log(L_DBG, "no tdata\n");
6684
+ continue;
6685
+ }
6686
+
6687
+ status = pjsip_inv_send_msg(call->inv, tdata);
6688
+ if(status != PJ_SUCCESS){
6689
+ addon_log(L_DBG, "pjsip_inv_send_msg failed\n");
6690
+ }
6691
+ ++iter;
6692
+ }
6693
+
6694
+ iter = g_account_ids.id_map.begin();
6695
+ while(iter != g_account_ids.id_map.end()){
6696
+ pjsip_regc *regc = (pjsip_regc*)iter->second;
6697
+
6698
+ addon_log(L_DBG, "Unregistering account %d\n", iter->first);
6699
+
6700
+ pjsip_tx_data *tdata;
6701
+ pj_status_t status;
6702
+
6703
+ status = pjsip_regc_unregister(regc, &tdata);
6704
+ if(status != PJ_SUCCESS)
6705
+ {
6706
+ addon_log(L_DBG, "pjsip_regc_unregister failed\n");
6707
+ }
6708
+
6709
+ status = pjsip_regc_send(regc, tdata);
6710
+ if(status != PJ_SUCCESS)
6711
+ {
6712
+ addon_log(L_DBG, "pjsip_regc_send failed\n");
6713
+ }
6714
+ ++iter;
6715
+ }
6716
+
6717
+ Subscription *subscription;
6718
+ iter = g_subscription_ids.id_map.begin();
6719
+
6720
+ rapidjson::Document doc;
6721
+ doc.Parse("{\"expires\": 0}");
6722
+
6723
+ while(iter != g_subscription_ids.id_map.end()){
6724
+ addon_log(L_DBG, "Unsubscribing subscription %d\n", iter->first);
6725
+
6726
+ subscription = (Subscription*)iter->second;
6727
+ if(!subscription_subscribe(subscription, 0, doc)) {
6728
+ addon_log(L_DBG, "Unsubscription failed failed\n");
6729
+ }
6730
+ ++iter;
6731
+ }
6754
6732
 
6755
- */
6733
+ PJW_UNLOCK();
6756
6734
 
6757
- return 0;
6735
+ //uint32_t wait = 100000 * (g_call_ids.id_map.size() + g_account_ids.id_map.size()));
6736
+ //wait += 1000000; //Wait one whole second to permit packet capture to get any final packets
6737
+
6738
+ /*
6739
+ time_t end,start;
6740
+ time(&start);
6741
+ end = start;
6742
+ */
6743
+ timeval tv_start;
6744
+ timeval tv_end;
6745
+ gettimeofday(&tv_start, NULL);
6746
+ gettimeofday(&tv_end, NULL);
6747
+
6748
+ unsigned int start = tv_start.tv_sec * 1000 + (tv_start.tv_usec / 1000);
6749
+ unsigned int end = tv_end.tv_sec * 1000 + (tv_end.tv_usec / 1000);
6750
+
6751
+ int DELAY = 1000; // 1000 ms delay
6752
+ while(end - start < DELAY) {
6753
+ pj_time_val tv = {0, 500};
6754
+ pj_status_t status;
6755
+ status = pjsip_endpt_handle_events(g_sip_endpt, &tv);
6756
+
6757
+ gettimeofday(&tv_end, NULL);
6758
+ end = tv_end.tv_sec * 1000 + (tv_end.tv_usec / 1000);
6759
+ //time(&end);
6760
+ }
6761
+
6762
+ addon_log(L_DBG, "CLEANUP DONE\n");
6763
+ return 0;
6758
6764
  }
6759
6765
 
6760
6766
  // Copied from streamutil.c (pjsip sample)
package/src/sip.hpp CHANGED
@@ -92,7 +92,7 @@ int pjw_get_codecs(char *out_codecs);
92
92
 
93
93
  int pjw_set_codecs(const char *in_codec_info);
94
94
 
95
- int __pjw_shutdown();
95
+ int __pjw_shutdown(int clean_up);
96
96
 
97
97
  int pjw_notify(long subscriber_id, const char *json);
98
98