Created
August 12, 2018 21:10
-
-
Save iha2/2895a57405bd3e8570e44590e63106bf to your computer and use it in GitHub Desktop.
initiate a webcam and turn it into an observable.
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
import { timer, Subject, from, Observable } from 'rxjs'; | |
export function createWebcam(webcam: HTMLVideoElement): Observable<{}> { | |
return from( | |
new Promise<{}>((resolve, reject) => { | |
if (navigator.getUserMedia) { | |
navigator.getUserMedia( | |
{ video: true }, | |
stream => { | |
webcam.srcObject = stream; | |
resolve(); | |
}, | |
error => { | |
reject(error); | |
} | |
); | |
} else { | |
reject(new Error('No getuserMedia method found in navigation found.')); | |
} | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment