Browse Source

ref(JitsiConference): move sendTones impl to TPC (#983)

Moves sendTones implementation to TraceablePeerConnection. It will be
responsible for creating/storing a DTMFSender. JitsiConference will
use the currently active TraceablePeerConnection to send the tones.

This fixes a bug where DTMF tones can not be sent after
JingleSessionPC/TraceablePeerConnection instance changes.
The JitsiDTMFManager instance was referencing invalid PeerConnection.
dev1
Paweł Domas 6 years ago
parent
commit
3edf6d300b
No account linked to committer's email address
3 changed files with 48 additions and 43 deletions
  1. 5
    19
      JitsiConference.js
  2. 0
    24
      modules/DTMF/JitsiDTMFManager.js
  3. 43
    0
      modules/RTC/TraceablePeerConnection.js

+ 5
- 19
JitsiConference.js View File

@@ -13,7 +13,6 @@ import JitsiTrackError from './JitsiTrackError';
13 13
 import * as JitsiTrackErrors from './JitsiTrackErrors';
14 14
 import * as JitsiTrackEvents from './JitsiTrackEvents';
15 15
 import authenticateAndUpgradeRole from './authenticateAndUpgradeRole';
16
-import JitsiDTMFManager from './modules/DTMF/JitsiDTMFManager';
17 16
 import P2PDominantSpeakerDetection from './modules/P2PDominantSpeakerDetection';
18 17
 import RTC from './modules/RTC/RTC';
19 18
 import TalkMutedDetection from './modules/TalkMutedDetection';
@@ -2010,26 +2009,13 @@ JitsiConference.prototype.myUserId = function() {
2010 2009
 };
2011 2010
 
2012 2011
 JitsiConference.prototype.sendTones = function(tones, duration, pause) {
2013
-    if (!this.dtmfManager) {
2014
-        const peerConnection = this.getActivePeerConnection();
2015
-
2016
-        if (!peerConnection) {
2017
-            logger.warn('cannot sendTones: no peer connection');
2018
-
2019
-            return;
2020
-        }
2021
-
2022
-        const localAudio = this.getLocalAudioTrack();
2023
-
2024
-        if (!localAudio) {
2025
-            logger.warn('cannot sendTones: no local audio stream');
2012
+    const peerConnection = this.getActivePeerConnection();
2026 2013
 
2027
-            return;
2028
-        }
2029
-        this.dtmfManager = new JitsiDTMFManager(localAudio, peerConnection);
2014
+    if (peerConnection) {
2015
+        peerConnection.sendTones(tones, duration, pause);
2016
+    } else {
2017
+        logger.warn('cannot sendTones: no peer connection');
2030 2018
     }
2031
-
2032
-    this.dtmfManager.sendTones(tones, duration, pause);
2033 2019
 };
2034 2020
 
2035 2021
 /**

+ 0
- 24
modules/DTMF/JitsiDTMFManager.js View File

@@ -1,24 +0,0 @@
1
-const logger = require('jitsi-meet-logger').getLogger(__filename);
2
-
3
-/**
4
- *
5
- * @param localAudio
6
- * @param peerConnection
7
- */
8
-function JitsiDTMFManager(localAudio, peerConnection) {
9
-    const audioTrack = localAudio.getTrack();
10
-
11
-    if (!audioTrack) {
12
-        throw new Error('Failed to initialize DTMFSender: no audio track.');
13
-    }
14
-    this.dtmfSender
15
-        = peerConnection.peerconnection.createDTMFSender(audioTrack);
16
-    logger.debug('Initialized DTMFSender');
17
-}
18
-
19
-JitsiDTMFManager.prototype.sendTones = function(tones, duration, pause) {
20
-    this.dtmfSender.insertDTMF(tones, duration || 200, pause || 200);
21
-};
22
-
23
-module.exports = JitsiDTMFManager;
24
-

+ 43
- 0
modules/RTC/TraceablePeerConnection.js View File

@@ -80,6 +80,14 @@ export default function TraceablePeerConnection(
80 80
      */
81 81
     this.audioTransferActive = !(options.startSilent === true);
82 82
 
83
+    /**
84
+     * The DTMF sender instance used to send DTMF tones.
85
+     *
86
+     * @type {RTCDTMFSender|undefined}
87
+     * @private
88
+     */
89
+    this._dtmfSender = undefined;
90
+
83 91
     /**
84 92
      * Indicates whether or not this peer connection instance is actively
85 93
      * sending/receiving video media. When set to <tt>false</tt> the SDP video
@@ -2053,6 +2061,41 @@ TraceablePeerConnection.prototype.setVideoTransferActive = function(active) {
2053 2061
     return changed;
2054 2062
 };
2055 2063
 
2064
+/**
2065
+ * Sends DTMF tones if possible.
2066
+ *
2067
+ * @param {string} tones - The DTMF tones string as defined by {@code RTCDTMFSender.insertDTMF}, 'tones' argument.
2068
+ * @param {number} duration - The amount of time in milliseconds that each DTMF should last. It's 200ms by default.
2069
+ * @param {number} interToneGap - The length of time in miliseconds to wait between tones. It's 200ms by default.
2070
+ *
2071
+ * @returns {void}
2072
+ */
2073
+TraceablePeerConnection.prototype.sendTones = function(tones, duration = 200, interToneGap = 200) {
2074
+    if (!this._dtmfSender) {
2075
+        if (this.peerconnection.getSenders) {
2076
+            const rtpSender = this.peerconnection.getSenders().find(s => s.dtmf);
2077
+
2078
+            this._dtmfSender = rtpSender && rtpSender.dtmf;
2079
+            this._dtmfSender && logger.info(`${this} initialized DTMFSender using getSenders`);
2080
+        }
2081
+
2082
+        if (!this._dtmfSender) {
2083
+            const localAudioTrack = Array.from(this.localTracks.values()).find(t => t.isAudioTrack());
2084
+
2085
+            if (this.peerconnection.createDTMFSender && localAudioTrack) {
2086
+                this._dtmfSender = this.peerconnection.createDTMFSender(localAudioTrack.getTrack());
2087
+            }
2088
+            this._dtmfSender && logger.info(`${this} initialized DTMFSender using deprecated createDTMFSender`);
2089
+        }
2090
+    }
2091
+
2092
+    if (this._dtmfSender) {
2093
+        this._dtmfSender.insertDTMF(tones, duration, interToneGap);
2094
+    } else {
2095
+        logger.warn(`${this} sendTones - failed to select DTMFSender`);
2096
+    }
2097
+};
2098
+
2056 2099
 /**
2057 2100
  * Makes the underlying TraceablePeerConnection generate new SSRC for
2058 2101
  * the recvonly video stream.

Loading…
Cancel
Save