use-is-audio-active
v1.0.0
Published
It is react custom hook to detect whether provided audio source is active
Downloads
4
Readme
use-is-audio-active
It is react custom hook to detect whether provided audio source is active
Install
npm install --save use-is-audio-active
Usage
import * as React from 'react'
import useIsAudioActive from 'use-is-audio-active'
const Example = () => {
const [stream, setStream] = React.useState(null)
const isActive = useIsAudioActive({ source: stream });
React.useEffect(() => {
(async function createStream() {
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true,
});
setStream(stream)
})()
}, [])
return (
<p>
Am I speaking: {' '} { isActive ? 'yes, you are 🕺' : "seems like ain't 🦻" }
</p>
)
}