@babblevoice/babble-drachtio-callmanager 2.0.2 → 2.0.3

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,9 +1,7 @@
1
1
 
2
2
  const expect = require( "chai" ).expect
3
- const callmanager = require( "../../index.js" )
4
3
  const call = require( "../../lib/call.js" )
5
4
  const srf = require( "../mock/srf.js" )
6
- const projectrtp = require( "@babblevoice/projectrtp" ).projectrtp
7
5
 
8
6
  /* These DO NOT form part of our interface */
9
7
  const clearcallmanager = require( "../../lib/callmanager.js" )._clear
@@ -18,22 +16,21 @@ describe( "xfer", function() {
18
16
  clearcallmanager()
19
17
  } )
20
18
 
21
- it( `call blind xfer single leg should fail`, async function() {
19
+ it( "call blind xfer single leg should fail", async function() {
22
20
 
23
- let srfscenario = new srf.srfscenario()
21
+ const srfscenario = new srf.srfscenario()
24
22
 
25
- let call = await new Promise( ( resolve ) => {
23
+ const call = await new Promise( ( resolve ) => {
26
24
  srfscenario.oncall( async ( call ) => { resolve( call ) } )
27
25
  srfscenario.inbound()
28
26
  } )
29
27
 
30
- let req = new srf.req( new srf.options() )
31
- let res = new srf.res()
28
+ const req = new srf.req( new srf.options() )
29
+ const res = new srf.res()
32
30
 
33
- let sipcodesent, msgsent
34
- res.onsend( ( sipcode, msg ) => {
31
+ let sipcodesent
32
+ res.onsend( ( sipcode ) => {
35
33
  sipcodesent = sipcode
36
- msgsent = msg
37
34
  } )
38
35
 
39
36
  await call.answer()
@@ -46,7 +43,7 @@ describe( "xfer", function() {
46
43
 
47
44
  } )
48
45
 
49
- it( `call blind xfer 2 leg no auth`, async function() {
46
+ it( "call blind xfer 2 leg no auth", async function() {
50
47
 
51
48
  /*
52
49
  Client a Us Client b
@@ -65,9 +62,9 @@ describe( "xfer", function() {
65
62
  em.emit( "call.referred", call )
66
63
  */
67
64
 
68
- let srfscenario = new srf.srfscenario()
65
+ const srfscenario = new srf.srfscenario()
69
66
 
70
- let call = await new Promise( ( resolve ) => {
67
+ const call = await new Promise( ( resolve ) => {
71
68
  srfscenario.oncall( async ( call ) => { resolve( call ) } )
72
69
  srfscenario.inbound()
73
70
  } )
@@ -82,19 +79,18 @@ describe( "xfer", function() {
82
79
  globalev = r
83
80
  } )
84
81
 
85
- let req = new srf.req( new srf.options() )
86
- let res = new srf.res()
82
+ const req = new srf.req( new srf.options() )
83
+ const res = new srf.res()
87
84
 
88
85
  req.setparsedheader( "refer-to", { "uri": "sip:alice@atlanta.example.com" } )
89
86
 
90
- let sipcodesent, msgsent
91
- res.onsend( ( sipcode, msg ) => {
87
+ let sipcodesent
88
+ res.onsend( ( sipcode ) => {
92
89
  sipcodesent = sipcode
93
- msgsent = msg
94
90
  } )
95
91
 
96
92
  await call.answer()
97
- let child = await call.newuac( { "contact": "1000@dummy" } )
93
+ const child = await call.newuac( { "contact": "1000@dummy" } )
98
94
  child.referauthrequired = false
99
95
 
100
96
  await child._dialog.callbacks.refer( req, res )
@@ -121,7 +117,7 @@ describe( "xfer", function() {
121
117
 
122
118
  } )
123
119
 
124
- it( `call blind xfer 2 leg auth`, async function() {
120
+ it( "call blind xfer 2 leg auth", async function() {
125
121
 
126
122
  /*
127
123
  Client a Us Client b
@@ -146,7 +142,7 @@ describe( "xfer", function() {
146
142
  */
147
143
 
148
144
  /* Step 1-4 */
149
- let options = {
145
+ const options = {
150
146
  "userlookup": async ( username, realm ) => {
151
147
  return {
152
148
  "secret": "zanzibar",
@@ -156,29 +152,26 @@ describe( "xfer", function() {
156
152
  }
157
153
  }
158
154
 
159
- let srfscenario = new srf.srfscenario( options )
155
+ const srfscenario = new srf.srfscenario( options )
160
156
 
161
- let eventhappened = false
162
157
  srfscenario.options.em.on( "call.authed", ( c ) => {
163
158
  expect( c ).to.be.an.instanceof( call )
164
159
  expect( c.type ).to.be.an( "string" ).to.be.equal( "uas" )
165
- eventhappened = true
166
160
  } )
167
161
 
168
- let c = await new Promise( ( resolve ) => {
162
+ const c = await new Promise( ( resolve ) => {
169
163
  srfscenario.oncall( async ( call ) => {
170
164
  resolve( call )
171
165
  } )
172
166
  srfscenario.inbound()
173
167
  } )
174
168
 
175
- let onsendcount = 0
176
169
  /* mock -
177
170
  auth example from https://datatracker.ietf.org/doc/html/draft-smith-sipping-auth-examples-01 3.3*/
178
171
  c._req.msg.uri = "sip:bob@biloxi.com"
179
172
  c._req.setparsedheader( "from", { "params": { "tag": "767sf76wew" }, "uri": "sip:bob@biloxi.com", "host": "biloxi.com" } )
180
173
 
181
- c._res.onsend( ( code, msg ) => {
174
+ c._res.onsend( ( code ) => {
182
175
 
183
176
  if( 407 == code ) {
184
177
 
@@ -187,19 +180,17 @@ describe( "xfer", function() {
187
180
 
188
181
  /* We would normally look here to get nonce and opaque - howevere we are frigging it */
189
182
  //let request = msg.headers[ "Proxy-Authenticate" ]
190
- let request = `Digest realm="biloxi.com", algorithm=MD5, qop="auth", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false`
183
+ let request = "Digest realm=\"biloxi.com\", algorithm=MD5, qop=\"auth\", nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", opaque=\"5ccc069c403ebaf9f0171e9517f40e41\", stale=false"
191
184
 
192
185
  /* The items a uac will add */
193
- request += `, username="bob", nc=00000001,cnonce="0a4f113b",`
194
- request += ` uri="sip:bob@biloxi.com",`
195
- request += ` response="89eb0059246c02b2f6ee02c7961d5ea3"`
186
+ request += ", username=\"bob\", nc=00000001,cnonce=\"0a4f113b\","
187
+ request += " uri=\"sip:bob@biloxi.com\","
188
+ request += " response=\"89eb0059246c02b2f6ee02c7961d5ea3\""
196
189
 
197
190
  srfscenario.req.set( "Proxy-Authorization", request )
198
191
  c._onauth( srfscenario.req, srfscenario.res )
199
192
 
200
193
  }
201
-
202
- onsendcount++
203
194
  } )
204
195
 
205
196
  let referedcall
@@ -211,34 +202,34 @@ describe( "xfer", function() {
211
202
  await c.answer()
212
203
 
213
204
  /* Step 5-8 */
214
- let child = await c.newuac( { "contact": "1000@dummy" } )
205
+ const child = await c.newuac( { "contact": "1000@dummy" } )
215
206
 
216
207
  /* Step 9-16 */
217
- let req = new srf.req( new srf.options() )
218
- let res = new srf.res()
208
+ const req = new srf.req( new srf.options() )
209
+ const res = new srf.res()
219
210
 
220
211
  req.setparsedheader( "refer-to", { "uri": "sip:alice@atlanta.example.com" } )
221
212
 
222
- let sipcodesent, msgsent
213
+ let sipcodesent
223
214
 
224
215
  req.msg.uri = "sip:bob@biloxi.com"
225
216
  req.setparsedheader( "from", { "params": { "tag": "767sf76wew" }, "uri": "sip:bob@biloxi.com", "host": "biloxi.com" } )
226
217
 
227
- res.onsend( ( code, msg ) => {
218
+ res.onsend( ( code ) => {
228
219
 
229
220
  if( 407 == code ) {
230
221
 
231
222
  child._auth._nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093"
232
223
  child._auth._opaque = "5ccc069c403ebaf9f0171e9517f40e41"
233
224
 
234
- /* We would normally look here to get nonce and opaque - howevere we are frigging it */
225
+ /* We would normally look here to get nonce and opaque - howevere we are frigging it */
235
226
  //let request = msg.headers[ "Proxy-Authenticate" ]
236
- let request = `Digest realm="biloxi.com", algorithm=MD5, qop="auth", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false`
227
+ let request = "Digest realm=\"biloxi.com\", algorithm=MD5, qop=\"auth\", nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", opaque=\"5ccc069c403ebaf9f0171e9517f40e41\", stale=false"
237
228
 
238
229
  /* The items a uac will add */
239
- request += `, username="bob", nc=00000001,cnonce="0a4f113b",`
240
- request += ` uri="sip:bob@biloxi.com",`
241
- request += ` response="89eb0059246c02b2f6ee02c7961d5ea3"`
230
+ request += ", username=\"bob\", nc=00000001,cnonce=\"0a4f113b\","
231
+ request += " uri=\"sip:bob@biloxi.com\","
232
+ request += " response=\"89eb0059246c02b2f6ee02c7961d5ea3\""
242
233
 
243
234
  req.set( "Proxy-Authorization", request )
244
235
 
@@ -276,18 +267,18 @@ describe( "xfer", function() {
276
267
 
277
268
  } )
278
269
 
279
- it( `call attended xfer 2 leg no auth`, async function() {
270
+ it( "call attended xfer 2 leg no auth", async function() {
280
271
  /* using terminology referenced in call.js */
281
- let srfscenario = new srf.srfscenario()
272
+ const srfscenario = new srf.srfscenario()
282
273
 
283
- let b_1 = await new Promise( ( resolve ) => {
274
+ const b_1 = await new Promise( ( resolve ) => {
284
275
  srfscenario.oncall( async ( call ) => { resolve( call ) } )
285
276
  srfscenario.inbound()
286
277
  } )
287
278
 
288
- let a_1 = await b_1.newuac( { "contact": "1000@dummy" } )
279
+ const a_1 = await b_1.newuac( { "contact": "1000@dummy" } )
289
280
 
290
- let b_2 = await new Promise( ( resolve ) => {
281
+ const b_2 = await new Promise( ( resolve ) => {
291
282
  srfscenario.oncall( async ( call ) => { resolve( call ) } )
292
283
  srfscenario.inbound()
293
284
  } )
@@ -295,13 +286,13 @@ describe( "xfer", function() {
295
286
  /* needed for _dialog.on... */
296
287
  await b_2.answer()
297
288
 
298
- let c_1 = await b_2.newuac( { "contact": "1001@dummy" } )
289
+ const c_1 = await b_2.newuac( { "contact": "1001@dummy" } )
299
290
 
300
291
  /* now we refer b_2 to b_1 */
301
- let req = new srf.req( new srf.options() )
302
- let res = new srf.res()
292
+ const req = new srf.req( new srf.options() )
293
+ const res = new srf.res()
303
294
 
304
- let xfermessages = []
295
+ const xfermessages = []
305
296
  res.onsend( ( sipcode, msg ) => {
306
297
  xfermessages.push( {
307
298
  "code": sipcode,
@@ -315,10 +306,10 @@ describe( "xfer", function() {
315
306
 
316
307
  /* Refer-To: <sip:dave@denver.example.org?Replaces=12345%40192.168.118.3%3B
317
308
  to-tag%3D12345%3Bfrom-tag%3D5FFE-3994> */
318
- let callid = b_1.sip.callid
319
- let totag = b_1.sip.tags.local
320
- let fromtag = b_1.sip.tags.remote
321
- let referto = `sip:1000@dummy.com?Replaces=${callid}%3Bto-tag%3D${totag}%3Bfrom-tag%3D${fromtag}`
309
+ const callid = b_1.sip.callid
310
+ const totag = b_1.sip.tags.local
311
+ const fromtag = b_1.sip.tags.remote
312
+ const referto = `sip:1000@dummy.com?Replaces=${callid}%3Bto-tag%3D${totag}%3Bfrom-tag%3D${fromtag}`
322
313
  req.setparsedheader( "refer-to", { "uri": referto } )
323
314
 
324
315
  b_2.referauthrequired = false
@@ -1,79 +0,0 @@
1
-
2
- const prtp = require( "@babblevoice/projectrtp" )
3
- const node = require( "@babblevoice/projectrtp/lib/node" )
4
- const expect = require( "chai" ).expect
5
- const call = require( "../../lib/call" )
6
-
7
- /**
8
- * Test file to run tests acting as a remote note. Starts a babble-rtp node in the background
9
- * before any tests begin then runs tests to open, play, polly etc.
10
- */
11
- describe( "server connect interface", () => {
12
-
13
- before( async () => {
14
- const host = "127.0.0.1"
15
- const port = 9002
16
- await prtp.projectrtp.node.listen( host, port )
17
- prtp.projectrtp.server.addnode( { host, port} )
18
-
19
- } )
20
-
21
- after( () => {
22
- prtp.projectrtp.server.clearnodes()
23
- node.interface.destroy()
24
- } )
25
-
26
- /**
27
- * Primarily testing waitforanyevent and related event handling functions.
28
- */
29
- it( "server connect and open channel", async function () {
30
- this.timeout( 7000 )
31
- this.slow( 5000 )
32
-
33
- const totalotherchannelcount = 100
34
- let chanclosecount = 0
35
- let allchannelsclosedresolve
36
- const allchannelsclosed = new Promise( resolve => allchannelsclosedresolve = resolve )
37
- const onclose = ( e ) => {
38
- if( "close" == e.action ) chanclosecount++
39
- if( totalotherchannelcount == chanclosecount ) allchannelsclosedresolve()
40
- }
41
-
42
- // A very short wav file
43
- prtp.projectrtp.tone.generate( "350+440*0.5:100", "/tmp/serverconnecttestwavghghgh.wav" )
44
- prtp.projectrtp.tone.generate( "350+440*0.5:100", "/tmp/otherserverconnecttestwavghhh.wav" )
45
-
46
- const channels = []
47
- for( let i = 0; totalotherchannelcount > i; i++ ) {
48
- channels.push( await prtp.projectrtp.openchannel( onclose ) )
49
- }
50
-
51
- for( let i = 0; 3 > i; i++ ) {
52
- const ourcall = new call()
53
-
54
- const chan = await prtp.projectrtp.openchannel( ourcall._handlechannelevents.bind( ourcall ) )
55
-
56
- ourcall._em.on( "channel", ( e ) => {
57
- /* For this test we don't want the call object to run our hangup
58
- handlers as they are more complex than we are trying to test here */
59
- if( "close" == e.event.action ) e.event.action = ""
60
- } )
61
-
62
- chan.play( { "interupt":true, "files": [ { "wav": "/tmp/serverconnecttestwavghghgh.wav" }, { "wav": "/tmp/otherserverconnecttestwavghhh.wav" } ] } )
63
-
64
- await ourcall.waitforanyevent( { "action": "play", "event": "start", "reason": "new" } )
65
- await ourcall.waitforanyevent( { "action": "play", "event": "end", "reason": /^((?!replaced).)*$/ } )
66
-
67
- chan.close()
68
- }
69
-
70
- for( const chan of channels ) {
71
- chan.close()
72
- }
73
-
74
- if( 0 != totalotherchannelcount )
75
- await allchannelsclosed
76
- expect( chanclosecount ).to.equal( totalotherchannelcount )
77
- } )
78
-
79
- } )