sip-lab 1.27.0 → 1.27.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/package.json +1 -1
- package/prebuilds/linux-x64/sip-lab.node +0 -0
- package/samples/pcma.js +217 -0
- package/src/sip.cpp +33 -10
package/package.json
CHANGED
|
Binary file
|
package/samples/pcma.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
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 sdp = require('sdp-matching')
|
|
7
|
+
|
|
8
|
+
var assert = require('assert')
|
|
9
|
+
|
|
10
|
+
async function test() {
|
|
11
|
+
//sip.set_log_level(6)
|
|
12
|
+
sip.dtmf_aggregation_on(500)
|
|
13
|
+
|
|
14
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
15
|
+
var e = evt.args[0]
|
|
16
|
+
return e
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
20
|
+
|
|
21
|
+
t1 = sip.transport.create({address: "127.0.0.1", type: 'udp'})
|
|
22
|
+
t2 = sip.transport.create({address: "127.0.0.1", type: 'udp'})
|
|
23
|
+
|
|
24
|
+
console.log("t1", t1)
|
|
25
|
+
console.log("t2", t2)
|
|
26
|
+
|
|
27
|
+
sip.set_codecs("PCMA/8000/1:128")
|
|
28
|
+
|
|
29
|
+
flags = 0
|
|
30
|
+
|
|
31
|
+
oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
|
|
32
|
+
|
|
33
|
+
await z.wait([
|
|
34
|
+
{
|
|
35
|
+
event: "incoming_call",
|
|
36
|
+
call_id: m.collect("call_id"),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
event: 'response',
|
|
40
|
+
call_id: oc.id,
|
|
41
|
+
method: 'INVITE',
|
|
42
|
+
msg: sip_msg({
|
|
43
|
+
$rs: '100',
|
|
44
|
+
$rr: 'Trying',
|
|
45
|
+
'$(hdrcnt(via))': 1,
|
|
46
|
+
'hdr_call_id': m.collect('sip_call_id'),
|
|
47
|
+
$fU: 'alice',
|
|
48
|
+
$fd: 'test.com',
|
|
49
|
+
$tU: 'bob',
|
|
50
|
+
'hdr_l': '0',
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
], 1000)
|
|
54
|
+
|
|
55
|
+
ic = {
|
|
56
|
+
id: z.store.call_id,
|
|
57
|
+
sip_call_id: z.store.sip_call_id,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
61
|
+
|
|
62
|
+
await z.wait([
|
|
63
|
+
{
|
|
64
|
+
event: 'media_update',
|
|
65
|
+
call_id: oc.id,
|
|
66
|
+
status: 'ok',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
event: 'media_update',
|
|
70
|
+
call_id: ic.id,
|
|
71
|
+
status: 'ok',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
event: 'response',
|
|
75
|
+
call_id: oc.id,
|
|
76
|
+
method: 'INVITE',
|
|
77
|
+
msg: sip_msg({
|
|
78
|
+
$rs: '200',
|
|
79
|
+
$rr: 'OK',
|
|
80
|
+
'$(hdrcnt(VIA))': 1,
|
|
81
|
+
$fU: 'alice',
|
|
82
|
+
$fd: 'test.com',
|
|
83
|
+
$tU: 'bob',
|
|
84
|
+
'hdr_content_type': 'application/sdp',
|
|
85
|
+
$rb: '!{_}a=sendrecv',
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
], 1000)
|
|
89
|
+
|
|
90
|
+
sip.call.reinvite(oc.id)
|
|
91
|
+
|
|
92
|
+
await z.wait([
|
|
93
|
+
{
|
|
94
|
+
event: 'reinvite',
|
|
95
|
+
call_id: ic.id
|
|
96
|
+
},
|
|
97
|
+
], 1000)
|
|
98
|
+
|
|
99
|
+
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
100
|
+
|
|
101
|
+
await z.wait([
|
|
102
|
+
{
|
|
103
|
+
event: 'response',
|
|
104
|
+
call_id: oc.id,
|
|
105
|
+
method: 'INVITE',
|
|
106
|
+
msg: sip_msg({
|
|
107
|
+
$rs: '100',
|
|
108
|
+
}),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
event: 'response',
|
|
112
|
+
call_id: oc.id,
|
|
113
|
+
method: 'INVITE',
|
|
114
|
+
msg: sip_msg({
|
|
115
|
+
$rs: '200',
|
|
116
|
+
$rr: 'OK',
|
|
117
|
+
$rb: '!{_}a=sendrecv',
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
event: 'media_update',
|
|
122
|
+
call_id: oc.id,
|
|
123
|
+
status: 'ok',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
event: 'media_update',
|
|
127
|
+
call_id: ic.id,
|
|
128
|
+
status: 'ok',
|
|
129
|
+
},
|
|
130
|
+
], 500)
|
|
131
|
+
|
|
132
|
+
sip.call.reinvite(oc.id, false, 0)
|
|
133
|
+
|
|
134
|
+
await z.wait([
|
|
135
|
+
{
|
|
136
|
+
event: 'reinvite',
|
|
137
|
+
call_id: ic.id
|
|
138
|
+
},
|
|
139
|
+
], 1000)
|
|
140
|
+
|
|
141
|
+
sip.call.respond(ic.id, {code: 200, reason: 'OK'})
|
|
142
|
+
|
|
143
|
+
await z.wait([
|
|
144
|
+
{
|
|
145
|
+
event: 'response',
|
|
146
|
+
call_id: oc.id,
|
|
147
|
+
method: 'INVITE',
|
|
148
|
+
msg: sip_msg({
|
|
149
|
+
$rs: '100',
|
|
150
|
+
}),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
event: 'response',
|
|
154
|
+
call_id: oc.id,
|
|
155
|
+
method: 'INVITE',
|
|
156
|
+
msg: sip_msg({
|
|
157
|
+
$rs: '200',
|
|
158
|
+
$rr: 'OK',
|
|
159
|
+
$rb: '!{_}a=sendrecv',
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
event: 'media_update',
|
|
164
|
+
call_id: oc.id,
|
|
165
|
+
status: 'ok',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
event: 'media_update',
|
|
169
|
+
call_id: ic.id,
|
|
170
|
+
status: 'ok',
|
|
171
|
+
},
|
|
172
|
+
], 500)
|
|
173
|
+
|
|
174
|
+
oc_stat = sip.call.get_stream_stat(oc.id, {media_id: 0})
|
|
175
|
+
ic_stat = sip.call.get_stream_stat(ic.id, {media_id: 0})
|
|
176
|
+
|
|
177
|
+
console.log(oc_stat)
|
|
178
|
+
console.log(ic_stat)
|
|
179
|
+
|
|
180
|
+
oc_stat = JSON.parse(oc_stat)
|
|
181
|
+
ic_stat = JSON.parse(ic_stat)
|
|
182
|
+
|
|
183
|
+
assert(oc_stat.CodecInfo == 'PCMA/8000/1')
|
|
184
|
+
assert(ic_stat.CodecInfo == 'PCMA/8000/1')
|
|
185
|
+
|
|
186
|
+
sip.call.terminate(oc.id)
|
|
187
|
+
|
|
188
|
+
await z.wait([
|
|
189
|
+
{
|
|
190
|
+
event: 'call_ended',
|
|
191
|
+
call_id: oc.id,
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
event: 'call_ended',
|
|
195
|
+
call_id: ic.id,
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
event: 'response',
|
|
199
|
+
call_id: oc.id,
|
|
200
|
+
method: 'BYE',
|
|
201
|
+
msg: sip_msg({
|
|
202
|
+
$rs: '200',
|
|
203
|
+
$rr: 'OK',
|
|
204
|
+
}),
|
|
205
|
+
},
|
|
206
|
+
], 1000)
|
|
207
|
+
|
|
208
|
+
console.log("Success")
|
|
209
|
+
|
|
210
|
+
sip.stop()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
test()
|
|
214
|
+
.catch(e => {
|
|
215
|
+
console.error(e)
|
|
216
|
+
process.exit(1)
|
|
217
|
+
})
|
package/src/sip.cpp
CHANGED
|
@@ -1510,8 +1510,8 @@ pjsip_transport *create_udp_transport(pjsip_endpoint *sip_endpt,
|
|
|
1510
1510
|
// pj_status_t status;
|
|
1511
1511
|
pjsip_transport *transport;
|
|
1512
1512
|
|
|
1513
|
-
int port = 5060;
|
|
1514
1513
|
for (int i = 0; i < 1000; ++i) {
|
|
1514
|
+
int port = 5060;
|
|
1515
1515
|
port += i;
|
|
1516
1516
|
transport = allocate_udp_transport(sip_endpt, ipaddr, port);
|
|
1517
1517
|
if (transport) {
|
|
@@ -1558,8 +1558,8 @@ pjsip_tpfactory *create_tcp_tpfactory(pjsip_endpoint *sip_endpt,
|
|
|
1558
1558
|
// pj_status_t status;
|
|
1559
1559
|
pjsip_tpfactory *tpfactory;
|
|
1560
1560
|
|
|
1561
|
-
int port = 6060;
|
|
1562
1561
|
for (int i = 0; i < 1000; ++i) {
|
|
1562
|
+
int port = 6060;
|
|
1563
1563
|
port += i;
|
|
1564
1564
|
tpfactory = allocate_tcp_tpfactory(sip_endpt, ipaddr, port);
|
|
1565
1565
|
if (tpfactory) {
|
|
@@ -1609,8 +1609,8 @@ pjsip_tpfactory *create_tls_tpfactory(pjsip_endpoint *sip_endpt,
|
|
|
1609
1609
|
// pj_status_t status;
|
|
1610
1610
|
pjsip_tpfactory *tpfactory;
|
|
1611
1611
|
|
|
1612
|
-
int port = 6060;
|
|
1613
1612
|
for (int i = 0; i < 1000; ++i) {
|
|
1613
|
+
int port = 6060;
|
|
1614
1614
|
port += i;
|
|
1615
1615
|
tpfactory = allocate_tls_tpfactory(sip_endpt, ipaddr, port);
|
|
1616
1616
|
if (tpfactory) {
|
|
@@ -4682,12 +4682,6 @@ bool start_tcp_media(Call *call, MediaEndpoint *me,
|
|
|
4682
4682
|
void close_audio_endpoint_ports_and_conf(Call *call, AudioEndpoint *ae) {
|
|
4683
4683
|
pj_status_t status;
|
|
4684
4684
|
|
|
4685
|
-
audio_endpoint_remove_port(call, ae, &ae->stream_cbp);
|
|
4686
|
-
|
|
4687
|
-
for(int i=0 ; i<MAX_FP ; i++) {
|
|
4688
|
-
audio_endpoint_remove_port(call, ae, &ae->feature_cbps[i]);
|
|
4689
|
-
}
|
|
4690
|
-
|
|
4691
4685
|
if (ae->master_port) {
|
|
4692
4686
|
status = pjmedia_master_port_stop(ae->master_port);
|
|
4693
4687
|
if(status != PJ_SUCCESS) {
|
|
@@ -4700,6 +4694,12 @@ void close_audio_endpoint_ports_and_conf(Call *call, AudioEndpoint *ae) {
|
|
|
4700
4694
|
ae->master_port = NULL;
|
|
4701
4695
|
}
|
|
4702
4696
|
|
|
4697
|
+
audio_endpoint_remove_port(call, ae, &ae->stream_cbp);
|
|
4698
|
+
|
|
4699
|
+
for(int i=0 ; i<MAX_FP ; i++) {
|
|
4700
|
+
audio_endpoint_remove_port(call, ae, &ae->feature_cbps[i]);
|
|
4701
|
+
}
|
|
4702
|
+
|
|
4703
4703
|
if (ae->conf) {
|
|
4704
4704
|
status = pjmedia_conf_destroy(ae->conf);
|
|
4705
4705
|
if(status != PJ_SUCCESS) {
|
|
@@ -4751,6 +4751,19 @@ bool restart_media_stream(Call *call, MediaEndpoint *me,
|
|
|
4751
4751
|
pjmedia_port *old_port = ae->stream_cbp.port;
|
|
4752
4752
|
pjmedia_port *new_port;
|
|
4753
4753
|
|
|
4754
|
+
bool master_port_was_stopped = false;
|
|
4755
|
+
|
|
4756
|
+
if(ae->master_port) {
|
|
4757
|
+
status = pjmedia_master_port_stop(ae->master_port);
|
|
4758
|
+
if(status != PJ_SUCCESS) {
|
|
4759
|
+
make_evt_media_update(evt, sizeof(evt), call->id,
|
|
4760
|
+
"setup_failed (pjmedia_master_port_stop failed)", "");
|
|
4761
|
+
dispatch_event(evt);
|
|
4762
|
+
return false;
|
|
4763
|
+
}
|
|
4764
|
+
master_port_was_stopped = true;
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4754
4767
|
status =
|
|
4755
4768
|
pjmedia_stream_info_from_sdp(&stream_info, call->inv->dlg->pool,
|
|
4756
4769
|
g_med_endpt, local_sdp, remote_sdp, idx);
|
|
@@ -4906,7 +4919,17 @@ bool restart_media_stream(Call *call, MediaEndpoint *me,
|
|
|
4906
4919
|
}
|
|
4907
4920
|
}
|
|
4908
4921
|
}
|
|
4909
|
-
|
|
4922
|
+
|
|
4923
|
+
if(master_port_was_stopped) {
|
|
4924
|
+
status = pjmedia_master_port_start(ae->master_port);
|
|
4925
|
+
if(status != PJ_SUCCESS) {
|
|
4926
|
+
make_evt_media_update(evt, sizeof(evt), call->id,
|
|
4927
|
+
"setup_failed (pjmedia_master_port_start failed)", "");
|
|
4928
|
+
dispatch_event(evt);
|
|
4929
|
+
return false;
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
|
|
4910
4933
|
return true;
|
|
4911
4934
|
}
|
|
4912
4935
|
|