sip-lab 1.15.0 → 1.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-lab",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -21,7 +21,7 @@
21
21
  "gypfile": true,
22
22
  "homepage": "https://github.com/MayamaTakeshi/sip-lab",
23
23
  "dependencies": {
24
- "@mayama/zeq": "^4.7.1",
24
+ "@mayama/zeq": "^4.12.0",
25
25
  "mrcp": "^1.4.0",
26
26
  "mrcp-matching": "^1.0.0",
27
27
  "node-addon-api": "^5.0.0",
@@ -32,7 +32,8 @@
32
32
  "devDependencies": {
33
33
  "prebuildify": "^6.0.0",
34
34
  "prebuildify-cross": "github:MayamaTakeshi/prebuildify-cross#use_existing_images",
35
- "sdp-matching": "^1.3.2"
35
+ "sdp-matching": "^1.3.2",
36
+ "sipjs-lab": "^1.3.10"
36
37
  },
37
38
  "files": [
38
39
  "index.js",
Binary file
@@ -0,0 +1,152 @@
1
+ // This test creates 256 caller UDP SIP endpoints, 256 callee UDP SIP endpoines and makes one call between them, test dtmf and disconeects.
2
+
3
+ const sip = require ('../index.js')
4
+ const Zeq = require('@mayama/zeq')
5
+ const m = require('data-matching')
6
+ const sip_msg = require('sip-matching')
7
+ const _ = require('lodash')
8
+
9
+ const NUMBER_OF_CALLS = 16
10
+
11
+ var z = new Zeq()
12
+
13
+ sip.dtmf_aggregation_on(500)
14
+
15
+ z.add_event_filter({
16
+ event: 'response',
17
+ msg: sip_msg({
18
+ $rs: '100',
19
+ }),
20
+ })
21
+
22
+ async function test() {
23
+ z.trap_events(sip.event_source, 'event', (evt) => {
24
+ var e = evt.args[0]
25
+ return e
26
+ })
27
+
28
+ console.log(sip.start((data) => { console.log(data)} ))
29
+
30
+ const caller_ts = []
31
+ const callee_ts = []
32
+
33
+ const ocs = []
34
+
35
+ for(var i=0 ; i<NUMBER_OF_CALLS ; i++) {
36
+ const caller_t = sip.transport.create({address: "127.0.0.1"})
37
+ caller_ts.push(caller_t)
38
+ const callee_t = sip.transport.create({address: "127.0.0.1"})
39
+ callee_ts.push(callee_t)
40
+
41
+ // make the call
42
+ const oc = sip.call.create(caller_t.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${callee_t.address}:${callee_t.port}`})
43
+ ocs.push(oc)
44
+ }
45
+
46
+ // Here we will wait for the calls to arrive
47
+ await z.wait(_.chain(callee_ts).map(t => ({
48
+ event: "incoming_call",
49
+ call_id: m.push("ic_ids"),
50
+ transport_id: t.id,
51
+ })).value(), 5000)
52
+
53
+ // Now we answer the calls
54
+ z.store.ic_ids.forEach(ic_id => {
55
+ sip.call.respond(ic_id, {code: 200, reason: 'OK'})
56
+ })
57
+
58
+ // Then we wait for the '200 OK' at the caller side
59
+ var events = _.chain(ocs).map(oc => ({
60
+ event: 'response',
61
+ call_id: oc.id,
62
+ method: 'INVITE',
63
+ msg: sip_msg({
64
+ $rs: '200',
65
+ $rr: 'OK',
66
+ '$(hdrcnt(VIA))': 1,
67
+ $fU: 'alice',
68
+ $fd: 'test.com',
69
+ $tU: 'bob',
70
+ '$hdr(content-type)': 'application/sdp',
71
+ $rb: '!{_}a=sendrecv',
72
+ }),
73
+ })).value()
74
+
75
+ events = events.concat(_.chain(ocs).map(oc => ({
76
+ event: 'media_update',
77
+ call_id: oc.id,
78
+ status: 'ok',
79
+ })).value())
80
+
81
+ events = events.concat(_.chain(z.store.ic_ids).map(ic_id => ({
82
+ event: 'media_update',
83
+ call_id: ic_id,
84
+ status: 'ok',
85
+ })).value())
86
+
87
+ await z.wait(events, 5000)
88
+
89
+ ocs.forEach(oc => {
90
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
91
+ })
92
+
93
+ await z.wait(_.chain(z.store.ic_ids).map(ic_id => ({
94
+ event: 'dtmf',
95
+ call_id: ic_id,
96
+ digits: '1234',
97
+ mode: 0,
98
+ media_id: 0,
99
+ })).value(), 5000)
100
+
101
+ z.store.ic_ids.forEach(ic_id => {
102
+ sip.call.send_dtmf(ic_id, {digits: '4321', mode: 1})
103
+ })
104
+
105
+ await z.wait(_.chain(ocs).map(oc => ({
106
+ event: 'dtmf',
107
+ call_id: oc.id,
108
+ digits: '4321',
109
+ mode: 1,
110
+ media_id: 0,
111
+ })).value(), 5000)
112
+
113
+ // now we terminate the calls
114
+ ocs.forEach(oc => {
115
+ sip.call.terminate(oc.id)
116
+ })
117
+
118
+ // and wait for termination events
119
+ events = _.chain(ocs).map(oc => ({
120
+ event: 'response',
121
+ call_id: oc.id,
122
+ method: 'BYE',
123
+ msg: sip_msg({
124
+ $rs: '200',
125
+ $rr: 'OK',
126
+ }),
127
+ })).value()
128
+
129
+ events = events.concat(_.chain(ocs).map(oc => ({
130
+ event: 'call_ended',
131
+ call_id: oc.id,
132
+ })).value())
133
+
134
+ events = events.concat(_.chain(z.store.ic_ids).map(ic_id => ({
135
+ event: 'call_ended',
136
+ call_id: ic_id,
137
+ })).value())
138
+
139
+ await z.wait(events, 5000)
140
+
141
+ console.log("Success")
142
+
143
+ sip.stop()
144
+ }
145
+
146
+
147
+ test()
148
+ .catch(e => {
149
+ console.error(e)
150
+ process.exit(1)
151
+ })
152
+
@@ -32,7 +32,7 @@ async function test() {
32
32
  console.log("t1", t1)
33
33
  console.log("t2", t2)
34
34
 
35
- oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
35
+ oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`, media: 'audio,audio'})
36
36
 
37
37
  await z.wait([
38
38
  {
@@ -46,7 +46,7 @@ async function test() {
46
46
  sip_call_id: z.store.sip_call_id,
47
47
  }
48
48
 
49
- sip.call.respond(ic.id, {code: 183, reason: 'Session Progress'})
49
+ sip.call.respond(ic.id, {code: 183, reason: 'Session Progress', media: 'audio,audio'})
50
50
 
51
51
  await z.wait([
52
52
  {
@@ -72,6 +72,9 @@ async function test() {
72
72
  {
73
73
  type: 'audio',
74
74
  },
75
+ {
76
+ type: 'audio',
77
+ },
75
78
  ],
76
79
  },
77
80
  {
@@ -82,6 +85,9 @@ async function test() {
82
85
  {
83
86
  type: 'audio',
84
87
  },
88
+ {
89
+ type: 'audio',
90
+ },
85
91
  ],
86
92
  },
87
93
  ], 1000)
@@ -97,6 +103,13 @@ async function test() {
97
103
  mode: 0,
98
104
  media_id: 0
99
105
  },
106
+ {
107
+ event: 'dtmf',
108
+ call_id: ic.id,
109
+ digits: '1234',
110
+ mode: 0,
111
+ media_id: 1
112
+ },
100
113
  {
101
114
  event: 'dtmf',
102
115
  call_id: oc.id,
@@ -104,11 +117,18 @@ async function test() {
104
117
  mode: 1,
105
118
  media_id: 0
106
119
  },
120
+ {
121
+ event: 'dtmf',
122
+ call_id: oc.id,
123
+ digits: '4321',
124
+ mode: 1,
125
+ media_id: 1
126
+ },
107
127
  ], 2000)
108
128
 
109
129
  await z.sleep(1000)
110
130
 
111
- sip.call.respond(ic.id, {code: 200, reason: 'OK'})
131
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: 'audio,audio'})
112
132
 
113
133
  await z.wait([
114
134
  {
@@ -116,8 +136,8 @@ async function test() {
116
136
  call_id: oc.id,
117
137
  method: 'INVITE',
118
138
  msg: sip_msg({
119
- $rs: '183',
120
- $rr: 'Session Progress',
139
+ $rs: '200',
140
+ $rr: 'OK',
121
141
  '$(hdrcnt(VIA))': 1,
122
142
  $fU: 'alice',
123
143
  $fd: 'test.com',
@@ -132,6 +152,19 @@ async function test() {
132
152
  sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
133
153
 
134
154
  await z.wait([
155
+ {
156
+ event: 'media_update',
157
+ call_id: oc.id,
158
+ status: 'ok',
159
+ media: [
160
+ {
161
+ type: 'audio',
162
+ },
163
+ {
164
+ type: 'audio',
165
+ },
166
+ ]
167
+ },
135
168
  {
136
169
  event: 'dtmf',
137
170
  call_id: ic.id,
@@ -139,6 +172,13 @@ async function test() {
139
172
  mode: 0,
140
173
  media_id: 0
141
174
  },
175
+ {
176
+ event: 'dtmf',
177
+ call_id: ic.id,
178
+ digits: '1234',
179
+ mode: 0,
180
+ media_id: 1
181
+ },
142
182
  {
143
183
  event: 'dtmf',
144
184
  call_id: oc.id,
@@ -146,9 +186,16 @@ async function test() {
146
186
  mode: 1,
147
187
  media_id: 0
148
188
  },
189
+ {
190
+ event: 'dtmf',
191
+ call_id: oc.id,
192
+ digits: '4321',
193
+ mode: 1,
194
+ media_id: 1
195
+ },
149
196
  ], 2000)
150
197
 
151
- sip.call.reinvite(oc.id)
198
+ sip.call.reinvite(oc.id, {media: 'audio,audio'})
152
199
 
153
200
  await z.wait([
154
201
  {
@@ -157,7 +204,7 @@ async function test() {
157
204
  },
158
205
  ], 1000)
159
206
 
160
- sip.call.respond(ic.id, {code: 200, reason: 'OK'})
207
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: 'audio,audio'})
161
208
 
162
209
  await z.wait([
163
210
  {
@@ -176,6 +223,9 @@ async function test() {
176
223
  {
177
224
  type: 'audio',
178
225
  },
226
+ {
227
+ type: 'audio',
228
+ },
179
229
  ]
180
230
  },
181
231
  {
@@ -186,6 +236,91 @@ async function test() {
186
236
  {
187
237
  type: 'audio',
188
238
  },
239
+ {
240
+ type: 'audio',
241
+ },
242
+ ]
243
+ },
244
+ ], 1000)
245
+
246
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
247
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
248
+
249
+ await z.wait([
250
+ {
251
+ event: 'dtmf',
252
+ call_id: ic.id,
253
+ digits: '1234',
254
+ mode: 0,
255
+ media_id: 0
256
+ },
257
+ {
258
+ event: 'dtmf',
259
+ call_id: ic.id,
260
+ digits: '1234',
261
+ mode: 0,
262
+ media_id: 1
263
+ },
264
+ {
265
+ event: 'dtmf',
266
+ call_id: oc.id,
267
+ digits: '4321',
268
+ mode: 1,
269
+ media_id: 0
270
+ },
271
+ {
272
+ event: 'dtmf',
273
+ call_id: oc.id,
274
+ digits: '4321',
275
+ mode: 1,
276
+ media_id: 1
277
+ },
278
+ ], 2000)
279
+
280
+ sip.call.reinvite(ic.id, {media: 'audio,audio'})
281
+
282
+ await z.wait([
283
+ {
284
+ event: 'reinvite',
285
+ call_id: oc.id,
286
+ },
287
+ ], 1000)
288
+
289
+ sip.call.respond(oc.id, {code: 200, reason: 'OK', media: 'audio,audio'})
290
+
291
+ await z.wait([
292
+ {
293
+ event: 'response',
294
+ call_id: ic.id,
295
+ method: 'INVITE',
296
+ msg: sip_msg({
297
+ $rs: '200',
298
+ }),
299
+ },
300
+ {
301
+ event: 'media_update',
302
+ call_id: oc.id,
303
+ status: 'ok',
304
+ media: [
305
+ {
306
+ type: 'audio',
307
+ },
308
+ {
309
+ type: 'audio',
310
+ },
311
+ ]
312
+ },
313
+ {
314
+ event: 'media_update',
315
+ call_id: ic.id,
316
+ status: 'ok',
317
+ media: [
318
+ {
319
+ type: 'audio',
320
+ },
321
+ {
322
+ type: 'audio',
323
+ },
189
324
  ]
190
325
  },
191
326
  ], 1000)
@@ -201,6 +336,13 @@ async function test() {
201
336
  mode: 0,
202
337
  media_id: 0
203
338
  },
339
+ {
340
+ event: 'dtmf',
341
+ call_id: ic.id,
342
+ digits: '1234',
343
+ mode: 0,
344
+ media_id: 1
345
+ },
204
346
  {
205
347
  event: 'dtmf',
206
348
  call_id: oc.id,
@@ -208,6 +350,13 @@ async function test() {
208
350
  mode: 1,
209
351
  media_id: 0
210
352
  },
353
+ {
354
+ event: 'dtmf',
355
+ call_id: oc.id,
356
+ digits: '4321',
357
+ mode: 1,
358
+ media_id: 1
359
+ },
211
360
  ], 2000)
212
361
 
213
362
  sip.call.terminate(oc.id)