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.
- package/DEV.md +19 -3
- package/README.md +8 -4
- package/binding.gyp +97 -86
- package/build_deps.sh +3 -2
- package/index.js +14 -7
- package/package.json +7 -2
- package/prebuilds/linux-x64/node.abi102.node +0 -0
- package/prebuilds/linux-x64/node.abi108.node +0 -0
- package/prebuilds/linux-x64/node.abi88.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/samples/16_audio_streams.js +179 -0
- package/samples/delayed_media.js +117 -81
- package/samples/g729.js +50 -28
- package/samples/mrcp_and_audio.js +445 -0
- package/samples/mrcp_and_audio.simplified_media.js +273 -0
- package/samples/mrcp_and_audio.switching_order.js +273 -0
- package/samples/options.js +82 -0
- package/samples/refer.js +247 -0
- package/samples/refuse_telephone_event.js +166 -0
- package/samples/register_no_expires.js +82 -0
- package/samples/register_subscribe.js +36 -4
- package/samples/reinvite_and_dtmf.js +236 -161
- package/samples/reinvite_audio_audio.js +320 -0
- package/samples/reinvite_with_hold_unhold.js +412 -0
- package/samples/send_and_receive_fax.js +4 -8
- package/samples/simple.js +5 -9
- package/samples/sip_cancel.js +4 -6
- package/samples/tcp_and_extra_headers.js +98 -45
- package/samples/two_audio_media.js +497 -0
- package/src/addon.cpp +488 -268
- package/src/event_templates.cpp +84 -35
- package/src/event_templates.hpp +22 -12
- package/src/idmanager.cpp +58 -57
- package/src/idmanager.hpp +10 -10
- package/src/log.cpp +9 -11
- package/src/log.hpp +4 -4
- package/src/sip.cpp +6841 -5040
- package/src/sip.hpp +26 -34
- package/src/packetdumper.cpp +0 -234
- package/src/packetdumper.hpp +0 -67
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
14
|
+
var e = evt.args[0]
|
|
15
|
+
return e
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
19
|
+
|
|
20
|
+
t1 = sip.transport.create({address: "127.0.0.1", port: 5090, type: 'udp'})
|
|
21
|
+
t2 = sip.transport.create({address: "127.0.0.1", port: 5092, type: 'udp'})
|
|
22
|
+
|
|
23
|
+
console.log("t1", t1)
|
|
24
|
+
console.log("t2", t2)
|
|
25
|
+
|
|
26
|
+
oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
|
|
27
|
+
|
|
28
|
+
sip.disable_telephone_event()
|
|
29
|
+
|
|
30
|
+
await z.wait([
|
|
31
|
+
{
|
|
32
|
+
event: "incoming_call",
|
|
33
|
+
call_id: m.collect("call_id"),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
event: 'response',
|
|
37
|
+
call_id: oc.id,
|
|
38
|
+
method: 'INVITE',
|
|
39
|
+
msg: sip_msg({
|
|
40
|
+
$rs: '100',
|
|
41
|
+
$rr: 'Trying',
|
|
42
|
+
'$(hdrcnt(via))': 1,
|
|
43
|
+
'$hdr(call-id)': m.collect('sip_call_id'),
|
|
44
|
+
$fU: 'alice',
|
|
45
|
+
$fd: 'test.com',
|
|
46
|
+
$tU: 'bob',
|
|
47
|
+
'$hdr(l)': '0',
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
], 1000)
|
|
51
|
+
|
|
52
|
+
ic = {
|
|
53
|
+
id: z.store.call_id,
|
|
54
|
+
sip_call_id: z.store.sip_call_id,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
58
|
+
|
|
59
|
+
await z.wait([
|
|
60
|
+
{
|
|
61
|
+
event: 'response',
|
|
62
|
+
call_id: oc.id,
|
|
63
|
+
method: 'INVITE',
|
|
64
|
+
msg: sip_msg({
|
|
65
|
+
$rs: '200',
|
|
66
|
+
$rr: 'OK',
|
|
67
|
+
'$(hdrcnt(VIA))': 1,
|
|
68
|
+
$fU: 'alice',
|
|
69
|
+
$fd: 'test.com',
|
|
70
|
+
$tU: 'bob',
|
|
71
|
+
'$hdr(content-type)': 'application/sdp',
|
|
72
|
+
$rb: '!{_}a=sendrecv',
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
event: 'media_update',
|
|
77
|
+
call_id: oc.id,
|
|
78
|
+
status: 'ok',
|
|
79
|
+
media: [
|
|
80
|
+
{
|
|
81
|
+
type: 'audio',
|
|
82
|
+
local: {
|
|
83
|
+
port: 10000,
|
|
84
|
+
mode: 'sendrecv'
|
|
85
|
+
},
|
|
86
|
+
remote: {
|
|
87
|
+
port: 10002,
|
|
88
|
+
mode: 'sendrecv'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
event: 'media_update',
|
|
95
|
+
call_id: ic.id,
|
|
96
|
+
status: 'ok',
|
|
97
|
+
media: [
|
|
98
|
+
{
|
|
99
|
+
type: 'audio',
|
|
100
|
+
local: {
|
|
101
|
+
port: 10002,
|
|
102
|
+
mode: 'sendrecv'
|
|
103
|
+
},
|
|
104
|
+
remote: {
|
|
105
|
+
port: 10000,
|
|
106
|
+
mode: 'sendrecv'
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
], 1000)
|
|
112
|
+
|
|
113
|
+
sip.call.send_dtmf(oc.id, {digits: '1234', mode: 1})
|
|
114
|
+
sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
|
|
115
|
+
|
|
116
|
+
await z.wait([
|
|
117
|
+
{
|
|
118
|
+
event: 'dtmf',
|
|
119
|
+
call_id: ic.id,
|
|
120
|
+
digits: '1234',
|
|
121
|
+
mode: 1,
|
|
122
|
+
media_id: 0
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
event: 'dtmf',
|
|
126
|
+
call_id: oc.id,
|
|
127
|
+
digits: '4321',
|
|
128
|
+
mode: 1,
|
|
129
|
+
media_id: 0
|
|
130
|
+
},
|
|
131
|
+
], 1500)
|
|
132
|
+
|
|
133
|
+
sip.call.terminate(oc.id)
|
|
134
|
+
|
|
135
|
+
await z.wait([
|
|
136
|
+
{
|
|
137
|
+
event: 'call_ended',
|
|
138
|
+
call_id: oc.id,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
event: 'call_ended',
|
|
142
|
+
call_id: ic.id,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
event: 'response',
|
|
146
|
+
call_id: oc.id,
|
|
147
|
+
method: 'BYE',
|
|
148
|
+
msg: sip_msg({
|
|
149
|
+
$rs: '200',
|
|
150
|
+
$rr: 'OK',
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
|
+
], 1000)
|
|
154
|
+
|
|
155
|
+
console.log("Success")
|
|
156
|
+
|
|
157
|
+
sip.stop()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
test()
|
|
162
|
+
.catch(e => {
|
|
163
|
+
console.error(e)
|
|
164
|
+
process.exit(1)
|
|
165
|
+
})
|
|
166
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
var assert = require('assert')
|
|
7
|
+
|
|
8
|
+
async function test() {
|
|
9
|
+
sip.set_log_level(9)
|
|
10
|
+
sip.dtmf_aggregation_on(500)
|
|
11
|
+
|
|
12
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
13
|
+
var e = evt.args[0]
|
|
14
|
+
return e
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
18
|
+
|
|
19
|
+
t1 = sip.transport.create({address: "127.0.0.1", port: 5090, type: 'udp'})
|
|
20
|
+
t2 = sip.transport.create({address: "127.0.0.1", port: 5092, type: 'udp'})
|
|
21
|
+
|
|
22
|
+
console.log("t1", t1)
|
|
23
|
+
console.log("t2", t2)
|
|
24
|
+
|
|
25
|
+
var server = `${t2.address}:${t2.port}`
|
|
26
|
+
var domain = 'test1.com'
|
|
27
|
+
|
|
28
|
+
var a1 = sip.account.create(t1.id, {
|
|
29
|
+
domain,
|
|
30
|
+
server,
|
|
31
|
+
username: 'user1',
|
|
32
|
+
password: 'pass1',
|
|
33
|
+
headers: {
|
|
34
|
+
'X-MyHeader1': 'aaa',
|
|
35
|
+
'X-MyHeader2': 'bbb',
|
|
36
|
+
},
|
|
37
|
+
expires: 0, // this will cause suppression of header Expires.
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
sip.account.register(a1, {auto_refresh: true})
|
|
41
|
+
|
|
42
|
+
await z.wait([
|
|
43
|
+
{
|
|
44
|
+
event: 'non_dialog_request',
|
|
45
|
+
request_id: m.collect('req_id'),
|
|
46
|
+
msg: sip_msg({
|
|
47
|
+
$rm: 'REGISTER',
|
|
48
|
+
$fU: 'user1',
|
|
49
|
+
$fd: domain,
|
|
50
|
+
$tU: 'user1',
|
|
51
|
+
$td: domain,
|
|
52
|
+
'$hdr(X-MyHeader1)': 'aaa',
|
|
53
|
+
hdr_x_myheader2: 'bbb',
|
|
54
|
+
hdr_expires: m.absent,
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
], 1000)
|
|
58
|
+
|
|
59
|
+
sip.request.respond(z.store.req_id, {code: 200, reason: 'OK', headers: {Expires: '120'}})
|
|
60
|
+
|
|
61
|
+
await z.wait([
|
|
62
|
+
{
|
|
63
|
+
event: 'registration_status',
|
|
64
|
+
account_id: a1.id,
|
|
65
|
+
code: 200,
|
|
66
|
+
reason: 'OK',
|
|
67
|
+
expires: 120,
|
|
68
|
+
},
|
|
69
|
+
], 1000)
|
|
70
|
+
|
|
71
|
+
console.log("Success")
|
|
72
|
+
|
|
73
|
+
sip.stop()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
test()
|
|
78
|
+
.catch(e => {
|
|
79
|
+
console.error(e)
|
|
80
|
+
process.exit(1)
|
|
81
|
+
})
|
|
82
|
+
|
|
@@ -6,7 +6,7 @@ var sip_msg = require('sip-matching')
|
|
|
6
6
|
var assert = require('assert')
|
|
7
7
|
|
|
8
8
|
async function test() {
|
|
9
|
-
|
|
9
|
+
sip.set_log_level(9)
|
|
10
10
|
sip.dtmf_aggregation_on(500)
|
|
11
11
|
|
|
12
12
|
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
@@ -34,6 +34,7 @@ async function test() {
|
|
|
34
34
|
'X-MyHeader1': 'aaa',
|
|
35
35
|
'X-MyHeader2': 'bbb',
|
|
36
36
|
},
|
|
37
|
+
expires: 60,
|
|
37
38
|
})
|
|
38
39
|
|
|
39
40
|
sip.account.register(a1, {auto_refresh: true})
|
|
@@ -41,6 +42,7 @@ async function test() {
|
|
|
41
42
|
await z.wait([
|
|
42
43
|
{
|
|
43
44
|
event: 'non_dialog_request',
|
|
45
|
+
request_id: m.collect('req_id'),
|
|
44
46
|
msg: sip_msg({
|
|
45
47
|
$rm: 'REGISTER',
|
|
46
48
|
$fU: 'user1',
|
|
@@ -48,12 +50,13 @@ async function test() {
|
|
|
48
50
|
$tU: 'user1',
|
|
49
51
|
$td: domain,
|
|
50
52
|
'$hdr(X-MyHeader1)': 'aaa',
|
|
51
|
-
|
|
53
|
+
hdr_x_myheader2: 'bbb',
|
|
54
|
+
hdr_expires: '60',
|
|
52
55
|
}),
|
|
53
56
|
},
|
|
54
57
|
], 1000)
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
sip.request.respond(z.store.req_id, {code: 200, reason: 'OK', headers: {Expires: '60'}})
|
|
57
60
|
|
|
58
61
|
await z.wait([
|
|
59
62
|
{
|
|
@@ -125,24 +128,53 @@ async function test() {
|
|
|
125
128
|
},
|
|
126
129
|
], 1000)
|
|
127
130
|
|
|
128
|
-
// Subscription-State expires will be computed by pjsip. It might not be the exact value of sub_expires due to
|
|
131
|
+
// Subscription-State expires will be computed by pjsip. It might not be the exact value of sub_expires due to latency so we give 2 seconds of tolerance
|
|
129
132
|
assert(z.store.sub_expires > (sub_expires - 2))
|
|
130
133
|
|
|
134
|
+
sip.subscriber.notify(subscriber_id, {
|
|
135
|
+
content_type: 'application/dialog-info+xml',
|
|
136
|
+
body: '<dialog>bla bla bla</dialog>',
|
|
137
|
+
subscription_state: 4,
|
|
138
|
+
reason: 'normal',
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
await z.wait([
|
|
142
|
+
{
|
|
143
|
+
event: 'request',
|
|
144
|
+
subscription_id: s1,
|
|
145
|
+
msg: sip_msg({
|
|
146
|
+
$rm: 'NOTIFY',
|
|
147
|
+
hdr_event: 'dialog',
|
|
148
|
+
hdr_subscription_state: 'active;expires=!{expires}',
|
|
149
|
+
hdr_content_type: 'application/dialog-info+xml',
|
|
150
|
+
$rb: '<dialog>bla bla bla</dialog>',
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
|
+
], 1000)
|
|
154
|
+
|
|
155
|
+
await z.sleep(100)
|
|
156
|
+
|
|
157
|
+
z.store.req_id = null
|
|
158
|
+
|
|
131
159
|
sip.account.unregister(a1)
|
|
132
160
|
|
|
133
161
|
await z.wait([
|
|
134
162
|
{
|
|
135
163
|
event: 'non_dialog_request',
|
|
164
|
+
request_id: m.collect('req_id'),
|
|
136
165
|
msg: sip_msg({
|
|
137
166
|
$rm: 'REGISTER',
|
|
138
167
|
$fU: 'user1',
|
|
139
168
|
$fd: domain,
|
|
140
169
|
$tU: 'user1',
|
|
141
170
|
$td: domain,
|
|
171
|
+
hdr_expires: '0',
|
|
142
172
|
}),
|
|
143
173
|
},
|
|
144
174
|
], 1000)
|
|
145
175
|
|
|
176
|
+
sip.request.respond(z.store.req_id, {code: 200, reason: 'OK', headers: {Expires: '0'}})
|
|
177
|
+
|
|
146
178
|
await z.wait([
|
|
147
179
|
{
|
|
148
180
|
event: 'registration_status',
|