Skip to content

Commit 77b59b5

Browse files
fix(extension): add safe handling for video stream cleanup [LW-12719] (#1896)
1 parent 899b1b3 commit 77b59b5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

apps/browser-extension-wallet/src/views/bitcoin-mode/features/multi-wallet/restore-wallet/steps/ScanShieldedMessage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export const ScanShieldedMessage: VFC = () => {
5858
const [deviceId, setDeviceId] = useState<MediaDeviceInfo['deviceId'] | null>();
5959

6060
const endVideoTracks = () => {
61-
streamRef.current.getVideoTracks().forEach((t) => t.stop());
62-
streamRef.current = null;
61+
if (streamRef.current) {
62+
streamRef.current.getVideoTracks().forEach((t) => t.stop());
63+
streamRef.current = null;
64+
}
6365
};
6466

6567
const handleDeviceChange = async (value: MediaDeviceInfo['deviceId']) => {
@@ -109,6 +111,8 @@ export const ScanShieldedMessage: VFC = () => {
109111
};
110112
setScanState('waiting');
111113
getVideoStream();
114+
115+
return endVideoTracks;
112116
}, [
113117
deviceId,
114118
analytics,

apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/ScanShieldedMessage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export const ScanShieldedMessage: VFC = () => {
5858
const [deviceId, setDeviceId] = useState<MediaDeviceInfo['deviceId'] | null>();
5959

6060
const endVideoTracks = () => {
61-
streamRef.current.getVideoTracks().forEach((t) => t.stop());
62-
streamRef.current = null;
61+
if (streamRef.current) {
62+
streamRef.current.getVideoTracks().forEach((t) => t.stop());
63+
streamRef.current = null;
64+
}
6365
};
6466

6567
const handleDeviceChange = async (value: MediaDeviceInfo['deviceId']) => {
@@ -109,6 +111,8 @@ export const ScanShieldedMessage: VFC = () => {
109111
};
110112
setScanState('waiting');
111113
getVideoStream();
114+
115+
return endVideoTracks;
112116
}, [
113117
deviceId,
114118
analytics,

0 commit comments

Comments
 (0)