Last active
August 12, 2018 22:17
-
-
Save iha2/2604230df2b174b500f502ccdac91f3f to your computer and use it in GitHub Desktop.
a redux observable epic that controls and uses a webcam.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initializeWebcamEpic = (actions$: ActionsObservable<StartWebcamAction>) => | |
actions$.pipe( | |
ofType(WebcamActionTypes.START_WEBCAM), | |
switchMap(({ payload }) => { | |
let timerIntervalMultiple = 0; | |
return initializeWebcam(payload.videoElement, payload.canvasElement).pipe( | |
tap(_ => (timerIntervalMultiple += 1)), | |
filter(_ => (timerIntervalMultiple * 40 > 200 ? true : false)), | |
map(_ => payload.canvasElement.toDataURL('image/jpeg', 1.0)), | |
map(jpeg => storeImage(jpeg)) | |
); | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment