mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 15:51:14 +00:00
Fix captcha replay bug. Fixes #348
This commit is contained in:
parent
cffdfab8eb
commit
6df4e51d50
1 changed files with 17 additions and 9 deletions
|
@ -41,6 +41,7 @@ interface State {
|
||||||
export class Login extends Component<any, State> {
|
export class Login extends Component<any, State> {
|
||||||
private isoData = setIsoData(this.context);
|
private isoData = setIsoData(this.context);
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
|
private audio: HTMLAudioElement;
|
||||||
|
|
||||||
emptyState: State = {
|
emptyState: State = {
|
||||||
loginForm: {
|
loginForm: {
|
||||||
|
@ -406,8 +407,8 @@ export class Login extends Component<any, State> {
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRegenCaptcha(_i: Login, event: any) {
|
handleRegenCaptcha(i: Login) {
|
||||||
event.preventDefault();
|
i.audio = null;
|
||||||
WebSocketService.Instance.send(wsClient.getCaptcha());
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,16 +420,23 @@ export class Login extends Component<any, State> {
|
||||||
WebSocketService.Instance.send(wsClient.passwordReset(resetForm));
|
WebSocketService.Instance.send(wsClient.passwordReset(resetForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCaptchaPlay(i: Login, event: any) {
|
handleCaptchaPlay(i: Login) {
|
||||||
event.preventDefault();
|
// This was a bad bug, it should only build the new audio on a new file.
|
||||||
let snd = new Audio("data:audio/wav;base64," + i.state.captcha.ok.wav);
|
// Replays would stop prematurely if this was rebuilt every time.
|
||||||
snd.play();
|
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.state.captchaPlaying = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
snd.addEventListener("ended", () => {
|
|
||||||
snd.currentTime = 0;
|
i.audio.addEventListener("ended", () => {
|
||||||
|
i.audio.currentTime = 0;
|
||||||
i.state.captchaPlaying = false;
|
i.state.captchaPlaying = false;
|
||||||
i.setState(this.state);
|
i.setState(i.state);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue