Skip to content
Snippets Groups Projects
Commit 22d425d8 authored by Greg Fodor's avatar Greg Fodor
Browse files

Fix race conditions on state

parent 5759cdb3
No related branches found
No related tags found
No related merge requests found
...@@ -288,17 +288,14 @@ class UIRoot extends Component { ...@@ -288,17 +288,14 @@ class UIRoot extends Component {
setMediaStreamToDefault = async () => { setMediaStreamToDefault = async () => {
let hasAudio = false; let hasAudio = false;
console.log(this.props.store.state);
const { lastUsedMicDeviceId } = this.props.store.state; const { lastUsedMicDeviceId } = this.props.store.state;
// Try to fetch last used mic, and if we don't get it then fall back to default. // Try to fetch last used mic, and if we don't get it then fall back to default.
if (lastUsedMicDeviceId) { if (lastUsedMicDeviceId) {
console.log("Check for " + lastUsedMicDeviceId);
hasAudio = await this.fetchAudioTrack({ audio: { deviceId: { exact: lastUsedMicDeviceId } } }); hasAudio = await this.fetchAudioTrack({ audio: { deviceId: { exact: lastUsedMicDeviceId } } });
} }
if (!hasAudio) { if (!hasAudio) {
console.log("Use defualt");
hasAudio = await this.fetchAudioTrack({ audio: true }); hasAudio = await this.fetchAudioTrack({ audio: true });
} }
...@@ -350,6 +347,8 @@ class UIRoot extends Component { ...@@ -350,6 +347,8 @@ class UIRoot extends Component {
setupNewMediaStream = async () => { setupNewMediaStream = async () => {
const mediaStream = new MediaStream(); const mediaStream = new MediaStream();
await this.fetchMicDevices();
if (this.state.videoTrack) { if (this.state.videoTrack) {
mediaStream.addTrack(this.state.videoTrack); mediaStream.addTrack(this.state.videoTrack);
} }
...@@ -380,17 +379,11 @@ class UIRoot extends Component { ...@@ -380,17 +379,11 @@ class UIRoot extends Component {
this.setState({ micLevel: this.micLevelMovingAverage.movingAverage() }); this.setState({ micLevel: this.micLevelMovingAverage.movingAverage() });
}, 50); }, 50);
setTimeout(() => { const micDeviceId = this.micDeviceIdForMicLabel(this.micLabelForMediaStream(mediaStream));
// TODO DEAL WITH BY REFACTORING THESE METHODS TO PASS IN mediaStream;
const selectedMicDeviceId = this.selectedMicDeviceId();
console.log(this.selectedMicLabel());
console.log("Save " + selectedMicDeviceId);
if (selectedMicDeviceId) { if (micDeviceId) {
this.props.store.update({ lastUsedMicDeviceId: this.selectedMicDeviceId() }); this.props.store.update({ lastUsedMicDeviceId: micDeviceId });
} }
}, 100);
this.setState({ micUpdateInterval }); this.setState({ micUpdateInterval });
} }
...@@ -418,7 +411,6 @@ class UIRoot extends Component { ...@@ -418,7 +411,6 @@ class UIRoot extends Component {
beginAudioSetup = async () => { beginAudioSetup = async () => {
this.startTestTone(); this.startTestTone();
await this.fetchMicDevices();
this.setState({ entryStep: ENTRY_STEPS.audio_setup }); this.setState({ entryStep: ENTRY_STEPS.audio_setup });
}; };
...@@ -441,17 +433,20 @@ class UIRoot extends Component { ...@@ -441,17 +433,20 @@ class UIRoot extends Component {
return !!this.state.micDevices.find(d => HMD_MIC_REGEXES.find(r => d.label.match(r))); return !!this.state.micDevices.find(d => HMD_MIC_REGEXES.find(r => d.label.match(r)));
}; };
micLabelForMediaStream = mediaStream => {
return (mediaStream && mediaStream.getAudioTracks().length > 0 && mediaStream.getAudioTracks()[0].label) || "";
};
selectedMicLabel = () => { selectedMicLabel = () => {
return ( return this.micLabelForMediaStream(this.state.mediaStream);
(this.state.mediaStream && };
this.state.mediaStream.getAudioTracks().length > 0 &&
this.state.mediaStream.getAudioTracks()[0].label) || micDeviceIdForMicLabel = label => {
"" return this.state.micDevices.filter(d => d.label === label).map(d => d.deviceId)[0];
);
}; };
selectedMicDeviceId = () => { selectedMicDeviceId = () => {
return this.state.micDevices.filter(d => d.label === this.selectedMicLabel()).map(d => d.deviceId)[0]; return this.micDeviceIdForMicLabel(this.selectedMicLabel());
}; };
onAudioReadyButton = () => { onAudioReadyButton = () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment