Skip to content

Instantly share code, notes, and snippets.

@iha2
Created August 12, 2018 21:10
Show Gist options
  • Save iha2/2895a57405bd3e8570e44590e63106bf to your computer and use it in GitHub Desktop.
Save iha2/2895a57405bd3e8570e44590e63106bf to your computer and use it in GitHub Desktop.
initiate a webcam and turn it into an observable.
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