1.0.3 • Published 3 years ago

react-motion-detect v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-motion-detect

A simple react component to detect motion from a camera and callback when detected.

Usage

import Motion from 'react-detect-motion';

const MyComponent = () => {
    const onMotion = () => {
        console.log('I get called when motion is detected')
    }

    return <Motion onMotion={onMotion} />
}

There many parameters to the component to configure the sensitivity and behavior.

ParameterTypeDescription
onMotionFunctionRequired: function called when motion is detected
detectIntervalNumber(optional) number of milliseconds between polling the video images for changes/movement - default: 100
widthNumber(optional) pixel width of the video used to analyze movement (and optionally display) - default: 64
heightNumber(optional) pixel height of the video used to analyze movement (and optionally display) - default: 48
motionThreasholdNumber(optional) total distance of all pixel shifts between analyzed frames to trigger motion detected - default: 50000
minTimeBetweenNumber(optional) minimum time between onMotion function calls in milliseconds - default: 3000
showElementsBoolean(optional) when enabled, the video and camera elements will be visibly rendered - this is required for Safari - default: false

Disclaimer

This has only been tested in the Chrome (Windows & MacOS) and on Safari (MacOS) -- your mileage may vary.