sip-lab 1.16.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/samples/16_calls.js +152 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-lab",
3
- "version": "1.16.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",
@@ -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
+