@babblevoice/babble-drachtio-callmanager 2.3.9 → 2.3.10

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 +53 -20
  2. package/package.json +1 -1
package/lib/call.js CHANGED
@@ -205,6 +205,9 @@ class call {
205
205
  */
206
206
  this.parent = undefined
207
207
 
208
+ /** @summary Other channels which we might need - for things like opening a channel on the same node. */
209
+ this.relatives = new Set()
210
+
208
211
  /**
209
212
  * @typedef {Object} epochs
210
213
  * @property {number} startat UNIX timestamp of when the call was started (created)
@@ -889,16 +892,19 @@ class call {
889
892
  /**
890
893
  Emits the event call.pick to allow other parts of dial plan to give up on further processing.
891
894
  It wuld be normal to bridge this call to another after this call has been made.
895
+ @return { call }
892
896
  */
893
897
  pick() {
894
898
  this.state.picked = true
895
899
  this._em.emit( "call.pick", this )
900
+ return this
896
901
  }
897
902
 
898
903
  /**
899
904
  Delink calls logically - any calls which have parent or children they are all removed.
900
905
  when the dialog is either answered (or doesn't answer for some reason).
901
906
  The promise resolves to a new call is one is generated, or undefined if not.
907
+ @return { call }
902
908
  */
903
909
  detach() {
904
910
  if( this.parent ) {
@@ -911,11 +917,14 @@ class call {
911
917
 
912
918
  this.parent = undefined
913
919
  this.children.clear()
920
+ return this
914
921
  }
915
922
 
916
923
  /**
917
- Logically adopt a child call
918
- @param { call } other
924
+ * Logically adopt a child call
925
+ * @param { object } other
926
+ * @param { boolean } [ mix ]
927
+ * @return { call }
919
928
  */
920
929
  adopt( other, mix ) {
921
930
  other.parent = this
@@ -935,6 +944,29 @@ class call {
935
944
  this.epochs.mix = Math.floor( +new Date() / 1000 )
936
945
  other.epochs.mix = Math.floor( +new Date() / 1000 )
937
946
  }
947
+ return this
948
+ }
949
+
950
+ /**
951
+ * Create a bond between us and another call. This is currently only used
952
+ * to provide other channels we know we might need to open a channel on
953
+ * the same node as. (replaces preferredcall)
954
+ * @param { object } relative
955
+ * @return { call }
956
+ */
957
+ bond( relative ) {
958
+ if( !relative ) return
959
+ this.relatives.add( relative )
960
+ return this
961
+ }
962
+
963
+ /**
964
+ * Disown distant relatives.
965
+ * @return { call }
966
+ */
967
+ disown() {
968
+ this.relatives.clear()
969
+ return this
938
970
  }
939
971
 
940
972
  /**
@@ -1452,12 +1484,11 @@ class call {
1452
1484
  }
1453
1485
 
1454
1486
  /**
1455
- * @param { object } preferredcall - allow to specify a, not necessarily related call,
1456
1487
  * that can be used to open the new channel's node.
1457
1488
  *
1458
1489
  * @returns { Promise }
1459
1490
  */
1460
- async #choosecodecforanswer( preferredcall = undefined ) {
1491
+ async #choosecodecforanswer() {
1461
1492
  if( this._req.msg && this._req.msg.body ) {
1462
1493
  this.selectedcodec = this.sdp.remote.intersection( this.options.preferedcodecs, true )
1463
1494
  if( !this.selectedcodec ) {
@@ -1484,8 +1515,6 @@ class call {
1484
1515
  channeldef.remote.icepwd = this.sdp.remote.sdp.media[ 0 ].icePwd
1485
1516
  }
1486
1517
 
1487
- channeldef.preferredcall = preferredcall
1488
-
1489
1518
  /* We might have already opened our audio when we received 183 (early). */
1490
1519
  await this.#openchannelsforanswer( channeldef )
1491
1520
  }
@@ -1495,15 +1524,14 @@ class call {
1495
1524
  * Answer this (inbound) call and store a channel which can be used. This framework will catch and cleanup this call if this is rejected.
1496
1525
  * @param { object } [ options ]
1497
1526
  * @param { boolean } [ options.early ] - don't answer the channel (establish) but establish early media (respond to 183).
1498
- * @param { object } [ options.preferredcall ]
1499
1527
  *
1500
1528
  * @return {Promise} Returns a promise which resolves if the call is answered, otherwise rejects the promise.
1501
1529
  */
1502
- async answer( options = { early: false, preferredcall: undefined } ) {
1530
+ async answer( options = { early: false } ) {
1503
1531
 
1504
1532
  if( this.canceled || this.established ) return
1505
1533
 
1506
- await this.#choosecodecforanswer( options.preferredcall )
1534
+ await this.#choosecodecforanswer()
1507
1535
 
1508
1536
  if( this.canceled ) return
1509
1537
 
@@ -2493,7 +2521,6 @@ class call {
2493
2521
  @param { string } [ options.entity.uri ]
2494
2522
  @param { number } [ options.entity.max ] - if included no more than this number of calls for this entity (only if we look user up)
2495
2523
  @param { object } [ options.parent ] - the call we wish to become parent
2496
- @param { object } [ options.preferredcall ] another related call which we may want to use the rtp host on
2497
2524
  @param { object } [ callbacks ]
2498
2525
  @param { earlycallback } [ callbacks.early ] - callback to provide a call object with early call (pre dialog)
2499
2526
  @param { confirmcallback } [ callbacks.confirm ] - called when a dialog is confirmed but before it is bridged with a parent - this provides an opportunity for another call to adopt this call
@@ -2517,9 +2544,6 @@ class call {
2517
2544
 
2518
2545
  if( !options.orphan && !options.parent ) {
2519
2546
  options.parent = this
2520
-
2521
- if ( !options.preferredcall )
2522
- options.preferredcall = options.parent.channels.audio
2523
2547
  }
2524
2548
 
2525
2549
  return await call.newuac( options, callbacks )
@@ -2635,12 +2659,19 @@ class call {
2635
2659
  mechanism. This is causing problems in code like this. There is no interface to
2636
2660
  detect which mode the channel is in - but the channels property will exist on a connect
2637
2661
  style channel. projectrtp will get a rewrite to support only one. */
2638
- if( relatedcall && relatedcall.channels.audio && relatedcall.channels.audio.channels )
2662
+ if( relatedcall && relatedcall.channels.audio && relatedcall.channels.audio.channels ) {
2639
2663
  this.channels.audio = await this.other.channels.audio.openchannel( channeldef, this._handlechannelevents.bind( this ) )
2640
- else if ( channeldef && channeldef.preferredcall && channeldef.preferredcall.channels && channeldef.preferredcall.channels.audio )
2641
- this.channels.audio = await channeldef.preferredcall.channels.audio.openchannel( channeldef, this._handlechannelevents.bind( this ) )
2642
- else
2643
- this.channels.audio = await projectrtp.openchannel( channeldef, this._handlechannelevents.bind( this ) )
2664
+ return
2665
+ }
2666
+
2667
+ for( const other of this.relatives ) {
2668
+ if( other.channels && other.channels.audio ) {
2669
+ this.channels.audio = await other.channels.audio.openchannel( channeldef, this._handlechannelevents.bind( this ) )
2670
+ return
2671
+ }
2672
+ }
2673
+
2674
+ this.channels.audio = await projectrtp.openchannel( channeldef, this._handlechannelevents.bind( this ) )
2644
2675
  }
2645
2676
 
2646
2677
  /**
@@ -2837,7 +2868,7 @@ class call {
2837
2868
  @param { object } [ options.callerid ]
2838
2869
  @param { string } [ options.callerid.number ]
2839
2870
  @param { string } [ options.callerid.name ]
2840
- @param { object } [ options.preferredcall ] another related call which we may want to use the rtp host on
2871
+ @param { call } [ options.bond ] - other channel to bond to for pottential channel pairing
2841
2872
  @param { object } [ callbacks ]
2842
2873
  @param { earlycallback } [ callbacks.early ] - callback to provide a call object with early call (pre dialog)
2843
2874
  @param { confirmcallback } [ callbacks.confirm ] - called when a dialog is confirmed but before it is bridged with a parent - this provides an opportunity for another call to adopt this call
@@ -2860,6 +2891,8 @@ class call {
2860
2891
  options.parent.adopt( newcall )
2861
2892
  }
2862
2893
 
2894
+ newcall.bond( options.bond )
2895
+
2863
2896
  newcall.options = {
2864
2897
  headers: { ...options.headers }
2865
2898
  }
@@ -2886,7 +2919,7 @@ class call {
2886
2919
  newcall.options.headers = tmpheaders
2887
2920
 
2888
2921
  newcall.#confignetwork( options )
2889
- await newcall.#openchannelsfornewuac( { "preferredcall" : options.preferredcall } )
2922
+ await newcall.#openchannelsfornewuac()
2890
2923
 
2891
2924
  let newdialog
2892
2925
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/babble-drachtio-callmanager",
3
- "version": "2.3.9",
3
+ "version": "2.3.10",
4
4
  "description": "Call processing to create a PBX",
5
5
  "main": "index.js",
6
6
  "scripts": {