Skip to content

Commit 5927b25

Browse files
committed
Fix bug where LocalVideoProvider doesnt update isVideoEnabled on unplugged video device
1 parent b93eebf commit 5927b25

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Changed
1919

2020
### Fixed
21+
- Fix a bug where the `isVideoEnabled` is still true even when the video device is unplugged.
2122

2223
- When audio inputs change in a meeting, `AudioInputProvider` will only automatically select a new audio input device if a meeting is joined with `DeviceLabels.Audio` or `DeviceLabels.AudioAndVideo` device labels.
2324
- Publish `MeetingStatus.Failed` only when a non-terminal failure is encountered. Currently, some Amazon Chime SDK for JavaScript meeting session statuses pass both the `sessionStatus.isFailure()` as well as `sessionStatus.isTerminal()` in JS SDK, thus, for a status if it is in both, it will be considered as non-terminal failure and `MeetingStatus.TerminalFailure` will never get set for such statuses. Check [MeetingSessionStatus](https://github.com/aws/amazon-chime-sdk-js/blob/main/src/meetingsession/MeetingSessionStatus.ts) file for more information on both methods in JS SDK.

src/providers/LocalVideoProvider/docs/LocalVideoProvider.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The React SDK depends on the Amazon Chime SDK for JavaScript, wherein, a single
1111
To start/stop a video preview, please check `PreviewVideo` component [documentation](/docs/sdk-components-previewvideo--page).
1212
To start/stop user's local video, use `toggleVideo` function from the `LocalVideoProvider`.
1313

14+
In the case of a video being unplugged, the React SDK will automatically stop the local video tile, and will not choose another video device automatically.
15+
1416
## State
1517

1618
```javascript

src/providers/LocalVideoProvider/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const LocalVideoProvider: React.FC = ({ children }) => {
2323
const logger = useLogger();
2424
const meetingManager = useMeetingManager();
2525
const audioVideo = useAudioVideo();
26-
const { selectedDevice } = useVideoInputs();
26+
const { devices, selectedDevice } = useVideoInputs();
2727
const [isVideoEnabled, setIsVideoEnabled] = useState(false);
2828
const [hasReachedVideoLimit, setHasReachedVideoLimit] = useState(false);
2929
const [tileId, setTileId] = useState<number | null>(null);
@@ -63,6 +63,14 @@ const LocalVideoProvider: React.FC = ({ children }) => {
6363
}
6464
}, [hasReachedVideoLimit]);
6565

66+
// In the case that the selected device is unplugged, the JS SDK will automatically call stopLocalVideoTile
67+
// We can then set the isVideoEnabled to false
68+
useEffect(() => {
69+
if (!audioVideo?.hasStartedLocalVideoTile()) {
70+
setIsVideoEnabled(false);
71+
}
72+
}, [devices]);
73+
6674
const toggleVideo = useCallback(async (): Promise<void> => {
6775
try {
6876
if (isVideoEnabled || !selectedDevice) {

0 commit comments

Comments
 (0)