File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,22 @@ export default function useGetDevices() {
12
12
return ;
13
13
}
14
14
try {
15
+ const cameraPermission = await navigator . permissions . query ( { name : "camera" } ) ;
16
+ const micPermission = await navigator . permissions . query ( { name : "microphone" } ) ;
17
+ //toggleLoader()
18
+ if ( cameraPermission . state !== "granted" || micPermission . state !== "granted" ) {
19
+ const stream = await navigator . mediaDevices . getUserMedia ( {
20
+ video : true ,
21
+ audio : true ,
22
+ } ) ;
23
+ if ( ! stream ) {
24
+ return ;
25
+ }
26
+ stream . getVideoTracks ( ) . forEach ( ( x ) => x . stop ( ) ) ;
27
+ stream . getAudioTracks ( ) . forEach ( ( x ) => x . stop ( ) ) ;
28
+ }
15
29
const devices = await navigator . mediaDevices . enumerateDevices ( ) ;
30
+ //toggleLoader()
16
31
defaultDevices = devices . reduce ( ( acc , device ) => {
17
32
if ( device . kind === "videoinput" ) {
18
33
acc . video . push ( device ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import usePageVisibility from "../hooks/pageVisibility";
6
6
import { classNames } from "../utils/classNames" ;
7
7
import { text } from "../utils/constants" ;
8
8
import { capitalize , getBrowserName } from "../utils/helpers" ;
9
- import useGetDevices from "../utils/ hooks" ;
9
+ import useGetDevices from "../hooks/useGetDevices " ;
10
10
export async function getStaticProps ( ) {
11
11
return {
12
12
props : { } ,
@@ -137,7 +137,7 @@ export default function Vlog() {
137
137
< form className = "w-full mx-auto md:w-1/4" onSubmit = { handleFormSubmit } >
138
138
{ ! isInitialized && (
139
139
< >
140
- { devices . audio . length && (
140
+ { devices . audio . length ? (
141
141
< div className = "flex flex-col" >
142
142
< label className = "w-full font-semibold" htmlFor = "audioDevice" >
143
143
Select audio input
@@ -168,8 +168,8 @@ export default function Vlog() {
168
168
</ select >
169
169
</ div >
170
170
</ div >
171
- ) }
172
- { devices . video . length && (
171
+ ) : null }
172
+ { devices . video . length ? (
173
173
< div className = "flex flex-col" >
174
174
< label className = "w-full font-semibold" htmlFor = "videoDevice" >
175
175
Select video input
@@ -200,7 +200,7 @@ export default function Vlog() {
200
200
</ select >
201
201
</ div >
202
202
</ div >
203
- ) }
203
+ ) : null }
204
204
< button
205
205
type = "submit"
206
206
className = "flex-grow-0 w-full px-4 py-2 mt-5 font-bold text-white transition bg-green-500 rounded hover:bg-green-700"
You can’t perform that action at this time.
0 commit comments