Commit fd8f341b authored by David Burke's avatar David Burke

Closes #199

parent 6715bf86
Pipeline #38685120 failed with stage
in 5 minutes and 4 seconds
......@@ -5,18 +5,23 @@ import {
EventEmitter,
Output,
ViewChild,
ElementRef
ElementRef,
OnDestroy
} from "@angular/core";
import { FormGroupState } from "ngrx-forms";
import { IResetPasswordVerifyForm } from "./reset-password-verify.reducer";
import jsQR from "jsqr";
import { IResetPasswordVerifyForm } from "./reset-password-verify.reducer";
@Component({
selector: "app-reset-password-verify",
templateUrl: "./reset-password-verify.component.html",
styleUrls: ["./reset-password-verify.component.scss", "../../account.component.scss"]
styleUrls: [
"./reset-password-verify.component.scss",
"../../account.component.scss"
]
})
export class ResetPasswordVerifyComponent implements OnInit {
export class ResetPasswordVerifyComponent implements OnInit, OnDestroy {
@Input()
form: FormGroupState<IResetPasswordVerifyForm>;
@Input()
......@@ -69,7 +74,8 @@ export class ResetPasswordVerifyComponent implements OnInit {
this.videoBootstrapped = true;
})
.catch(err => {
this.cameraError = "Unable to initialize the camera. Try typing the backup code in the text field below instead.";
this.cameraError =
"Unable to initialize the camera. Try typing the backup code in the text field below instead.";
this.toggleScan();
});
} else {
......@@ -78,21 +84,20 @@ export class ResetPasswordVerifyComponent implements OnInit {
}
}
// TODO: figure out how to run this function when navigated away from route
stopStreamedVideo(videoElem: any) {
const stream = videoElem.srcObject;
stopStreamedVideo() {
const stream = this.video.srcObject as MediaStream;
const tracks = stream.getTracks();
tracks.forEach(function(track: any) {
track.stop();
});
videoElem.srcObject = null;
this.video.srcObject = null;
}
handleQrFound = (content: string) => {
this.verify.emit(content);
}
this.verify.emit(content);
};
onSubmit() {
if (this.form.isValid) {
......@@ -106,9 +111,13 @@ export class ResetPasswordVerifyComponent implements OnInit {
this.canvas = this.canvasElement.getContext("2d")!;
}
ngOnDestroy() {
this.stopStreamedVideo();
}
/*
* Video event loop, runs forever while showScanner is true and then stops
*/
* Video event loop, runs forever while showScanner is true and then stops
*/
tick = () => {
if (this.showScanner) {
if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {
......@@ -131,9 +140,9 @@ export class ResetPasswordVerifyComponent implements OnInit {
this.showQuitButton = true;
if (code) {
this.handleQrFound(code.data);
}
}
}
requestAnimationFrame(this.tick);
}
}
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment