@babblevoice/babble-drachtio-callmanager 3.4.0 → 3.4.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 (2) hide show
  1. package/lib/call.js +118 -45
  2. package/package.json +1 -1
package/lib/call.js CHANGED
@@ -475,12 +475,13 @@ class call {
475
475
  * @returns { object }
476
476
  */
477
477
  #getremotefromheaders() {
478
- let parsed
478
+ let parsed = {}
479
479
  if( this._req.has( "p-asserted-identity" ) ) {
480
480
  parsed = this._req.getParsedHeader( "p-asserted-identity" )
481
481
  } else if( this._req.has( "remote-party-id" ) ) {
482
482
  parsed = this._req.getParsedHeader( "remote-party-id" )
483
483
  }
484
+
484
485
  return parsed
485
486
  }
486
487
 
@@ -493,14 +494,14 @@ class call {
493
494
 
494
495
  #fixparseduriobj( parsed ) {
495
496
 
496
- if( !parsed ) parsed = {}
497
+ if( !parsed ) parsed = { name: "" }
498
+ const name = parsed.name
499
+
497
500
  if( !parsed.uri && parsed.user && parsed.host ) parsed.uri = parsed.user + "@" + parsed.host
498
501
  if( parsed.uri && !parsed.user && !parsed.host ) parsed = parseuri( parsed.uri )
499
502
 
500
- let parseduri = parseuri( parsed.uri )
501
-
502
- if( !parseduri ) parseduri = { "user": parsed.user, "host": parsed.host }
503
503
  if( !parsed.params ) parsed.params = {}
504
+ if( name ) parsed.name = name
504
505
 
505
506
  return parsed
506
507
  }
@@ -550,6 +551,7 @@ class call {
550
551
  if( parsed.uri ) startingpoint.uri = parsed.uri
551
552
  if( parsed.user ) startingpoint.user = parsed.user
552
553
  if( parsed.host ) startingpoint.host = parsed.host
554
+ if( parsed.name ) startingpoint.name = parsed.name
553
555
  }
554
556
 
555
557
  #fromcontact( startingpoint ) {
@@ -594,15 +596,6 @@ class call {
594
596
  return false
595
597
  }
596
598
 
597
- #fromentity( startingpoint ) {
598
-
599
- if( this.#fromoutentity( startingpoint ) ) return true
600
- if( this.#frominentity( startingpoint ) ) return true
601
-
602
- return false
603
- }
604
-
605
-
606
599
  /**
607
600
  * We have received an INVITE
608
601
  * @param { object } startingpoint
@@ -1578,7 +1571,12 @@ class call {
1578
1571
  If we are not ringing - send ringing to the other end.
1579
1572
  */
1580
1573
  ring() {
1581
- if( !this.ringing && "uas" === this.type ) {
1574
+
1575
+ if( "uac" === this.type ) return
1576
+
1577
+ if ( this.established ) {
1578
+ this.play( this.ringsoup )
1579
+ } else if( !this.ringing ) {
1582
1580
  this.state.ringing = true
1583
1581
  this._res.send( 180, {
1584
1582
  headers: {
@@ -1592,6 +1590,20 @@ class call {
1592
1590
  }
1593
1591
  }
1594
1592
 
1593
+ /**
1594
+ * Play a sound soup
1595
+ * @param { object } soup
1596
+ * @returns { Boolean }
1597
+ */
1598
+ play( soup ) {
1599
+ if( !this.channels.audio ) return false
1600
+ if( !this.established && !this.state.early ) return false
1601
+ if( !soup ) return false
1602
+
1603
+ this.channels.audio.play( soup )
1604
+ return true
1605
+ }
1606
+
1595
1607
  /**true
1596
1608
  Shortcut to hangup with the reason busy.
1597
1609
  */
@@ -1706,7 +1718,7 @@ class call {
1706
1718
 
1707
1719
  #handlechannelevclose( e ) {
1708
1720
  /* keep a record */
1709
- if( this.channels.audio.history ) {
1721
+ if( this.channels.audio && this.channels.audio.history ) {
1710
1722
  this.channels.closed.audio.push( this.channels.audio.history )
1711
1723
  } else {
1712
1724
  this.channels.closed.audio.push( e )
@@ -1862,6 +1874,44 @@ class call {
1862
1874
  return callmanager.options.moh
1863
1875
  }
1864
1876
 
1877
+ /**
1878
+ * Set the sound soup for music on ringing.
1879
+ * @param { object } soup - sound soup as described in projectrtp
1880
+ */
1881
+ set ringsoup( soup ) {
1882
+ this._ringsoup = soup
1883
+ }
1884
+
1885
+ /**
1886
+ * Return the current ringsoup
1887
+ * @returns { object } sound soup
1888
+ */
1889
+ get ringsoup() {
1890
+ if( this._ringsoup ) {
1891
+ return this._ringsoup
1892
+ }
1893
+ return callmanager.options.ringsoup
1894
+ }
1895
+
1896
+ /**
1897
+ * Set the sound soup for music on engaged.
1898
+ * @param { object } soup - sound soup as described in projectrtp
1899
+ */
1900
+ set engagedsoup( soup ) {
1901
+ this._engagedsoup = soup
1902
+ }
1903
+
1904
+ /**
1905
+ * Return the current engagedsoup
1906
+ * @returns { object } sound soup
1907
+ */
1908
+ get engagedsoup() {
1909
+ if( this._engagedsoup ) {
1910
+ return this._engagedsoup
1911
+ }
1912
+ return callmanager.options.engagedsoup
1913
+ }
1914
+
1865
1915
  /**
1866
1916
  * If we have been placed on hold (and it has been neotiated) then configure audio to match.
1867
1917
  * @param { "inactive"|"recvonly" } direction - from the other end
@@ -2051,7 +2101,7 @@ class call {
2051
2101
  const channeldef = await othercall.#createchannelremotedef()
2052
2102
 
2053
2103
  const oldchannel = othercall.channels.audio
2054
- const newchannel = await this.#openchannel( channeldef, this )
2104
+ const newchannel = await this.#openchannel( channeldef, othercall )
2055
2105
  await othercall.bond( this ).reinvite( channeldef, newchannel )
2056
2106
 
2057
2107
  await oldchannel.unmix()
@@ -2077,17 +2127,20 @@ class call {
2077
2127
  */
2078
2128
  async #openchannel( channeldef, bindcall ) {
2079
2129
 
2080
- if ( bindcall && bindcall.channels.audio ) {
2081
- const chan = await bindcall.channels.audio.openchannel(
2082
- channeldef, this._handlechannelevents.bind( this ) )
2130
+ let chan = undefined
2083
2131
 
2084
- this.channels.count++
2085
- return chan
2132
+ if ( !bindcall || !this.channels.audio ) {
2133
+ chan = await projectrtp.openchannel(
2134
+ channeldef, this._handlechannelevents.bind( this ) )
2135
+ } else {
2136
+ chan = await this.channels.audio.openchannel(
2137
+ channeldef, bindcall._handlechannelevents.bind( bindcall ) )
2086
2138
  }
2087
2139
 
2088
- const chan = await projectrtp.openchannel(
2089
- channeldef, this._handlechannelevents.bind( this ) )
2090
- this.channels.count++
2140
+ if ( bindcall )
2141
+ bindcall.channels.count++
2142
+ else
2143
+ this.channels.count++
2091
2144
 
2092
2145
  return chan
2093
2146
  }
@@ -2702,39 +2755,59 @@ class call {
2702
2755
 
2703
2756
  /**
2704
2757
  * Hangup the call with reason. Public interface for callers to use.
2705
- * @param {object} reason - one of the reasons from the hangupcodes enum
2706
- */
2707
- async hangup( reason ) {
2758
+ * @param { object } reason - one of the reasons from the hangupcodes enum
2759
+ * @param { boolean } tone if true play teh appropriate tone instead of actaully hanging up
2760
+ */
2761
+ async hangup( reason, tone = false ) {
2708
2762
 
2709
2763
  if( this._state._hangup || this._state._onhangup ) {
2710
2764
  await this.waitforhangup()
2711
2765
  return
2712
2766
  }
2713
- this._state._hangup = true
2767
+
2714
2768
  this._sethangupcause( "us", reason )
2715
2769
 
2716
2770
  if( this.state.established ) {
2717
- try {
2718
- await this._dialog.destroy()
2719
- } catch( e ) { console.trace( e ) }
2720
-
2721
- } else if( "uac" === this.type &&
2722
- this.state.trying ) {
2723
- try {
2724
- this.canceled = true
2725
- if( this._req ) {
2726
- this._req.cancel( ( err /*, cancel */ ) => {
2727
- if( err ) console.trace( err )
2728
- } )
2729
- }
2730
- } catch( e ) { console.trace( e ) }
2771
+ if( await this.#hangupestablish( reason, tone ) ) return
2772
+ } else if( "uac" === this.type && this.state.trying ) {
2773
+ this.#hangupnotestablish()
2731
2774
  } else if( this._res ) {
2732
2775
  this._res.send( this.hangup_cause.sip )
2733
2776
  }
2734
2777
 
2778
+ this._state._hangup = true
2735
2779
  await this._onhangup( "us", reason )
2736
2780
  }
2737
2781
 
2782
+ /**
2783
+ * @param { object } reason - plays the apropropriate tone - TODO support other tone than USER_BUSY
2784
+ * @param { boolean } tone
2785
+ */
2786
+ async #hangupestablish( reason, tone ) {
2787
+ if( tone && 486 == reason.sip ) {
2788
+ this.play( this.engagedsoup )
2789
+ return true
2790
+ }
2791
+
2792
+ this._state._hangup = true
2793
+
2794
+ try {
2795
+ await this._dialog.destroy()
2796
+ } catch( e ) { console.trace( e ) }
2797
+ return false
2798
+ }
2799
+
2800
+ #hangupnotestablish() {
2801
+ try {
2802
+ this.canceled = true
2803
+ if( this._req ) {
2804
+ this._req.cancel( ( err /*, cancel */ ) => {
2805
+ if( err ) console.trace( err )
2806
+ } )
2807
+ }
2808
+ } catch( e ) { console.trace( e ) }
2809
+ }
2810
+
2738
2811
  /**
2739
2812
  *
2740
2813
  * @returns { Promise }
@@ -2943,13 +3016,13 @@ class call {
2943
3016
  detect which mode the channel is in - but the channels property will exist on a connect
2944
3017
  style channel. projectrtp will getrelatives a rewrite to support only one. */
2945
3018
  if( othercall && othercall.channels.audio ) {
2946
- this.channels.audio = await this.#openchannel( channeldef, othercall )
3019
+ this.channels.audio = await othercall.#openchannel( channeldef, this )
2947
3020
  return
2948
3021
  }
2949
3022
 
2950
3023
  for( const other of this.relatives ) {
2951
3024
  if( other.channels && other.channels.audio ) {
2952
- this.channels.audio = await this.#openchannel( channeldef, other )
3025
+ this.channels.audio = await other.#openchannel( channeldef, this )
2953
3026
  return
2954
3027
  }
2955
3028
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/babble-drachtio-callmanager",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Call processing to create a PBX",
5
5
  "main": "index.js",
6
6
  "scripts": {