@babblevoice/babble-drachtio-callmanager 1.1.4 → 1.3.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/lib/call.js +20 -2
- package/lib/store.js +60 -12
- package/package.json +2 -2
- package/test/interface/call.js +39 -11
- package/test/unit/store.js +14 -7
package/lib/call.js
CHANGED
|
@@ -1060,7 +1060,7 @@ class call {
|
|
|
1060
1060
|
|
|
1061
1061
|
this._req.on( "cancel", () => this._oncanceled() )
|
|
1062
1062
|
|
|
1063
|
-
let authorization = this._auth.parseauthheaders( this._req
|
|
1063
|
+
let authorization = this._auth.parseauthheaders( this._req )
|
|
1064
1064
|
|
|
1065
1065
|
if( undefined === callmanager.options.userlookup ) {
|
|
1066
1066
|
this._promises.reject.auth( "no userlookup function provided")
|
|
@@ -1443,6 +1443,24 @@ class call {
|
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* Set the sound soup for music on hold.
|
|
1448
|
+
* @param { object } soup - sound soup as described in projectrtp
|
|
1449
|
+
*/
|
|
1450
|
+
set moh( soup ) {
|
|
1451
|
+
this._moh = soup
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* Return the current moh
|
|
1456
|
+
*/
|
|
1457
|
+
get moh() {
|
|
1458
|
+
if( this._moh ) {
|
|
1459
|
+
return this._moh
|
|
1460
|
+
}
|
|
1461
|
+
return callmanager.options.moh
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1446
1464
|
/**
|
|
1447
1465
|
* If we have been placed on hold (and it has been neotiated) then configure audio to match.
|
|
1448
1466
|
* @private
|
|
@@ -1458,7 +1476,7 @@ class call {
|
|
|
1458
1476
|
let other = this.other
|
|
1459
1477
|
if( other ) {
|
|
1460
1478
|
other.channels.audio.unmix()
|
|
1461
|
-
other.channels.audio.play(
|
|
1479
|
+
other.channels.audio.play( this.moh )
|
|
1462
1480
|
}
|
|
1463
1481
|
|
|
1464
1482
|
this._em.emit( "call.hold", this )
|
package/lib/store.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
let storebycallid = new Map()
|
|
4
4
|
let storebyuuid = new Map()
|
|
5
5
|
let storebyentity = new Map()
|
|
6
|
+
let storebyentityrealm = new Map()
|
|
6
7
|
|
|
7
8
|
/** @module store */
|
|
8
9
|
|
|
@@ -39,14 +40,33 @@ module.exports.set = async ( c ) => {
|
|
|
39
40
|
let entity = c._entity
|
|
40
41
|
if( !entity ) return true
|
|
41
42
|
|
|
43
|
+
if( !entity.uri && entity.username && entity.realm ) {
|
|
44
|
+
entity.uri = entity.username + "@" + entity.realm
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if( entity.uri && !entity.username ) {
|
|
48
|
+
entity.username = entity.uri.split( '@' ).shift()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if( entity.uri && !entity.realm ) {
|
|
52
|
+
entity.realm = entity.uri.split( '@' ).pop()
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
let storedentity = storebyentity.get( entity.uri )
|
|
43
|
-
if(
|
|
56
|
+
if( !storedentity ) {
|
|
44
57
|
storedentity = new Map()
|
|
45
58
|
storebyentity.set( entity.uri, storedentity )
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
storedentity.set( c.uuid, c )
|
|
49
62
|
|
|
63
|
+
let storedentityrealm = storebyentityrealm.get( entity.realm )
|
|
64
|
+
if( !storedentityrealm ) {
|
|
65
|
+
storedentityrealm = new Map()
|
|
66
|
+
storebyentityrealm.set( entity.realm, storedentityrealm )
|
|
67
|
+
}
|
|
68
|
+
storedentityrealm.set( c.uuid, c )
|
|
69
|
+
|
|
50
70
|
return true
|
|
51
71
|
}
|
|
52
72
|
|
|
@@ -60,6 +80,16 @@ module.exports.getbyentity = async ( uri ) => {
|
|
|
60
80
|
return storebyentity.get( uri )
|
|
61
81
|
}
|
|
62
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Retreive call object by realm.
|
|
85
|
+
* @param {string} realm - the entity realm
|
|
86
|
+
* @return {Promise} which resolves to either a set containing calls for this entity or undefined
|
|
87
|
+
*/
|
|
88
|
+
module.exports.getbyentityrealm = async ( realm ) => {
|
|
89
|
+
if( !storebyentityrealm.has( realm ) ) return false
|
|
90
|
+
return storebyentityrealm.get( realm )
|
|
91
|
+
}
|
|
92
|
+
|
|
63
93
|
/**
|
|
64
94
|
* Returns a unique call by call id and sip tags.
|
|
65
95
|
* @param {object} sip - sip params required
|
|
@@ -110,17 +140,33 @@ module.exports.delete = async function( c ) {
|
|
|
110
140
|
}
|
|
111
141
|
|
|
112
142
|
let entity = c._entity
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
143
|
+
if( !entity ) return
|
|
144
|
+
|
|
145
|
+
if( !entity.uri && entity.username && entity.realm ) {
|
|
146
|
+
entity.uri = entity.username + "@" + entity.realm
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if( entity.uri && !entity.username ) {
|
|
150
|
+
entity.username = entity.uri.split( '@' ).shift()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if( entity.uri && !entity.realm ) {
|
|
154
|
+
entity.realm = entity.uri.split( '@' ).pop()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let entityentries = storebyentity.get( entity.uri )
|
|
158
|
+
if( undefined !== entityentries ) {
|
|
159
|
+
entityentries.delete( c.uuid )
|
|
160
|
+
if( 0 === entityentries.size ) {
|
|
161
|
+
storebyentity.delete( entity.uri )
|
|
117
162
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let storedentityrealm = storebyentityrealm.get( entity.realm )
|
|
166
|
+
if( storedentityrealm ) {
|
|
167
|
+
storedentityrealm.delete( c.uuid )
|
|
168
|
+
if( 0 === storedentityrealm.size ) {
|
|
169
|
+
storebyentityrealm.delete( entity.realm )
|
|
124
170
|
}
|
|
125
171
|
}
|
|
126
172
|
}
|
|
@@ -132,6 +178,7 @@ module.exports.clear = async() => {
|
|
|
132
178
|
storebycallid = new Map()
|
|
133
179
|
storebyuuid = new Map()
|
|
134
180
|
storebyentity = new Map()
|
|
181
|
+
storebyentityrealm = new Map()
|
|
135
182
|
}
|
|
136
183
|
|
|
137
184
|
/**
|
|
@@ -141,6 +188,7 @@ module.exports.stats = async () => {
|
|
|
141
188
|
return {
|
|
142
189
|
"storebycallid": storebycallid.size,
|
|
143
190
|
"storebyuuid": storebyuuid.size,
|
|
144
|
-
"storebyentity": storebyentity.size
|
|
191
|
+
"storebyentity": storebyentity.size,
|
|
192
|
+
"storebyentityrealm": storebyentityrealm.size
|
|
145
193
|
}
|
|
146
194
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babblevoice/babble-drachtio-callmanager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Call processing to create a PBX",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babblevoice/babble-drachtio-auth": "^1.0.
|
|
23
|
+
"@babblevoice/babble-drachtio-auth": "^1.0.2",
|
|
24
24
|
"chai": "^4.3.4",
|
|
25
25
|
"drachtio-srf": "^4.4.47",
|
|
26
26
|
"mocha": "^9.2.2",
|
package/test/interface/call.js
CHANGED
|
@@ -752,7 +752,7 @@ describe( "call object", function() {
|
|
|
752
752
|
} )
|
|
753
753
|
|
|
754
754
|
it( `uas.newuac - early callback is called`, async function() {
|
|
755
|
-
|
|
755
|
+
new srf.srfscenario( {} )
|
|
756
756
|
|
|
757
757
|
let options = {
|
|
758
758
|
"contact": "ourcontactstring",
|
|
@@ -768,7 +768,7 @@ describe( "call object", function() {
|
|
|
768
768
|
} )
|
|
769
769
|
|
|
770
770
|
it( `uas.newuac - confirmed callback is called`, async function() {
|
|
771
|
-
|
|
771
|
+
new srf.srfscenario( {} )
|
|
772
772
|
|
|
773
773
|
let options = {
|
|
774
774
|
"contact": "ourcontactstring",
|
|
@@ -784,7 +784,7 @@ describe( "call object", function() {
|
|
|
784
784
|
} )
|
|
785
785
|
|
|
786
786
|
it( `uas.newuac - simple update`, async function() {
|
|
787
|
-
|
|
787
|
+
new srf.srfscenario( {} )
|
|
788
788
|
|
|
789
789
|
let options = {
|
|
790
790
|
"contact": "ourcontactstring",
|
|
@@ -814,7 +814,7 @@ describe( "call object", function() {
|
|
|
814
814
|
} )
|
|
815
815
|
|
|
816
816
|
it( `uas.newuac - simple update - but don't allow as not in allow`, async function() {
|
|
817
|
-
|
|
817
|
+
new srf.srfscenario( {} )
|
|
818
818
|
|
|
819
819
|
let options = {
|
|
820
820
|
"contact": "ourcontactstring",
|
|
@@ -841,7 +841,7 @@ describe( "call object", function() {
|
|
|
841
841
|
} )
|
|
842
842
|
|
|
843
843
|
it( `Test listen and emit event on call object`, async function() {
|
|
844
|
-
|
|
844
|
+
new srf.srfscenario( {} )
|
|
845
845
|
|
|
846
846
|
let options = {
|
|
847
847
|
"contact": "ourcontactstring",
|
|
@@ -864,7 +864,7 @@ describe( "call object", function() {
|
|
|
864
864
|
} )
|
|
865
865
|
|
|
866
866
|
it( `Test listen and emit event on and removealllisteners call object`, async function() {
|
|
867
|
-
|
|
867
|
+
new srf.srfscenario( {} )
|
|
868
868
|
|
|
869
869
|
let options = {
|
|
870
870
|
"contact": "ourcontactstring",
|
|
@@ -890,7 +890,7 @@ describe( "call object", function() {
|
|
|
890
890
|
} )
|
|
891
891
|
|
|
892
892
|
it( `Test listen and emit event on and removealllisteners (none specified) call object`, async function() {
|
|
893
|
-
|
|
893
|
+
new srf.srfscenario( {} )
|
|
894
894
|
|
|
895
895
|
let options = {
|
|
896
896
|
"contact": "ourcontactstring",
|
|
@@ -916,7 +916,7 @@ describe( "call object", function() {
|
|
|
916
916
|
} )
|
|
917
917
|
|
|
918
918
|
it( `Test listen and emit event on and off call object`, async function() {
|
|
919
|
-
|
|
919
|
+
new srf.srfscenario( {} )
|
|
920
920
|
|
|
921
921
|
let options = {
|
|
922
922
|
"contact": "ourcontactstring",
|
|
@@ -944,7 +944,7 @@ describe( "call object", function() {
|
|
|
944
944
|
} )
|
|
945
945
|
|
|
946
946
|
it( `Test listen and emit event once call object`, async function() {
|
|
947
|
-
|
|
947
|
+
new srf.srfscenario( {} )
|
|
948
948
|
|
|
949
949
|
let options = {
|
|
950
950
|
"contact": "ourcontactstring",
|
|
@@ -968,7 +968,7 @@ describe( "call object", function() {
|
|
|
968
968
|
} )
|
|
969
969
|
|
|
970
970
|
it( `Test listen and emit call.pick on call object`, async function() {
|
|
971
|
-
|
|
971
|
+
new srf.srfscenario( {} )
|
|
972
972
|
|
|
973
973
|
let options = {
|
|
974
974
|
"contact": "ourcontactstring",
|
|
@@ -990,7 +990,7 @@ describe( "call object", function() {
|
|
|
990
990
|
} )
|
|
991
991
|
|
|
992
992
|
it( `Create a call and mock rtpengine and ensure we receive events`, async function() {
|
|
993
|
-
|
|
993
|
+
new srf.srfscenario( {} )
|
|
994
994
|
let rtpserver = callmanager.projectrtp.proxy.listen()
|
|
995
995
|
|
|
996
996
|
let connection = net.createConnection( 9002, "127.0.0.1" )
|
|
@@ -1072,4 +1072,32 @@ describe( "call object", function() {
|
|
|
1072
1072
|
connection.destroy()
|
|
1073
1073
|
rtpserver.destroy()
|
|
1074
1074
|
} )
|
|
1075
|
+
|
|
1076
|
+
it( `set get moh`, async function() {
|
|
1077
|
+
new srf.srfscenario( {} )
|
|
1078
|
+
|
|
1079
|
+
let options = {
|
|
1080
|
+
"contact": "ourcontactstring",
|
|
1081
|
+
"late": true
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
let c = await call.newuac( options )
|
|
1085
|
+
|
|
1086
|
+
let s = {
|
|
1087
|
+
"loop": true,
|
|
1088
|
+
"files": [
|
|
1089
|
+
{ "wav": "some.wav" }
|
|
1090
|
+
]
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/* no default configured */
|
|
1094
|
+
expect( c.moh ).to.be.undefined
|
|
1095
|
+
c.moh = s
|
|
1096
|
+
|
|
1097
|
+
expect( c._moh.loop ).to.equal( true )
|
|
1098
|
+
expect( c.moh.loop ).to.equal( true )
|
|
1099
|
+
|
|
1100
|
+
c._onhangup( "wire" )
|
|
1101
|
+
|
|
1102
|
+
} )
|
|
1075
1103
|
} )
|
package/test/unit/store.js
CHANGED
|
@@ -25,7 +25,8 @@ describe( "callmanager - store", function() {
|
|
|
25
25
|
expect( await callstore.stats() ).to.deep.include( {
|
|
26
26
|
"storebycallid": 1,
|
|
27
27
|
"storebyuuid": 1,
|
|
28
|
-
"storebyentity": 1
|
|
28
|
+
"storebyentity": 1,
|
|
29
|
+
"storebyentityrealm": 1
|
|
29
30
|
} )
|
|
30
31
|
} )
|
|
31
32
|
|
|
@@ -47,7 +48,8 @@ describe( "callmanager - store", function() {
|
|
|
47
48
|
expect( await callstore.stats() ).to.deep.include( {
|
|
48
49
|
"storebycallid": 1,
|
|
49
50
|
"storebyuuid": 1,
|
|
50
|
-
"storebyentity": 1
|
|
51
|
+
"storebyentity": 1,
|
|
52
|
+
"storebyentityrealm": 1
|
|
51
53
|
} )
|
|
52
54
|
|
|
53
55
|
dummycall.sip.tags.local = "4444"
|
|
@@ -56,7 +58,8 @@ describe( "callmanager - store", function() {
|
|
|
56
58
|
expect( await callstore.stats() ).to.deep.include( {
|
|
57
59
|
"storebycallid": 1,
|
|
58
60
|
"storebyuuid": 1,
|
|
59
|
-
"storebyentity": 1
|
|
61
|
+
"storebyentity": 1,
|
|
62
|
+
"storebyentityrealm": 1
|
|
60
63
|
} )
|
|
61
64
|
|
|
62
65
|
let searchfor = {
|
|
@@ -111,7 +114,8 @@ describe( "callmanager - store", function() {
|
|
|
111
114
|
expect( await callstore.stats() ).to.deep.include( {
|
|
112
115
|
"storebycallid": 2,
|
|
113
116
|
"storebyuuid": 2,
|
|
114
|
-
"storebyentity": 0
|
|
117
|
+
"storebyentity": 0,
|
|
118
|
+
"storebyentityrealm": 0
|
|
115
119
|
} )
|
|
116
120
|
|
|
117
121
|
dummycall1._entity = {
|
|
@@ -123,7 +127,8 @@ describe( "callmanager - store", function() {
|
|
|
123
127
|
expect( await callstore.stats() ).to.deep.include( {
|
|
124
128
|
"storebycallid": 2,
|
|
125
129
|
"storebyuuid": 2,
|
|
126
|
-
"storebyentity": 1
|
|
130
|
+
"storebyentity": 1,
|
|
131
|
+
"storebyentityrealm": 1
|
|
127
132
|
} )
|
|
128
133
|
|
|
129
134
|
await callstore.set( dummycall3 )
|
|
@@ -131,7 +136,8 @@ describe( "callmanager - store", function() {
|
|
|
131
136
|
expect( await callstore.stats() ).to.deep.include( {
|
|
132
137
|
"storebycallid": 3,
|
|
133
138
|
"storebyuuid": 3,
|
|
134
|
-
"storebyentity": 1
|
|
139
|
+
"storebyentity": 1,
|
|
140
|
+
"storebyentityrealm": 1
|
|
135
141
|
} )
|
|
136
142
|
|
|
137
143
|
let c = await callstore.getbycallid( dummycall1.sip )
|
|
@@ -147,7 +153,8 @@ describe( "callmanager - store", function() {
|
|
|
147
153
|
expect( await callstore.stats() ).to.deep.include( {
|
|
148
154
|
"storebycallid": 0,
|
|
149
155
|
"storebyuuid": 0,
|
|
150
|
-
"storebyentity": 0
|
|
156
|
+
"storebyentity": 0,
|
|
157
|
+
"storebyentityrealm": 0
|
|
151
158
|
} )
|
|
152
159
|
} )
|
|
153
160
|
} )
|