sip-lab 1.13.0 → 1.14.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.
@@ -0,0 +1,328 @@
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
+ async function test() {
9
+ sip.set_log_level(9)
10
+
11
+ //sip.set_log_level(6)
12
+ sip.dtmf_aggregation_on(500)
13
+
14
+ // Let's ignore '100 Trying'
15
+ z.add_event_filter({
16
+ event: 'response',
17
+ msg: sip_msg({
18
+ $rs: '100',
19
+ }),
20
+ })
21
+
22
+ z.trap_events(sip.event_source, 'event', (evt) => {
23
+ var e = evt.args[0]
24
+ return e
25
+ })
26
+
27
+ console.log(sip.start((data) => { console.log(data)} ))
28
+
29
+ t1 = sip.transport.create({address: "127.0.0.1", port: 5090, type: 'udp'})
30
+ t2 = sip.transport.create({address: "127.0.0.1", port: 5092, type: 'udp'})
31
+
32
+ console.log("t1", t1)
33
+ console.log("t2", t2)
34
+
35
+ oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`, media: [
36
+ "audio",
37
+ {
38
+ type: "audio",
39
+ port: 0, // it means not in use
40
+ },
41
+ "audio",
42
+ {
43
+ type: "audio",
44
+ port: 0, // it means not in use
45
+ }
46
+ ]})
47
+
48
+ await z.wait([
49
+ {
50
+ event: "incoming_call",
51
+ call_id: m.collect("call_id"),
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', media: [
61
+ "audio",
62
+ {
63
+ type: "audio",
64
+ port: 0, // it means not in use
65
+ },
66
+ "audio",
67
+ {
68
+ type: "audio",
69
+ port: 0, // it means not in use
70
+ }
71
+ ]})
72
+
73
+ await z.wait([
74
+ {
75
+ event: 'response',
76
+ call_id: oc.id,
77
+ method: 'INVITE',
78
+ msg: sip_msg({
79
+ $rs: '200',
80
+ $rr: 'OK',
81
+ '$(hdrcnt(VIA))': 1,
82
+ $fU: 'alice',
83
+ $fd: 'test.com',
84
+ $tU: 'bob',
85
+ '$hdr(content-type)': 'application/sdp',
86
+ $rb: '!{_}a=sendrecv',
87
+ }),
88
+ },
89
+ {
90
+ event: 'media_update',
91
+ call_id: oc.id,
92
+ status: 'ok',
93
+ media: [
94
+ {
95
+ type: 'audio',
96
+ local: {},
97
+ },
98
+ {
99
+ type: 'audio',
100
+ port: 0,
101
+ },
102
+ {
103
+ type: 'audio',
104
+ local: {},
105
+ },
106
+ {
107
+ type: 'audio',
108
+ port: 0,
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ event: 'media_update',
114
+ call_id: ic.id,
115
+ status: 'ok',
116
+ media: [
117
+ {
118
+ type: 'audio',
119
+ local: {},
120
+ },
121
+ {
122
+ type: 'audio',
123
+ port: 0,
124
+ },
125
+ {
126
+ type: 'audio',
127
+ local: {},
128
+ },
129
+ {
130
+ type: 'audio',
131
+ port: 0,
132
+ },
133
+ ],
134
+ },
135
+ ], 1000)
136
+
137
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
138
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
139
+
140
+ await z.wait([
141
+ {
142
+ event: 'dtmf',
143
+ call_id: ic.id,
144
+ digits: '1234',
145
+ mode: 0,
146
+ media_id: 0
147
+ },
148
+ {
149
+ event: 'dtmf',
150
+ call_id: ic.id,
151
+ digits: '1234',
152
+ mode: 0,
153
+ media_id: 2
154
+ },
155
+ {
156
+ event: 'dtmf',
157
+ call_id: oc.id,
158
+ digits: '4321',
159
+ mode: 1,
160
+ media_id: 0
161
+ },
162
+ {
163
+ event: 'dtmf',
164
+ call_id: oc.id,
165
+ digits: '4321',
166
+ mode: 1,
167
+ media_id: 2
168
+ },
169
+ ], 2000)
170
+
171
+ sip.call.reinvite(oc.id, {media: [
172
+ "audio",
173
+ {
174
+ type: "audio",
175
+ port: 0, // it means not in use
176
+ },
177
+ "audio",
178
+ {
179
+ type: "audio",
180
+ port: 0, // it means not in use
181
+ }
182
+ ]})
183
+
184
+ await z.wait([
185
+ {
186
+ event: 'reinvite',
187
+ call_id: ic.id,
188
+ },
189
+ ], 1000)
190
+
191
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: [
192
+ "audio",
193
+ {
194
+ type: "audio",
195
+ port: 0, // it means not in use
196
+ },
197
+ "audio",
198
+ {
199
+ type: "audio",
200
+ port: 0, // it means not in use
201
+ }
202
+ ]})
203
+
204
+ await z.wait([
205
+ {
206
+ event: 'response',
207
+ call_id: oc.id,
208
+ method: 'INVITE',
209
+ msg: sip_msg({
210
+ $rs: '200',
211
+ }),
212
+ },
213
+ {
214
+ event: 'media_update',
215
+ call_id: ic.id,
216
+ status: 'ok',
217
+ media: [
218
+ {
219
+ type: 'audio',
220
+ local: {}
221
+ },
222
+ {
223
+ type: 'audio',
224
+ port: 0,
225
+ },
226
+ {
227
+ type: 'audio',
228
+ local: {},
229
+ },
230
+ {
231
+ type: 'audio',
232
+ port: 0,
233
+ },
234
+ ],
235
+ },
236
+ {
237
+ event: 'media_update',
238
+ call_id: oc.id,
239
+ status: 'ok',
240
+ media: [
241
+ {
242
+ type: 'audio',
243
+ local: {}
244
+ },
245
+ {
246
+ type: 'audio',
247
+ port: 0,
248
+ },
249
+ {
250
+ type: 'audio',
251
+ local: {},
252
+ },
253
+ {
254
+ type: 'audio',
255
+ port: 0,
256
+ },
257
+ ],
258
+ },
259
+ ], 1000)
260
+
261
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
262
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
263
+
264
+ await z.wait([
265
+ {
266
+ event: 'dtmf',
267
+ call_id: ic.id,
268
+ digits: '1234',
269
+ mode: 0,
270
+ media_id: 0
271
+ },
272
+ {
273
+ event: 'dtmf',
274
+ call_id: ic.id,
275
+ digits: '1234',
276
+ mode: 0,
277
+ media_id: 2
278
+ },
279
+ {
280
+ event: 'dtmf',
281
+ call_id: oc.id,
282
+ digits: '4321',
283
+ mode: 1,
284
+ media_id: 0
285
+ },
286
+ {
287
+ event: 'dtmf',
288
+ call_id: oc.id,
289
+ digits: '4321',
290
+ mode: 1,
291
+ media_id: 2
292
+ },
293
+ ], 2000)
294
+
295
+ sip.call.terminate(oc.id)
296
+
297
+ await z.wait([
298
+ {
299
+ event: 'call_ended',
300
+ call_id: oc.id,
301
+ },
302
+ {
303
+ event: 'call_ended',
304
+ call_id: ic.id,
305
+ },
306
+ {
307
+ event: 'response',
308
+ call_id: oc.id,
309
+ method: 'BYE',
310
+ msg: sip_msg({
311
+ $rs: '200',
312
+ $rr: 'OK',
313
+ }),
314
+ },
315
+ ], 1000)
316
+
317
+ console.log("Success")
318
+
319
+ sip.stop()
320
+ }
321
+
322
+
323
+ test()
324
+ .catch(e => {
325
+ console.error(e)
326
+ process.exit(1)
327
+ })
328
+
package/samples/g729.js CHANGED
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  var assert = require('assert')
8
9
 
@@ -3,9 +3,9 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var mrcp = require('mrcp')
7
8
  var mrcp_msg = require('mrcp-matching')
8
- var sdp_msg = require('sdp-matching')
9
9
 
10
10
  async function test() {
11
11
  sip.set_log_level(9)
@@ -115,7 +115,7 @@ async function test() {
115
115
  $fd: 'test.com',
116
116
  $tU: 'bob',
117
117
  '$hdr(content-type)': 'application/sdp',
118
- $rb: sdp_msg({
118
+ $rb: sdp.jsonpath_matcher({
119
119
  '$.media[?(@.desc.type=="application")].val_attrs.channel': [m.collect('mrcp_channel')],
120
120
  }),
121
121
  }),
@@ -407,8 +407,6 @@ async function test() {
407
407
  },
408
408
  ], 500)
409
409
 
410
- await z.sleep(1000) // we need this delay otherwise, frequently the app will crash after this point.
411
-
412
410
  sip.call.terminate(oc.id)
413
411
 
414
412
  await z.wait([
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  sip.set_log_level(9)
@@ -235,8 +236,6 @@ async function test() {
235
236
  //await z.sleep(100)
236
237
  }
237
238
 
238
- await z.sleep(1000) // we need this delay otherwise, frequently the app will crash after this point.
239
-
240
239
  sip.call.terminate(oc.id)
241
240
 
242
241
  await z.wait([
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
  var assert = require('assert')
7
8
 
8
9
  async function test() {
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -130,7 +131,7 @@ async function test() {
130
131
  mode: 1,
131
132
  media_id: 1
132
133
  },
133
- ], 1500)
134
+ ], 2000)
134
135
 
135
136
  sip.call.reinvite(oc.id, {media: 'audio,audio'})
136
137
 
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(9)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(6)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  sip.set_log_level(6)
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  sip.set_log_level(9)
@@ -45,7 +46,7 @@ async function test() {
45
46
  sip_call_id: z.store.sip_call_id,
46
47
  }
47
48
 
48
- sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio,audio"})
49
+ sip.call.respond(ic.id, {code: 200, reason: 'OK', media: "audio"})
49
50
 
50
51
  await z.wait([
51
52
  {
@@ -70,9 +71,11 @@ async function test() {
70
71
  media: [
71
72
  {
72
73
  type: 'audio',
74
+ local: {},
73
75
  },
74
76
  {
75
77
  type: 'audio',
78
+ port: 0,
76
79
  }
77
80
  ],
78
81
  },
@@ -83,9 +86,11 @@ async function test() {
83
86
  media: [
84
87
  {
85
88
  type: 'audio',
89
+ local: {},
86
90
  },
87
91
  {
88
92
  type: 'audio',
93
+ port: 0,
89
94
  }
90
95
  ],
91
96
  },
@@ -109,22 +114,9 @@ async function test() {
109
114
  mode: 1,
110
115
  media_id: 0
111
116
  },
112
- {
113
- event: 'dtmf',
114
- call_id: ic.id,
115
- digits: '1234',
116
- mode: 0,
117
- media_id: 1
118
- },
119
- {
120
- event: 'dtmf',
121
- call_id: oc.id,
122
- digits: '4321',
123
- mode: 1,
124
- media_id: 1
125
- },
126
117
  ], 2000)
127
118
 
119
+ // now reinvite with two media
128
120
  sip.call.reinvite(oc.id, {media: "audio,audio"})
129
121
 
130
122
  await z.wait([
@@ -153,13 +145,9 @@ async function test() {
153
145
  {
154
146
  type: 'audio',
155
147
  local: {
156
- addr: '127.0.0.1',
157
- port: 10004,
158
148
  mode: 'sendrecv'
159
149
  },
160
150
  remote: {
161
- addr: '127.0.0.1',
162
- port: 10000,
163
151
  mode: 'sendrecv'
164
152
  },
165
153
  fmt: [
@@ -170,13 +158,9 @@ async function test() {
170
158
  {
171
159
  type: 'audio',
172
160
  local: {
173
- addr: '127.0.0.1',
174
- port: 10006,
175
161
  mode: 'sendrecv'
176
162
  },
177
163
  remote: {
178
- addr: '127.0.0.1',
179
- port: 10002,
180
164
  mode: 'sendrecv'
181
165
  },
182
166
  fmt: [
@@ -194,13 +178,9 @@ async function test() {
194
178
  {
195
179
  type: 'audio',
196
180
  local: {
197
- addr: '127.0.0.1',
198
- port: 10000,
199
181
  mode: 'sendrecv'
200
182
  },
201
183
  remote: {
202
- addr: '127.0.0.1',
203
- port: 10004,
204
184
  mode: 'sendrecv'
205
185
  },
206
186
  fmt: [
@@ -211,13 +191,9 @@ async function test() {
211
191
  {
212
192
  type: 'audio',
213
193
  local: {
214
- addr: '127.0.0.1',
215
- port: 10002,
216
194
  mode: 'sendrecv'
217
195
  },
218
196
  remote: {
219
- addr: '127.0.0.1',
220
- port: 10006,
221
197
  mode: 'sendrecv'
222
198
  },
223
199
  fmt: [
@@ -260,13 +236,9 @@ async function test() {
260
236
  {
261
237
  type: 'audio',
262
238
  local: {
263
- addr: '127.0.0.1',
264
- port: 10004,
265
239
  mode: 'sendrecv'
266
240
  },
267
241
  remote: {
268
- addr: '127.0.0.1',
269
- port: 10000,
270
242
  mode: 'sendrecv'
271
243
  },
272
244
  fmt: [
@@ -274,6 +246,10 @@ async function test() {
274
246
  '120 telephone-event/8000'
275
247
  ]
276
248
  },
249
+ {
250
+ type: 'audio',
251
+ port: 0,
252
+ },
277
253
  ]
278
254
  },
279
255
  {
@@ -284,13 +260,9 @@ async function test() {
284
260
  {
285
261
  type: 'audio',
286
262
  local: {
287
- addr: '127.0.0.1',
288
- port: 10000,
289
263
  mode: 'sendrecv'
290
264
  },
291
265
  remote: {
292
- addr: '127.0.0.1',
293
- port: 10004,
294
266
  mode: 'sendrecv'
295
267
  },
296
268
  fmt: [
@@ -298,6 +270,10 @@ async function test() {
298
270
  '120 telephone-event/8000'
299
271
  ]
300
272
  },
273
+ {
274
+ type: 'audio',
275
+ port: 0,
276
+ },
301
277
  ]
302
278
  },
303
279
  ], 1000)
@@ -351,13 +327,9 @@ async function test() {
351
327
  {
352
328
  type: 'audio',
353
329
  local: {
354
- addr: '127.0.0.1',
355
- port: 10004,
356
330
  mode: 'sendrecv'
357
331
  },
358
332
  remote: {
359
- addr: '127.0.0.1',
360
- port: 10000,
361
333
  mode: 'sendrecv'
362
334
  },
363
335
  fmt: [
@@ -368,13 +340,9 @@ async function test() {
368
340
  {
369
341
  type: 'audio',
370
342
  local: {
371
- addr: '127.0.0.1',
372
- port: 10006,
373
343
  mode: 'sendrecv'
374
344
  },
375
345
  remote: {
376
- addr: '127.0.0.1',
377
- port: 10002,
378
346
  mode: 'sendrecv'
379
347
  },
380
348
  fmt: [
@@ -392,13 +360,9 @@ async function test() {
392
360
  {
393
361
  type: 'audio',
394
362
  local: {
395
- addr: '127.0.0.1',
396
- port: 10000,
397
363
  mode: 'sendrecv'
398
364
  },
399
365
  remote: {
400
- addr: '127.0.0.1',
401
- port: 10004,
402
366
  mode: 'sendrecv'
403
367
  },
404
368
  fmt: [
@@ -409,13 +373,9 @@ async function test() {
409
373
  {
410
374
  type: 'audio',
411
375
  local: {
412
- addr: '127.0.0.1',
413
- port: 10002,
414
376
  mode: 'sendrecv'
415
377
  },
416
378
  remote: {
417
- addr: '127.0.0.1',
418
- port: 10006,
419
379
  mode: 'sendrecv'
420
380
  },
421
381
  fmt: [
@@ -3,6 +3,7 @@ var Zeq = require('@mayama/zeq')
3
3
  var z = new Zeq()
4
4
  var m = require('data-matching')
5
5
  var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
6
7
 
7
8
  async function test() {
8
9
  //sip.set_log_level(6)