Skip to content

Commit da7b314

Browse files
committed
Added check formidi
1 parent b5115c0 commit da7b314

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

package-lock.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ export const useMIDI = () => {
99
outputs: [],
1010
});
1111
useEffect(() => {
12-
navigator.requestMIDIAccess().then((access) => {
13-
changeConnections({
14-
inputs: enrichInputs([...access.inputs.values()]),
15-
outputs: [...access.outputs.values()],
16-
});
17-
access.onstatechange = (e) => {
12+
if (navigator.requestMIDIAccess) {
13+
navigator.requestMIDIAccess().then((access) => {
1814
changeConnections({
1915
inputs: enrichInputs([...access.inputs.values()]),
2016
outputs: [...access.outputs.values()],
2117
});
22-
};
23-
});
18+
access.onstatechange = (e) => {
19+
changeConnections({
20+
inputs: enrichInputs([...access.inputs.values()]),
21+
outputs: [...access.outputs.values()],
22+
});
23+
};
24+
});
25+
}
2426
}, []);
25-
return [connections.inputs, connections.outputs];
27+
return [connections.inputs, connections.outputs, !!navigator.requestMIDIAccess];
2628
};
2729

2830
// If listeners were kept in a general .listeners field then 100 functions listening for a noteOn event would get

0 commit comments

Comments
 (0)