@@ -50,9 +50,19 @@ class Regbot {
5050 this . register ( srf ) ;
5151 }
5252
53- stop ( ) {
54- this . logger . info ( `stopping regbot ${ this . fromUser } @ ${ this . sip_realm } ` ) ;
53+ stop ( srf ) {
54+ const { deleteEphemeralGateway } = srf . locals . realtimeDbHelpers ;
5555 clearTimeout ( this . timer ) ;
56+ this . timer = null ;
57+ // remove any ephemeral gateways created for this regbot
58+ if ( this . addresses && this . addresses . length ) {
59+ this . addresses . forEach ( ( ip ) => {
60+ deleteEphemeralGateway ( ip , this . voip_carrier_sid ) . catch ( ( err ) => {
61+ this . logger . error ( { err, ip} , 'Error deleting ephemeral gateway on regbot stop' ) ;
62+ } ) ;
63+ } ) ;
64+ }
65+
5666 }
5767
5868 toJSON ( ) {
@@ -136,7 +146,7 @@ class Regbot {
136146 if ( REGISTER_RESPONSE_REMOVE . includes ( res . status ) ) {
137147 const { updateCarrierBySid, lookupCarrierBySid } = srf . locals . dbHelpers ;
138148 await updateCarrierBySid ( this . voip_carrier_sid , { requires_register : false } ) ;
139- this . stop ( ) ; //Remove the retry timer
149+ this . stop ( srf ) ; //Remove the retry timer
140150 const carrier = await lookupCarrierBySid ( this . voip_carrier_sid ) ;
141151 if ( carrier ) {
142152 // eslint-disable-next-line max-len
@@ -194,25 +204,25 @@ class Regbot {
194204
195205 // for reg trunks, create ephemeral set of IP addresses for inbound gateways
196206 if ( this . trunk_type === 'reg' ) {
197- const addresses = [ ] ;
207+ this . addresses = [ ] ;
198208 if ( this . port ) {
199209 const addrs = await dnsResolverA ( this . logger , this . sip_realm ) ;
200- addresses . push ( ...addrs ) ;
210+ this . addresses . push ( ...addrs ) ;
201211 }
202212 else {
203213 const addrs = await dnsResolverSrv ( this . logger , this . sip_realm , this . transport ) ;
204- addresses . push ( ...addrs ) ;
214+ this . addresses . push ( ...addrs ) ;
205215 }
206216
207- if ( addresses . length ) {
217+ if ( this . addresses . length ) {
208218 try {
209219 await Promise . all (
210- addresses . map ( ( ip ) => createEphemeralGateway ( ip , this . voip_carrier_sid , expires ) )
220+ this . addresses . map ( ( ip ) => createEphemeralGateway ( ip , this . voip_carrier_sid , expires ) )
211221 ) ;
212222 } catch ( err ) {
213- this . logger . error ( { addresses, err} , 'Error creating hash for reg-gateway' ) ;
223+ this . logger . error ( { addresses : this . addresses , err} , 'Error creating hash for reg-gateway' ) ;
214224 }
215- this . logger . debug ( { addresses} ,
225+ this . logger . debug ( { addresses : this . addresses } ,
216226 `Created ephemeral gateways for registration trunk ${ this . voip_carrier_sid } , ${ this . sip_realm } ` ) ;
217227 }
218228 }
0 commit comments