Skip to content

Commit

Permalink
Reset stream in camera_stream if camera changes #305
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin49999 authored Nov 25, 2024
1 parent 3de272a commit c9bc4fa
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/widgets/camera_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ class _ViamCameraStreamViewState extends State<ViamCameraStreamView> {
_startStream();
}

@override
void didUpdateWidget(ViamCameraStreamView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.camera != widget.camera) {
_cleanupStream();
_startStream();
}
}

@override
void dispose() {
_renderer.dispose();
_streamSub.cancel();
widget.streamClient.closeStream();
_cleanupStream();
super.dispose();
}

Expand Down Expand Up @@ -70,6 +77,12 @@ class _ViamCameraStreamViewState extends State<ViamCameraStreamView> {
});
}

void _cleanupStream() {
_renderer.dispose();
_streamSub.cancel();
widget.streamClient.closeStream();
}

@override
Widget build(BuildContext context) {
return (_error != null)
Expand Down

0 comments on commit c9bc4fa

Please sign in to comment.