Browse Source

ref(device-selection): set audio output sink id after receiving ref (#4066)

The Audio.js setRef callback does not behave like react ref callback
in that the former will not have fired before componentDidMount
but the later will have. So for audio output preview, trying to set
sink id on mount will no-op because it does not have a ref yet to
Audio.js, possibly leading to audio output previews playing on
the default speaker device. This generally has not been a user
visible problem due to coincidence; other re-renders necessary
by the parent of audio output preview will have triggered
componentDidUpdates on the audio out preview, which would then
set the sink id on the Audio.js ref it should have received
by then.
master
virtuacoplenny 6 years ago
parent
commit
7a677ead93
No account linked to committer's email address
1 changed files with 16 additions and 25 deletions
  1. 16
    25
      react/features/device-selection/components/AudioOutputPreview.js

+ 16
- 25
react/features/device-selection/components/AudioOutputPreview.js View File

42
 
42
 
43
         this._audioElement = null;
43
         this._audioElement = null;
44
 
44
 
45
+        this._audioElementReady = this._audioElementReady.bind(this);
45
         this._onClick = this._onClick.bind(this);
46
         this._onClick = this._onClick.bind(this);
46
-        this._setAudioElement = this._setAudioElement.bind(this);
47
-    }
48
-
49
-    /**
50
-     * Sets the target output device on the component's audio element after
51
-     * initial render.
52
-     *
53
-     * @inheritdoc
54
-     * @returns {void}
55
-     */
56
-    componentDidMount() {
57
-        this._setAudioSink();
58
     }
47
     }
59
 
48
 
60
     /**
49
     /**
81
                     { this.props.t('deviceSelection.testAudio') }
70
                     { this.props.t('deviceSelection.testAudio') }
82
                 </a>
71
                 </a>
83
                 <Audio
72
                 <Audio
84
-                    setRef = { this._setAudioElement }
73
+                    setRef = { this._audioElementReady }
85
                     src = { TEST_SOUND_PATH } />
74
                     src = { TEST_SOUND_PATH } />
86
             </div>
75
             </div>
87
         );
76
         );
88
     }
77
     }
89
 
78
 
90
-    _onClick: () => void;
79
+    _audioElementReady: (Object) => void;
91
 
80
 
92
     /**
81
     /**
93
-     * Plays a test sound.
82
+     * Sets the instance variable for the component's audio element so it can be
83
+     * accessed directly.
94
      *
84
      *
85
+     * @param {Object} element - The DOM element for the component's audio.
95
      * @private
86
      * @private
96
      * @returns {void}
87
      * @returns {void}
97
      */
88
      */
98
-    _onClick() {
99
-        this._audioElement
100
-        && this._audioElement.play();
89
+    _audioElementReady(element: Object) {
90
+        this._audioElement = element;
91
+
92
+        this._setAudioSink();
101
     }
93
     }
102
 
94
 
103
-    _setAudioElement: (Object) => void;
95
+    _onClick: () => void;
104
 
96
 
105
     /**
97
     /**
106
-     * Sets the instance variable for the component's audio element so it can be
107
-     * accessed directly.
98
+     * Plays a test sound.
108
      *
99
      *
109
-     * @param {Object} element - The DOM element for the component's audio.
110
      * @private
100
      * @private
111
      * @returns {void}
101
      * @returns {void}
112
      */
102
      */
113
-    _setAudioElement(element: Object) {
114
-        this._audioElement = element;
103
+    _onClick() {
104
+        this._audioElement
105
+            && this._audioElement.play();
115
     }
106
     }
116
 
107
 
117
     /**
108
     /**
122
      */
113
      */
123
     _setAudioSink() {
114
     _setAudioSink() {
124
         this._audioElement
115
         this._audioElement
125
-        && this._audioElement.setSinkId(this.props.deviceId);
116
+            && this._audioElement.setSinkId(this.props.deviceId);
126
     }
117
     }
127
 }
118
 }
128
 
119
 

Loading…
Cancel
Save