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.
- package/index.js +4 -5
- package/package.json +1 -1
- package/prebuilds/linux-x64/node.abi102.node +0 -0
- package/prebuilds/linux-x64/node.abi108.node +0 -0
- package/prebuilds/linux-x64/node.abi111.node +0 -0
- package/prebuilds/linux-x64/node.abi115.node +0 -0
- package/prebuilds/linux-x64/node.abi120.node +0 -0
- package/prebuilds/linux-x64/node.abi88.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/samples/100_calls.js +1 -0
- package/samples/16_audio_streams.js +1 -0
- package/samples/183_session_progress.js +1 -0
- package/samples/custom_call_id.js +1 -0
- package/samples/delayed_media.js +1 -0
- package/samples/four_audio_streams_two_refused.js +1 -0
- package/samples/g729.js +1 -0
- package/samples/media_fields.js +1 -0
- package/samples/mrcp_and_audio.js +1 -0
- package/samples/mrcp_and_audio.simplified_media.js +1 -0
- package/samples/multiple_audio_streams.js +1 -0
- package/samples/options.js +1 -0
- package/samples/pcma.js +1 -0
- package/samples/play_wav_and_speech_recog.bad_transcript.pcmu8000.js +1 -0
- package/samples/refer.js +1 -0
- package/samples/refuse_telephone_event.js +1 -0
- package/samples/register_no_expires.js +1 -0
- package/samples/register_subscribe.js +1 -0
- package/samples/reinvite_and_dtmf.js +1 -0
- package/samples/reinvite_audio_audio.js +1 -0
- package/samples/reinvite_with_hold_unhold.js +1 -0
- package/samples/rtp_and_srtp.js +1 -0
- package/samples/rtp_and_srtp.rtp_refused.js +1 -0
- package/samples/rtp_and_srtp.unbalanced_sdp_answer.js.future +1 -0
- package/samples/send_and_receive_bfsk.js.future +1 -0
- package/samples/send_and_receive_fax.js +1 -0
- package/samples/session_expires.update.js.future +1 -0
- package/samples/session_expires.update.with_sipjs-lab.js +64 -47
- package/samples/simple.js +1 -0
- package/samples/sip_cancel.js +1 -0
- package/samples/speech_synth_and_recog.speex16000.js +1 -0
- package/samples/srtp.js +1 -0
- package/samples/start_play_wav_with_end_of_file_event.js +1 -0
- package/samples/start_play_wav_with_no_loop.js +1 -0
- package/samples/stop_with_cleanup.js +127 -0
- package/samples/tcp.js +1 -0
- package/samples/text_to_speech.js +1 -0
- package/samples/tls.js +1 -0
- package/samples/two_audio_streams.js +1 -0
- package/samples/two_audio_streams.port_zero.js +1 -0
- package/samples_extra/ws_speech_server.bfsk.js +1 -0
- package/samples_extra/ws_speech_server.dtmf.js +1 -0
- package/samples_extra/ws_speech_server.google.js +1 -0
- package/samples_extra/ws_speech_server.send_bfsk.js +1 -0
- package/samples_extra/ws_speech_server.start_bfsk_detection.js.future +1 -0
- package/src/addon.cpp +9 -1
- package/src/idmanager.cpp +4 -0
- package/src/idmanager.hpp +1 -0
- package/src/sip.cpp +113 -107
- 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(
|
|
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
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/samples/100_calls.js
CHANGED
package/samples/delayed_media.js
CHANGED
package/samples/g729.js
CHANGED
package/samples/media_fields.js
CHANGED
package/samples/options.js
CHANGED
package/samples/pcma.js
CHANGED
package/samples/refer.js
CHANGED
package/samples/rtp_and_srtp.js
CHANGED
|
@@ -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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
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
package/samples/sip_cancel.js
CHANGED
package/samples/srtp.js
CHANGED
|
@@ -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
package/samples/tls.js
CHANGED
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
|
-
|
|
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
package/src/idmanager.hpp
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
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
|
-
|
|
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)
|