sip-lab 1.13.1 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-lab",
3
- "version": "1.13.1",
3
+ "version": "1.14.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -21,18 +21,18 @@
21
21
  "gypfile": true,
22
22
  "homepage": "https://github.com/MayamaTakeshi/sip-lab",
23
23
  "dependencies": {
24
- "@mayama/zeq": "^4.1.17",
24
+ "@mayama/zeq": "^4.7.1",
25
25
  "mrcp": "^1.4.0",
26
26
  "mrcp-matching": "^1.0.0",
27
27
  "node-addon-api": "^5.0.0",
28
28
  "node-gyp": "^9.3.0",
29
29
  "node-gyp-build": "^4.5.0",
30
- "sdp-matching": "^1.2.0",
31
- "sip-matching": "^1.3.34"
30
+ "sip-matching": "^1.5.2"
32
31
  },
33
32
  "devDependencies": {
34
33
  "prebuildify": "^5.0.1",
35
- "prebuildify-cross": "github:MayamaTakeshi/prebuildify-cross#use_existing_images"
34
+ "prebuildify-cross": "github:MayamaTakeshi/prebuildify-cross#use_existing_images",
35
+ "sdp-matching": "^1.3.2"
36
36
  },
37
37
  "files": [
38
38
  "index.js",
Binary file
Binary file
@@ -0,0 +1,246 @@
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", type: 'udp'})
30
+ t2 = sip.transport.create({address: "127.0.0.1", 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}`})
36
+
37
+ await z.wait([
38
+ {
39
+ event: "incoming_call",
40
+ call_id: m.collect("call_id"),
41
+ },
42
+ ], 1000)
43
+
44
+ ic = {
45
+ id: z.store.call_id,
46
+ sip_call_id: z.store.sip_call_id,
47
+ }
48
+
49
+ sip.call.respond(ic.id, {code: 183, reason: 'Session Progress'})
50
+
51
+ await z.wait([
52
+ {
53
+ event: 'response',
54
+ call_id: oc.id,
55
+ method: 'INVITE',
56
+ msg: sip_msg({
57
+ $rs: '183',
58
+ $rr: 'Session Progress',
59
+ '$(hdrcnt(VIA))': 1,
60
+ $fU: 'alice',
61
+ $fd: 'test.com',
62
+ $tU: 'bob',
63
+ '$hdr(content-type)': 'application/sdp',
64
+ $rb: '!{_}a=sendrecv',
65
+ }),
66
+ },
67
+ {
68
+ event: 'media_update',
69
+ call_id: oc.id,
70
+ status: 'ok',
71
+ media: [
72
+ {
73
+ type: 'audio',
74
+ },
75
+ ],
76
+ },
77
+ {
78
+ event: 'media_update',
79
+ call_id: ic.id,
80
+ status: 'ok',
81
+ media: [
82
+ {
83
+ type: 'audio',
84
+ },
85
+ ],
86
+ },
87
+ ], 1000)
88
+
89
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
90
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
91
+
92
+ await z.wait([
93
+ {
94
+ event: 'dtmf',
95
+ call_id: ic.id,
96
+ digits: '1234',
97
+ mode: 0,
98
+ media_id: 0
99
+ },
100
+ {
101
+ event: 'dtmf',
102
+ call_id: oc.id,
103
+ digits: '4321',
104
+ mode: 1,
105
+ media_id: 0
106
+ },
107
+ ], 2000)
108
+
109
+ await z.sleep(1000)
110
+
111
+ sip.call.respond(ic.id, {code: 200, reason: 'OK'})
112
+
113
+ await z.wait([
114
+ {
115
+ event: 'response',
116
+ call_id: oc.id,
117
+ method: 'INVITE',
118
+ msg: sip_msg({
119
+ $rs: '183',
120
+ $rr: 'Session Progress',
121
+ '$(hdrcnt(VIA))': 1,
122
+ $fU: 'alice',
123
+ $fd: 'test.com',
124
+ $tU: 'bob',
125
+ '$hdr(content-type)': 'application/sdp',
126
+ $rb: '!{_}a=sendrecv',
127
+ }),
128
+ },
129
+ ], 1000)
130
+
131
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
132
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
133
+
134
+ await z.wait([
135
+ {
136
+ event: 'dtmf',
137
+ call_id: ic.id,
138
+ digits: '1234',
139
+ mode: 0,
140
+ media_id: 0
141
+ },
142
+ {
143
+ event: 'dtmf',
144
+ call_id: oc.id,
145
+ digits: '4321',
146
+ mode: 1,
147
+ media_id: 0
148
+ },
149
+ ], 2000)
150
+
151
+ sip.call.reinvite(oc.id)
152
+
153
+ await z.wait([
154
+ {
155
+ event: 'reinvite',
156
+ call_id: ic.id,
157
+ },
158
+ ], 1000)
159
+
160
+ sip.call.respond(ic.id, {code: 200, reason: 'OK'})
161
+
162
+ await z.wait([
163
+ {
164
+ event: 'response',
165
+ call_id: oc.id,
166
+ method: 'INVITE',
167
+ msg: sip_msg({
168
+ $rs: '200',
169
+ }),
170
+ },
171
+ {
172
+ event: 'media_update',
173
+ call_id: ic.id,
174
+ status: 'ok',
175
+ media: [
176
+ {
177
+ type: 'audio',
178
+ },
179
+ ]
180
+ },
181
+ {
182
+ event: 'media_update',
183
+ call_id: oc.id,
184
+ status: 'ok',
185
+ media: [
186
+ {
187
+ type: 'audio',
188
+ },
189
+ ]
190
+ },
191
+ ], 1000)
192
+
193
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
194
+ sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
195
+
196
+ await z.wait([
197
+ {
198
+ event: 'dtmf',
199
+ call_id: ic.id,
200
+ digits: '1234',
201
+ mode: 0,
202
+ media_id: 0
203
+ },
204
+ {
205
+ event: 'dtmf',
206
+ call_id: oc.id,
207
+ digits: '4321',
208
+ mode: 1,
209
+ media_id: 0
210
+ },
211
+ ], 2000)
212
+
213
+ sip.call.terminate(oc.id)
214
+
215
+ await z.wait([
216
+ {
217
+ event: 'call_ended',
218
+ call_id: oc.id,
219
+ },
220
+ {
221
+ event: 'call_ended',
222
+ call_id: ic.id,
223
+ },
224
+ {
225
+ event: 'response',
226
+ call_id: oc.id,
227
+ method: 'BYE',
228
+ msg: sip_msg({
229
+ $rs: '200',
230
+ $rr: 'OK',
231
+ }),
232
+ },
233
+ ], 1000)
234
+
235
+ console.log("Success")
236
+
237
+ sip.stop()
238
+ }
239
+
240
+
241
+ test()
242
+ .catch(e => {
243
+ console.error(e)
244
+ process.exit(1)
245
+ })
246
+
@@ -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)
@@ -65,15 +66,25 @@ async function test() {
65
66
  $fd: 'test.com',
66
67
  $tU: 'bob',
67
68
  '$hdr(content-type)': 'application/sdp',
68
- $rb: '!{_}a=sendrecv',
69
+ $rb: sdp.matcher({
70
+ media: m.full_match([
71
+ m.partial_match({
72
+ desc: {
73
+ type: 'audio',
74
+ port: m.nonzero,
75
+ protocol: "RTP/AVP",
76
+ },
77
+ }),
78
+ ]),
79
+ })
69
80
  }),
70
81
  },
71
82
  {
72
83
  event: 'media_update',
73
84
  call_id: oc.id,
74
85
  status: 'ok',
75
- media: [
76
- {
86
+ media: m.full_match([
87
+ m.partial_match({
77
88
  type: 'audio',
78
89
  local: {
79
90
  mode: 'sendrecv'
@@ -81,15 +92,15 @@ async function test() {
81
92
  remote: {
82
93
  mode: 'sendrecv'
83
94
  },
84
- }
85
- ],
95
+ }),
96
+ ]),
86
97
  },
87
98
  {
88
99
  event: 'media_update',
89
100
  call_id: ic.id,
90
101
  status: 'ok',
91
- media: [
92
- {
102
+ media: m.full_match([
103
+ m.partial_match({
93
104
  type: 'audio',
94
105
  local: {
95
106
  mode: 'sendrecv'
@@ -97,8 +108,8 @@ async function test() {
97
108
  remote: {
98
109
  mode: 'sendrecv'
99
110
  },
100
- }
101
- ],
111
+ }),
112
+ ]),
102
113
  },
103
114
 
104
115
  ], 1000)
@@ -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([