Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav authored and github-actions[bot] committed Sep 28, 2022
1 parent 65b6c30 commit 9c616c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/permission/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const App: Component = () => {
const camPermission = createPermission("camera");

const requestPermission = (constraints: MediaStreamConstraints) =>
navigator.mediaDevices.getUserMedia(constraints)
navigator.mediaDevices
.getUserMedia(constraints)
.then(stream => stream.getTracks().forEach(track => track.stop()))
.catch(console.warn);

Expand Down
18 changes: 10 additions & 8 deletions packages/permission/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ export const createPermission = (
})
: getUserMedia(constraints);
});
createEffect(on(status, (status) => {
if (status) {
setPermission(status.state);
const listener = () => setPermission(status.state);
status.addEventListener("change", listener);
onCleanup(() => status.removeEventListener("change", listener));
}
}))
createEffect(
on(status, status => {
if (status) {
setPermission(status.state);
const listener = () => setPermission(status.state);
status.addEventListener("change", listener);
onCleanup(() => status.removeEventListener("change", listener));
}
})
);
}
return permission;
};

0 comments on commit 9c616c8

Please sign in to comment.