Skip to content

Instantly share code, notes, and snippets.

@iha2
Last active August 12, 2018 22:17
Show Gist options
  • Save iha2/2604230df2b174b500f502ccdac91f3f to your computer and use it in GitHub Desktop.
Save iha2/2604230df2b174b500f502ccdac91f3f to your computer and use it in GitHub Desktop.
a redux observable epic that controls and uses a webcam.
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