@babblevoice/babble-drachtio-callmanager 3.5.8 → 3.6.1

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.
Files changed (3) hide show
  1. package/index.js +4 -1
  2. package/lib/call.js +67 -27
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -14,7 +14,10 @@ const default_options = {
14
14
  "registrar": false, /* our registrar object or falsey */
15
15
  "referauthrequired": true,
16
16
  "ignoreipv6candidates": true, /* ipv6 does not work in projectrtp */
17
- "privacy": false
17
+ "privacy": false,
18
+ "hangupchildrenonhangup": true,
19
+ "hangupparentonhangup": false,
20
+ "continueonotherhangup": false
18
21
  }
19
22
 
20
23
  /**
package/lib/call.js CHANGED
@@ -1141,7 +1141,8 @@ class call {
1141
1141
  other.moh = this.moh
1142
1142
 
1143
1143
  /* maintain privacy */
1144
- other.options.privacy = this.options.privacy
1144
+ if ( this.options.privacy )
1145
+ other.options.privacy = this.options.privacy
1145
1146
 
1146
1147
  if( mix ) this.mix( other )
1147
1148
  return this
@@ -1228,7 +1229,7 @@ class call {
1228
1229
  }
1229
1230
 
1230
1231
  /* are we still established? */
1231
- if( !this.established || this.state.destroyed ) return this
1232
+ if( !this.established || this.state.destroyed || this.parent.destroyed ) return this
1232
1233
  if( !this.channels.audio ) {
1233
1234
  /* something bad has happened */
1234
1235
  this.hangup( hangupcodes.NOT_ACCEPTABLE )
@@ -2586,6 +2587,8 @@ class call {
2586
2587
 
2587
2588
  /* Link logically and mix */
2588
2589
  a_1.adopt( c_1, true )
2590
+ /* update the caller id on the call */
2591
+ await a_1.update()
2589
2592
 
2590
2593
  this._notifyrefercomplete()
2591
2594
 
@@ -2797,14 +2800,29 @@ class call {
2797
2800
  } ).catch( () => {} )
2798
2801
  }
2799
2802
 
2803
+ /**
2804
+ * @param { boolean } value - allow our relation (child or parent) to hang us up or not - set to true if this leg wants to continue
2805
+ */
2806
+ set continueonotherhangup( value ) {
2807
+ this.options.continueonotherhangup = value
2808
+ }
2809
+
2810
+ /**
2811
+ * @returns { boolean }
2812
+ */
2813
+ get continueonotherhangup() {
2814
+ return this.options.continueonotherhangup
2815
+ }
2816
+
2800
2817
  /**
2801
2818
  * Used by our frame to a) continue a hangup which has been initiated by either us or the network.
2802
2819
  * Complete the hangup, including hanging up all children and waiting for them to complete their
2803
2820
  * hangup.
2804
- * @param { string } [ src ] - "us"|"wire"
2821
+ * @param { "us" | "wire" } [ src ] - "us"|"wire"
2805
2822
  * @param { object } [ reason ] - one of the reasons from the hangupcodes enum - only used if we havn't alread set our reason
2806
2823
  * @private
2807
2824
  */
2825
+ // eslint-disable-next-line complexity
2808
2826
  async _onhangup( src = "us", reason ) {
2809
2827
 
2810
2828
  if( this._state._onhangup ) {
@@ -2813,18 +2831,33 @@ class call {
2813
2831
  }
2814
2832
  this._state._onhangup = true
2815
2833
 
2816
- /* hangup our children but, no other relations - i.e. children of our parent */
2817
- const hangups = []
2818
- for( const child of this.children ) {
2819
- hangups.push( child.hangup( this.hangup_cause ) )
2820
- }
2834
+ this._sethangupcause( src, reason )
2821
2835
 
2822
- /* wait for all children to have completed their hangup */
2823
- if( 0 < hangups.length ) {
2824
- await Promise.all( hangups )
2825
- }
2836
+ if( "wire" == src ) {
2837
+ /*
2838
+ 1. Hangup our children regardless of our state
2839
+ 2. If we are established and the only child child - hangup our parent (unless otherwise told not to: parent.continueonotherhangup)
2840
+ */
2841
+ const hangups = []
2842
+ if( this.options.hangupchildrenonhangup ) {
2843
+ for( const child of this.children ) {
2844
+ if( !child.options.continueonotherhangup ) {
2845
+ hangups.push( child.hangup( this.hangup_cause ) )
2846
+ }
2847
+ }
2848
+ }
2826
2849
 
2827
- this._sethangupcause( src, reason )
2850
+ if( this.established && this.options.hangupparentonhangup && this.parent ) {
2851
+ if( !this.parent.options.continueonotherhangup && 2 > this.parent.children.size ) {
2852
+ hangups.push( this.parent.hangup( this.hangup_cause ) )
2853
+ }
2854
+ }
2855
+
2856
+ /* wait for all relatives to complete their hangup */
2857
+ if( 0 < hangups.length ) {
2858
+ await Promise.all( hangups )
2859
+ }
2860
+ }
2828
2861
 
2829
2862
  /* flag destroyed so when we receive our close event we know what to do */
2830
2863
  this.destroyed = true
@@ -2844,19 +2877,21 @@ class call {
2844
2877
  /**
2845
2878
  * Hangup the call with reason. Public interface for callers to use.
2846
2879
  * @param { object } reason - one of the reasons from the hangupcodes enum
2847
- * @param { boolean } tone if true play teh appropriate tone instead of actaully hanging up
2880
+ * @param { boolean } [ tone ] if true play the appropriate tone instead of actaully hanging up
2881
+ * @param { "wire" | "us" } [ source ] - who initiated the hangup - typically us - but if the signal came from another network interface - then wire
2882
+ *
2848
2883
  */
2849
- async hangup( reason, tone = false ) {
2884
+ async hangup( reason, tone = false, source = "us" ) {
2850
2885
 
2851
2886
  if( this._state._hangup || this._state._onhangup ) {
2852
2887
  await this.waitforhangup()
2853
2888
  return
2854
2889
  }
2855
2890
 
2856
- this._sethangupcause( "us", reason )
2891
+ this._sethangupcause( source, reason )
2857
2892
 
2858
2893
  if( this.state.established ) {
2859
- if( await this.#hangupestablish( reason, tone ) ) return
2894
+ if( this.#hangupestablish( reason, tone ) ) return
2860
2895
  } else if( "uac" === this.type && this.state.trying ) {
2861
2896
  this.#hangupnotestablish()
2862
2897
  } else if( this._res ) {
@@ -2864,29 +2899,29 @@ class call {
2864
2899
  }
2865
2900
 
2866
2901
  this._state._hangup = true
2867
- await this._onhangup( "us", reason )
2902
+
2903
+ try {
2904
+ if( this._dialog ) await this._dialog.destroy()
2905
+ } catch( e ) { console.trace( e ) }
2906
+
2907
+ await this._onhangup( source, reason )
2868
2908
  }
2869
2909
 
2870
2910
  /**
2871
2911
  * @param { object } reason - plays the apropropriate tone
2872
2912
  * @param { boolean } tone
2873
2913
  */
2874
- async #hangupestablish( reason, tone ) {
2914
+ #hangupestablish( reason, tone ) {
2875
2915
  if( undefined != reason && tone ) {
2876
2916
  switch( reason.sip ) {
2877
2917
  case 486:
2878
2918
  this.play( this.engagedsoup )
2879
- break
2919
+ return true
2880
2920
  case 480:
2881
2921
  this.play( this.unobtainablesoup )
2922
+ return true
2882
2923
  }
2883
- return true
2884
2924
  }
2885
- this._state._hangup = true
2886
-
2887
- try {
2888
- await this._dialog.destroy()
2889
- } catch( e ) { console.trace( e ) }
2890
2925
  return false
2891
2926
  }
2892
2927
 
@@ -2920,6 +2955,7 @@ class call {
2920
2955
  /**
2921
2956
  * Send an UPDATE. Use to updated called id, caller id, sdp etc. Send in dialog - TODO look how to send
2922
2957
  * early as this is recomended in the RFC.
2958
+ * @param { object } [ remote ]
2923
2959
  */
2924
2960
  async update( remote ) {
2925
2961
 
@@ -3224,7 +3260,7 @@ class call {
3224
3260
  if( err.status in inboundsiperros ) reason = inboundsiperros[ err.status ]
3225
3261
 
3226
3262
  this.state.destroyed = true
3227
- if( this ) this._onhangup( "wire", reason )
3263
+ this._onhangup( "wire", reason )
3228
3264
  } else {
3229
3265
  console.trace( err )
3230
3266
  }
@@ -3362,6 +3398,9 @@ class call {
3362
3398
  * @property { object } [ calledid ]
3363
3399
  * @property { string } [ calledid.number ]
3364
3400
  * @property { string } [ calledid.name ]
3401
+ * @property { boolean } [ continueonotherhangup ] - if true continue on other hangup
3402
+ * @property { boolean } [ hangupchildrenonhangup ]
3403
+ * @property { boolean } [ hangupparentonhangup ]
3365
3404
  * @property { call } [ bond ] - other channel to bond to for pottential channel pairing
3366
3405
  */
3367
3406
 
@@ -3504,6 +3543,7 @@ class call {
3504
3543
  if( earlypromise ) await earlypromise
3505
3544
 
3506
3545
  if( !newdialog ) {
3546
+ callstore.delete( newcall )
3507
3547
  if( callbacks.fail ) callbacks.fail( newcall )
3508
3548
  return newcall
3509
3549
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/babble-drachtio-callmanager",
3
- "version": "3.5.8",
3
+ "version": "3.6.1",
4
4
  "description": "Call processing to create a PBX",
5
5
  "main": "index.js",
6
6
  "scripts": {