Skip to content

Commit

Permalink
Merge pull request #239 from Azure-Samples/chwhilar/fix-noCameras-on-…
Browse files Browse the repository at this point in the history
…callStart

If there are no cameras in the system, and then a camera is plugged i…
  • Loading branch information
chriswhilar authored Aug 26, 2024
2 parents d0b0723 + 6eec3de commit 1c89a55
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Project/src/MakeCall/CallCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export default class CallCard extends React.Component {
this.deviceManager.on('videoDevicesUpdated', async e => {
e.added.forEach(addedCameraDevice => {
const addedCameraDeviceOption = { key: addedCameraDevice.id, text: addedCameraDevice.name };
// If there were no cameras in the system and then a camera is plugged in / enabled, select it for use.
if (this.state.cameraDeviceOptions.length === 0 && !this.state.selectedCameraDeviceId) {
this.setState({ selectedCameraDeviceId: addedCameraDevice.id });
}
this.setState(prevState => ({
...prevState,
cameraDeviceOptions: [...prevState.cameraDeviceOptions, addedCameraDeviceOption]
Expand All @@ -151,7 +155,9 @@ export default class CallCard extends React.Component {

e.removed.forEach(async removedCameraDevice => {
// If the selected camera is removed, select a new camera.
// Note: When the selected camera is removed, the calling sdk automatically turns video off.
// If there are no other cameras, then just set this.state.selectedCameraDeviceId to undefined.
// When the selected camera is removed, the calling sdk automatically turns video off.
// User needs to manually turn video on again.
this.setState(prevState => ({
...prevState,
cameraDeviceOptions: prevState.cameraDeviceOptions.filter(option => { return option.key !== removedCameraDevice.id })
Expand Down Expand Up @@ -211,11 +217,6 @@ export default class CallCard extends React.Component {
this.callFinishConnectingResolve();
}
}
if (this.call.state === 'Incoming') {
this.setState({ selectedCameraDeviceId: cameraDevices[0]?.id });
this.setState({ selectedSpeakerDeviceId: speakerDevices[0]?.id });
this.setState({ selectedMicrophoneDeviceId: microphoneDevices[0]?.id });
}

if (this.call.state !== 'Disconnected') {
this.setState({ callState: this.call.state });
Expand Down

0 comments on commit 1c89a55

Please sign in to comment.