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.
@@ -1,273 +0,0 @@
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
-
7
- async function test() {
8
- sip.set_log_level(9)
9
-
10
- //sip.set_log_level(6)
11
- sip.dtmf_aggregation_on(500)
12
-
13
- z.trap_events(sip.event_source, 'event', (evt) => {
14
- var e = evt.args[0]
15
- return e
16
- })
17
-
18
- console.log(sip.start((data) => { console.log(data)} ))
19
-
20
- t1 = sip.transport.create({address: "127.0.0.1", port: 5090, type: 'udp'})
21
- t2 = sip.transport.create({address: "127.0.0.1", port: 5092, type: 'udp'})
22
-
23
- console.log("t1", t1)
24
- console.log("t2", t2)
25
-
26
- oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`, media: [{type: 'mrcp'}, {type: 'audio'}]})
27
-
28
- await z.wait([
29
- {
30
- event: "incoming_call",
31
- call_id: m.collect("call_id"),
32
- },
33
- {
34
- event: 'response',
35
- call_id: oc.id,
36
- method: 'INVITE',
37
- msg: sip_msg({
38
- $rs: '100',
39
- $rr: 'Trying',
40
- '$(hdrcnt(via))': 1,
41
- '$hdr(call-id)': m.collect('sip_call_id'),
42
- $fU: 'alice',
43
- $fd: 'test.com',
44
- $tU: 'bob',
45
- '$hdr(l)': '0',
46
- }),
47
- },
48
- ], 1000)
49
-
50
- ic = {
51
- id: z.store.call_id,
52
- sip_call_id: z.store.sip_call_id,
53
- }
54
-
55
- sip.call.respond(ic.id, {code: 200, reason: 'OK', media: [{type: 'audio'}, {type: 'mrcp'}]})
56
-
57
- await z.wait([
58
- {
59
- event: 'response',
60
- call_id: oc.id,
61
- method: 'INVITE',
62
- msg: sip_msg({
63
- $rs: '200',
64
- $rr: 'OK',
65
- '$(hdrcnt(VIA))': 1,
66
- $fU: 'alice',
67
- $fd: 'test.com',
68
- $tU: 'bob',
69
- '$hdr(content-type)': 'application/sdp',
70
- $rb: '!{_}a=sendrecv',
71
- }),
72
- },
73
- {
74
- event: 'media_update',
75
- call_id: oc.id,
76
- status: 'ok',
77
- media: [
78
- {
79
- type: 'mrcp',
80
- local: {
81
- port: 9
82
- },
83
- remote: {
84
- port: m.collect('mrcp_server_port')
85
- }
86
- },
87
- {
88
- type: 'audio',
89
- local: {
90
- port: 10000,
91
- mode: 'sendrecv'
92
- },
93
- remote: {
94
- port: 10002,
95
- mode: 'sendrecv'
96
- }
97
- },
98
- ],
99
- },
100
- {
101
- event: 'media_update',
102
- call_id: ic.id,
103
- status: 'ok',
104
- media: [
105
- {
106
- type: 'mrcp',
107
- local: {
108
- port: m.collect('mrcp_server_port')
109
- },
110
- remote: {
111
- port: 9
112
- }
113
- },
114
- {
115
- type: 'audio',
116
- local: {
117
- port: 10002,
118
- mode: 'sendrecv'
119
- },
120
- remote: {
121
- port: 10000,
122
- mode: 'sendrecv'
123
- }
124
- },
125
- ],
126
- },
127
- ], 1000)
128
-
129
- sip.call.send_dtmf(oc.id, {digits: '1234', mode: 0})
130
- sip.call.send_dtmf(ic.id, {digits: '4321', mode: 1})
131
-
132
- await z.wait([
133
- {
134
- event: 'dtmf',
135
- call_id: ic.id,
136
- digits: '1234',
137
- mode: 0,
138
- media_id: 1
139
- },
140
- {
141
- event: 'dtmf',
142
- call_id: oc.id,
143
- digits: '4321',
144
- mode: 1,
145
- media_id: 1
146
- },
147
- ], 1500)
148
-
149
- for(i=0 ;i< 1; i++) {
150
- //await z.sleep(100)
151
- sip.call.reinvite(oc.id, {media: [{type: 'mrcp'}, {type: 'audio'}]})
152
-
153
- await z.wait([
154
- {
155
- event: 'reinvite',
156
- call_id: ic.id,
157
- },
158
- ], 500)
159
-
160
- sip.call.respond(ic.id, {code: 200, reason: 'OK', media: [{type: 'audio'}, {type: 'mrcp'}]})
161
-
162
- await z.wait([
163
- {
164
- event: 'response',
165
- call_id: oc.id,
166
- method: 'INVITE',
167
- msg: sip_msg({
168
- $rs: '100',
169
- }),
170
- },
171
- {
172
- event: 'response',
173
- call_id: oc.id,
174
- method: 'INVITE',
175
- msg: sip_msg({
176
- $rs: '200',
177
- $rr: 'OK',
178
- $rb: '!{_}a=sendrecv',
179
- }),
180
- },
181
- {
182
- event: 'media_update',
183
- call_id: oc.id,
184
- status: 'ok',
185
- },
186
- {
187
- event: 'media_update',
188
- call_id: ic.id,
189
- status: 'ok',
190
- },
191
- ], 500)
192
-
193
- //await z.sleep(100)
194
- sip.call.reinvite(ic.id, {media: [{type: 'mrcp'}, {type: 'audio'}]})
195
-
196
- await z.wait([
197
- {
198
- event: 'reinvite',
199
- call_id: oc.id,
200
- },
201
- ], 500)
202
-
203
- sip.call.respond(oc.id, {code: 200, reason: 'OK', media: [{type: 'audio'}, {type: 'mrcp'}]})
204
-
205
- await z.wait([
206
- {
207
- event: 'response',
208
- call_id: ic.id,
209
- method: 'INVITE',
210
- msg: sip_msg({
211
- $rs: '100',
212
- }),
213
- },
214
- {
215
- event: 'response',
216
- call_id: ic.id,
217
- method: 'INVITE',
218
- msg: sip_msg({
219
- $rs: '200',
220
- $rr: 'OK',
221
- }),
222
- },
223
- {
224
- event: 'media_update',
225
- call_id: oc.id,
226
- status: 'ok',
227
- },
228
- {
229
- event: 'media_update',
230
- call_id: ic.id,
231
- status: 'ok',
232
- },
233
- ], 500)
234
-
235
- //await z.sleep(100)
236
- }
237
-
238
- await z.sleep(1000) // we need this delay otherwise, frequently the app will crash after this point.
239
-
240
- sip.call.terminate(oc.id)
241
-
242
- await z.wait([
243
- {
244
- event: 'call_ended',
245
- call_id: oc.id,
246
- },
247
- {
248
- event: 'call_ended',
249
- call_id: ic.id,
250
- },
251
- {
252
- event: 'response',
253
- call_id: oc.id,
254
- method: 'BYE',
255
- msg: sip_msg({
256
- $rs: '200',
257
- $rr: 'OK',
258
- }),
259
- },
260
- ], 1000)
261
-
262
- console.log("Success")
263
-
264
- sip.stop()
265
- }
266
-
267
-
268
- test()
269
- .catch(e => {
270
- console.error(e)
271
- process.exit(1)
272
- })
273
-