Skip to content

Commit

Permalink
[MODIFIED] camera permission check setState (#467)
Browse files Browse the repository at this point in the history
Signed-off-by: Zeeshan Mehboob <[email protected]>
  • Loading branch information
zesu22 authored Dec 12, 2024
1 parent 03634ad commit cb7cf1c
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,31 @@ export const VideoPreview = ({
// if camera permission granted then set the state
const cameraPermissionAllowed = useCallback((stream: MediaStream) => {
window.videoLocalStream = stream;
if (!permissionGranted) {
setPermissionGranted(true);
}
setPermissionGranted(true);
}, []);

// if camera permission denied then set the state
const cameraPermissionDenied = useCallback((error: any) => {
if (permissionGranted) {
setPermissionGranted(false);
if (error.name === "NotReadableError") {
if (permissionErrMsg.header !== "not_accessible_header") {
setPermissionErrMsg({
header: "not_accessible_header",
description: "not_accessible_description",
});
}
} else if (permissionErrMsg.header !== "permission_denied_header") {
setPermissionErrMsg({
header: "permission_denied_header",
description: "permission_denied_description",
});
}
}
setPermissionGranted(false);

// doing this type of setting the state
// so that it not re render anything
// it will only render when state is actually changed
setPermissionErrMsg((_) =>
error.name === "NotReadableError"
? _.header !== "not_accessible_header"
? {
header: "not_accessible_header",
description: "not_accessible_description",
}
: _
: _.header !== "permission_denied_header"
? {
header: "permission_denied_header",
description: "permission_denied_description",
}
: _
);
}, []);

// video preview div, it will show the video preview if camera permission granted
Expand Down

0 comments on commit cb7cf1c

Please sign in to comment.