@babblevoice/babble-drachtio-callmanager 2.3.0 → 2.3.2
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/lib/call.js +38 -16
- package/lib/store.js +44 -27
- package/package.json +1 -1
- package/test/unit/store.js +7 -7
package/lib/call.js
CHANGED
|
@@ -787,9 +787,11 @@ class call {
|
|
|
787
787
|
/**
|
|
788
788
|
Allows 3rd parties to emit events to listeners specific to this call.
|
|
789
789
|
@param { string } ev - event name
|
|
790
|
+
@param { any } argv1
|
|
790
791
|
*/
|
|
791
|
-
emit( ev ) {
|
|
792
|
-
this._em.emit( ev,
|
|
792
|
+
emit( ev, argv1 ) {
|
|
793
|
+
if( argv1 ) return this._em.emit( ev, argv1 )
|
|
794
|
+
else return this._em.emit( ev, this )
|
|
793
795
|
}
|
|
794
796
|
|
|
795
797
|
/**
|
|
@@ -1570,7 +1572,7 @@ class call {
|
|
|
1570
1572
|
} catch ( e ) { console.trace( e ) }
|
|
1571
1573
|
|
|
1572
1574
|
switch( e.action ) {
|
|
1573
|
-
case "close":
|
|
1575
|
+
case "close":
|
|
1574
1576
|
this.#handlechannelevclose( e )
|
|
1575
1577
|
return
|
|
1576
1578
|
case "telephone-event":
|
|
@@ -1911,6 +1913,10 @@ class call {
|
|
|
1911
1913
|
other.channels.audio.dtmf( digit )
|
|
1912
1914
|
}
|
|
1913
1915
|
|
|
1916
|
+
try {
|
|
1917
|
+
this._em.emit( "channel", { "call": this, "event": { action: "telephone-event", event: digit, source: "sip-info" } } )
|
|
1918
|
+
} catch ( e ) { console.trace( e ) }
|
|
1919
|
+
|
|
1914
1920
|
return res.send( 200 )
|
|
1915
1921
|
}
|
|
1916
1922
|
|
|
@@ -2460,16 +2466,17 @@ class call {
|
|
|
2460
2466
|
|
|
2461
2467
|
/* If max-forwards is not specified then we decrement the parent and pass on */
|
|
2462
2468
|
if( !( "headers" in options ) ) options.headers = {}
|
|
2469
|
+
|
|
2470
|
+
let maxforwards = 70
|
|
2463
2471
|
if( !options.headers[ Object.keys( options.headers ).find( key => "max-forwards" === key.toLowerCase() ) ] ) {
|
|
2464
|
-
if(
|
|
2465
|
-
|
|
2472
|
+
if( this._req.has( "Max-Forwards" ) ) {
|
|
2473
|
+
maxforwards = parseInt( this._req.get( "Max-Forwards" ) ) - 1
|
|
2474
|
+
if( isNaN( maxforwards ) || 0 >= maxforwards ) return false
|
|
2466
2475
|
}
|
|
2467
|
-
|
|
2468
|
-
const maxforwards = parseInt( this._req.get( "Max-Forwards" ) )
|
|
2469
|
-
if( 0 >= maxforwards ) return false
|
|
2470
|
-
options.headers[ "Max-Forwards" ] = maxforwards - 1
|
|
2471
2476
|
}
|
|
2472
2477
|
|
|
2478
|
+
options.headers[ "Max-Forwards" ] = maxforwards
|
|
2479
|
+
|
|
2473
2480
|
if( !options.orphan ) {
|
|
2474
2481
|
options.parent = this
|
|
2475
2482
|
}
|
|
@@ -2491,12 +2498,8 @@ class call {
|
|
|
2491
2498
|
}
|
|
2492
2499
|
return true
|
|
2493
2500
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
*
|
|
2497
|
-
* @returns { Promise< boolean | object > }
|
|
2498
|
-
*/
|
|
2499
|
-
static async #callcontactfornewuac( options, callbacks ) {
|
|
2501
|
+
|
|
2502
|
+
static async #sanityforcallcontact( options ) {
|
|
2500
2503
|
|
|
2501
2504
|
if( !( await call.#checkmaxcallsforentity( options ) ) ) return false
|
|
2502
2505
|
|
|
@@ -2505,13 +2508,27 @@ class call {
|
|
|
2505
2508
|
if( !options.entity ) return false
|
|
2506
2509
|
|
|
2507
2510
|
const contactinfo = await callmanager.options.registrar.contacts( options.entity )
|
|
2508
|
-
|
|
2509
2511
|
if( 0 == contactinfo.contacts.length )
|
|
2510
2512
|
return false
|
|
2511
2513
|
|
|
2512
2514
|
if( options.first )
|
|
2513
2515
|
contactinfo.contacts = [ contactinfo.contacts[ 0 ] ]
|
|
2514
2516
|
|
|
2517
|
+
return contactinfo
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
/**
|
|
2521
|
+
*
|
|
2522
|
+
* @returns { Promise< boolean | object > }
|
|
2523
|
+
*/
|
|
2524
|
+
static async #callcontactfornewuac( options, callbacks ) {
|
|
2525
|
+
|
|
2526
|
+
const contactinfo = await call.#sanityforcallcontact( options )
|
|
2527
|
+
if( !contactinfo ) {
|
|
2528
|
+
if( callbacks.fail ) callbacks.fail()
|
|
2529
|
+
return false
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2515
2532
|
let numcontacts = 0
|
|
2516
2533
|
const ourcallbacks = {}
|
|
2517
2534
|
let failcount = 0
|
|
@@ -2556,6 +2573,11 @@ class call {
|
|
|
2556
2573
|
}
|
|
2557
2574
|
}
|
|
2558
2575
|
|
|
2576
|
+
if( 0 == numcontacts ) {
|
|
2577
|
+
if( callbacks.fail ) callbacks.fail()
|
|
2578
|
+
return false
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2559
2581
|
const child = await waitonchildrenpromise
|
|
2560
2582
|
return child
|
|
2561
2583
|
}
|
package/lib/store.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
let storebycallid = new Map()
|
|
4
4
|
let storebyuuid = new Map()
|
|
5
5
|
let storebyentity = new Map()
|
|
6
|
-
let
|
|
6
|
+
let storebyrealm = new Map()
|
|
7
7
|
|
|
8
8
|
/** @module store */
|
|
9
9
|
|
|
@@ -104,6 +104,7 @@ function fixentity( c ) {
|
|
|
104
104
|
* @param {object} c.entity - entity object
|
|
105
105
|
* @param {object} c.entity.uri
|
|
106
106
|
* @param {object} c._entity
|
|
107
|
+
* @param {object} c.destination
|
|
107
108
|
* @param {object} [ c._state ]
|
|
108
109
|
* @param {boolean} [ c._state._hangup ]
|
|
109
110
|
* @return {Promise} - which resolves on completion (for future in case we support redis or similar)
|
|
@@ -118,21 +119,29 @@ module.exports.set = async ( c ) => {
|
|
|
118
119
|
storebyuuid.set( c.uuid, c )
|
|
119
120
|
addtocallidset( c )
|
|
120
121
|
|
|
122
|
+
let realm = ""
|
|
123
|
+
const destination = c.destination
|
|
124
|
+
if( destination ) realm = c.destination.host
|
|
125
|
+
|
|
121
126
|
const entity = fixentity( c )
|
|
122
|
-
if( "boolean"
|
|
127
|
+
if( "boolean" !== typeof entity ) {
|
|
128
|
+
|
|
129
|
+
let storedentity = storebyentity.get( entity.uri )
|
|
130
|
+
if( !storedentity ) {
|
|
131
|
+
storedentity = new Map()
|
|
132
|
+
storebyentity.set( entity.uri, storedentity )
|
|
133
|
+
}
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
storedentity = new Map()
|
|
127
|
-
storebyentity.set( entity.uri, storedentity )
|
|
135
|
+
storedentity.set( c.uuid, c )
|
|
136
|
+
realm = entity.realm
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
|
|
139
|
+
if( !realm ) return true
|
|
131
140
|
|
|
132
|
-
let storedentityrealm =
|
|
141
|
+
let storedentityrealm = storebyrealm.get( realm )
|
|
133
142
|
if( !storedentityrealm ) {
|
|
134
143
|
storedentityrealm = new Map()
|
|
135
|
-
|
|
144
|
+
storebyrealm.set( realm, storedentityrealm )
|
|
136
145
|
}
|
|
137
146
|
storedentityrealm.set( c.uuid, c )
|
|
138
147
|
|
|
@@ -154,11 +163,14 @@ module.exports.getbyentity = async ( uri ) => {
|
|
|
154
163
|
* @param {string} realm - the entity realm
|
|
155
164
|
* @return {Promise} which resolves to either a set containing calls for this entity or undefined
|
|
156
165
|
*/
|
|
157
|
-
module.exports.
|
|
158
|
-
if( !
|
|
159
|
-
return
|
|
166
|
+
module.exports.getbyrealm = async ( realm ) => {
|
|
167
|
+
if( !storebyrealm.has( realm ) ) return false
|
|
168
|
+
return storebyrealm.get( realm )
|
|
160
169
|
}
|
|
161
170
|
|
|
171
|
+
/* backwards compat - is now realm more generally */
|
|
172
|
+
module.exports.getbyentityrealm = module.exports.getbyrealm
|
|
173
|
+
|
|
162
174
|
/**
|
|
163
175
|
* Returns a unique call by call id and sip tags.
|
|
164
176
|
* @param {object} sip - sip params required
|
|
@@ -201,22 +213,27 @@ module.exports.delete = async function( c ) {
|
|
|
201
213
|
|
|
202
214
|
deletefromcallidset( c )
|
|
203
215
|
|
|
204
|
-
|
|
205
|
-
|
|
216
|
+
let realm = ""
|
|
217
|
+
const destination = c.destination
|
|
218
|
+
if( destination ) realm = c.destination.host
|
|
206
219
|
|
|
207
|
-
const
|
|
208
|
-
if(
|
|
209
|
-
entityentries.
|
|
210
|
-
if(
|
|
211
|
-
|
|
220
|
+
const entity = fixentity( c )
|
|
221
|
+
if( "boolean" !== typeof entity ) {
|
|
222
|
+
const entityentries = storebyentity.get( entity.uri )
|
|
223
|
+
if( undefined !== entityentries ) {
|
|
224
|
+
entityentries.delete( c.uuid )
|
|
225
|
+
if( 0 === entityentries.size ) {
|
|
226
|
+
storebyentity.delete( entity.uri )
|
|
227
|
+
}
|
|
212
228
|
}
|
|
229
|
+
realm = entity.realm
|
|
213
230
|
}
|
|
214
231
|
|
|
215
|
-
const
|
|
216
|
-
if(
|
|
217
|
-
|
|
218
|
-
if( 0 ===
|
|
219
|
-
|
|
232
|
+
const storedrealm = storebyrealm.get( realm )
|
|
233
|
+
if( storedrealm ) {
|
|
234
|
+
storedrealm.delete( c.uuid )
|
|
235
|
+
if( 0 === storedrealm.size ) {
|
|
236
|
+
storebyrealm.delete( entity.realm )
|
|
220
237
|
}
|
|
221
238
|
}
|
|
222
239
|
}
|
|
@@ -228,7 +245,7 @@ module.exports.clear = async() => {
|
|
|
228
245
|
storebycallid = new Map()
|
|
229
246
|
storebyuuid = new Map()
|
|
230
247
|
storebyentity = new Map()
|
|
231
|
-
|
|
248
|
+
storebyrealm = new Map()
|
|
232
249
|
}
|
|
233
250
|
|
|
234
251
|
/**
|
|
@@ -239,7 +256,7 @@ module.exports.stats = async () => {
|
|
|
239
256
|
"storebycallid": storebycallid.size,
|
|
240
257
|
"storebyuuid": storebyuuid.size,
|
|
241
258
|
"storebyentity": storebyentity.size,
|
|
242
|
-
"
|
|
259
|
+
"storebyrealm": storebyrealm.size
|
|
243
260
|
}
|
|
244
261
|
}
|
|
245
262
|
|
|
@@ -247,5 +264,5 @@ module.exports.stats = async () => {
|
|
|
247
264
|
* Debug only
|
|
248
265
|
*/
|
|
249
266
|
module.exports._dump = () => {
|
|
250
|
-
console.log( storebycallid, storebyuuid, storebyentity,
|
|
267
|
+
console.log( storebycallid, storebyuuid, storebyentity, storebyrealm )
|
|
251
268
|
}
|
package/package.json
CHANGED
package/test/unit/store.js
CHANGED
|
@@ -30,7 +30,7 @@ describe( "callmanager - store", function() {
|
|
|
30
30
|
"storebycallid": 1,
|
|
31
31
|
"storebyuuid": 1,
|
|
32
32
|
"storebyentity": 1,
|
|
33
|
-
"
|
|
33
|
+
"storebyrealm": 1
|
|
34
34
|
} )
|
|
35
35
|
} )
|
|
36
36
|
|
|
@@ -53,7 +53,7 @@ describe( "callmanager - store", function() {
|
|
|
53
53
|
"storebycallid": 1,
|
|
54
54
|
"storebyuuid": 1,
|
|
55
55
|
"storebyentity": 1,
|
|
56
|
-
"
|
|
56
|
+
"storebyrealm": 1
|
|
57
57
|
} )
|
|
58
58
|
|
|
59
59
|
dummycall.sip.tags.local = "4444"
|
|
@@ -63,7 +63,7 @@ describe( "callmanager - store", function() {
|
|
|
63
63
|
"storebycallid": 1,
|
|
64
64
|
"storebyuuid": 1,
|
|
65
65
|
"storebyentity": 1,
|
|
66
|
-
"
|
|
66
|
+
"storebyrealm": 1
|
|
67
67
|
} )
|
|
68
68
|
|
|
69
69
|
let searchfor = {
|
|
@@ -119,7 +119,7 @@ describe( "callmanager - store", function() {
|
|
|
119
119
|
"storebycallid": 2,
|
|
120
120
|
"storebyuuid": 2,
|
|
121
121
|
"storebyentity": 0,
|
|
122
|
-
"
|
|
122
|
+
"storebyrealm": 0
|
|
123
123
|
} )
|
|
124
124
|
|
|
125
125
|
dummycall1._entity = {
|
|
@@ -132,7 +132,7 @@ describe( "callmanager - store", function() {
|
|
|
132
132
|
"storebycallid": 2,
|
|
133
133
|
"storebyuuid": 2,
|
|
134
134
|
"storebyentity": 1,
|
|
135
|
-
"
|
|
135
|
+
"storebyrealm": 1
|
|
136
136
|
} )
|
|
137
137
|
|
|
138
138
|
await callstore.set( dummycall3 )
|
|
@@ -141,7 +141,7 @@ describe( "callmanager - store", function() {
|
|
|
141
141
|
"storebycallid": 3,
|
|
142
142
|
"storebyuuid": 3,
|
|
143
143
|
"storebyentity": 1,
|
|
144
|
-
"
|
|
144
|
+
"storebyrealm": 1
|
|
145
145
|
} )
|
|
146
146
|
|
|
147
147
|
let c = await callstore.getbycallid( dummycall1.sip )
|
|
@@ -158,7 +158,7 @@ describe( "callmanager - store", function() {
|
|
|
158
158
|
"storebycallid": 0,
|
|
159
159
|
"storebyuuid": 0,
|
|
160
160
|
"storebyentity": 0,
|
|
161
|
-
"
|
|
161
|
+
"storebyrealm": 0
|
|
162
162
|
} )
|
|
163
163
|
} )
|
|
164
164
|
} )
|