@babblevoice/babble-drachtio-callmanager 1.1.4 → 1.2.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/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( undefined === storedentity ) {
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
- if( entity ) {
115
- if( !entity.uri && entity.username && entity.realm ) {
116
- entity.uri = entity.username + "@" + entity.realm
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
- let entityentries = storebyentity.get( entity.uri )
119
- if( undefined !== entityentries ) {
120
- entityentries.delete( c.uuid )
121
- if( 0 === entityentries.size ) {
122
- storebyentity.delete( entity.uri )
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.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "Call processing to create a PBX",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
  } )