Skip to content

Commit

Permalink
Fix captcha replay bug. Fixes #348 (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Jul 22, 2021
1 parent cffdfab commit 49d5810
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/shared/components/home/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface State {
export class Login extends Component<any, State> {
private isoData = setIsoData(this.context);
private subscription: Subscription;
private audio: HTMLAudioElement;

emptyState: State = {
loginForm: {
Expand Down Expand Up @@ -406,8 +407,8 @@ export class Login extends Component<any, State> {
i.setState(i.state);
}

handleRegenCaptcha(_i: Login, event: any) {
event.preventDefault();
handleRegenCaptcha(i: Login) {
i.audio = null;
WebSocketService.Instance.send(wsClient.getCaptcha());
}

Expand All @@ -419,16 +420,23 @@ export class Login extends Component<any, State> {
WebSocketService.Instance.send(wsClient.passwordReset(resetForm));
}

handleCaptchaPlay(i: Login, event: any) {
event.preventDefault();
let snd = new Audio("data:audio/wav;base64," + i.state.captcha.ok.wav);
snd.play();
handleCaptchaPlay(i: Login) {
// This was a bad bug, it should only build the new audio on a new file.
// Replays would stop prematurely if this was rebuilt every time.
if (i.audio == null) {
let base64 = `data:audio/wav;base64,${i.state.captcha.ok.wav}`;
i.audio = new Audio(base64);
}

i.audio.play();

i.state.captchaPlaying = true;
i.setState(i.state);
snd.addEventListener("ended", () => {
snd.currentTime = 0;

i.audio.addEventListener("ended", () => {
i.audio.currentTime = 0;
i.state.captchaPlaying = false;
i.setState(this.state);
i.setState(i.state);
});
}

Expand Down

0 comments on commit 49d5810

Please sign in to comment.