test 3
This commit is contained in:
@@ -23,15 +23,10 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
|
|
||||||
private readonly pollIntervalMs = 5000;
|
private readonly pollIntervalMs = 5000;
|
||||||
private pollTimer?: ReturnType<typeof setInterval>;
|
private pollTimer?: ReturnType<typeof setInterval>;
|
||||||
private mobileFallbackTimeout?: ReturnType<typeof setTimeout>;
|
|
||||||
private launchFrame?: HTMLIFrameElement;
|
|
||||||
private readonly handleVisibilityChange = () => {
|
private readonly handleVisibilityChange = () => {
|
||||||
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
|
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
|
||||||
this.clearMobileLaunchArtifacts();
|
this.checkLoginAfterReturn();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.checkLoginAfterReturn();
|
|
||||||
};
|
};
|
||||||
private readonly handleWindowFocus = () => {
|
private readonly handleWindowFocus = () => {
|
||||||
this.checkLoginAfterReturn();
|
this.checkLoginAfterReturn();
|
||||||
@@ -46,7 +41,6 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
this.initQrLogin();
|
this.initQrLogin();
|
||||||
} else {
|
} else {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -60,7 +54,6 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@@ -72,7 +65,6 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
|
|
||||||
close(): void {
|
close(): void {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.authService.hideLogin();
|
this.authService.hideLogin();
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
}
|
}
|
||||||
@@ -88,7 +80,7 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
|
|
||||||
if (this.isMobileBrowser()) {
|
if (this.isMobileBrowser()) {
|
||||||
this.awaitingTelegramReturn.set(true);
|
this.awaitingTelegramReturn.set(true);
|
||||||
this.launchTelegramApp(webSessionID);
|
window.location.href = this.authService.getTelegramAppLoginUrl(webSessionID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,14 +89,12 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
|
|
||||||
refreshQr(): void {
|
refreshQr(): void {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
this.initQrLogin();
|
this.initQrLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private initQrLogin(): void {
|
private initQrLogin(): void {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.qrStatus.set('loading');
|
this.qrStatus.set('loading');
|
||||||
this.loginUrl.set('');
|
this.loginUrl.set('');
|
||||||
this.webSessionID.set('');
|
this.webSessionID.set('');
|
||||||
@@ -139,7 +129,6 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
next: (session) => {
|
next: (session) => {
|
||||||
if (session?.active) {
|
if (session?.active) {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
this.authService.onTelegramLoginComplete();
|
this.authService.onTelegramLoginComplete();
|
||||||
}
|
}
|
||||||
@@ -176,46 +165,12 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
this.authService.checkSessionOnce(webSessionID).subscribe(session => {
|
this.authService.checkSessionOnce(webSessionID).subscribe(session => {
|
||||||
if (session?.active) {
|
if (session?.active) {
|
||||||
this.awaitingTelegramReturn.set(false);
|
this.awaitingTelegramReturn.set(false);
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
this.authService.onTelegramLoginComplete();
|
this.authService.onTelegramLoginComplete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private launchTelegramApp(webSessionID: string): void {
|
|
||||||
if (typeof document === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clearMobileLaunchArtifacts();
|
|
||||||
|
|
||||||
this.launchFrame = document.createElement('iframe');
|
|
||||||
this.launchFrame.style.display = 'none';
|
|
||||||
this.launchFrame.setAttribute('aria-hidden', 'true');
|
|
||||||
this.launchFrame.setAttribute('tabindex', '-1');
|
|
||||||
this.launchFrame.src = this.authService.getTelegramAppLoginUrl(webSessionID);
|
|
||||||
document.body.appendChild(this.launchFrame);
|
|
||||||
|
|
||||||
this.mobileFallbackTimeout = setTimeout(() => {
|
|
||||||
this.removeLaunchFrame();
|
|
||||||
}, 1400);
|
|
||||||
}
|
|
||||||
|
|
||||||
private clearMobileLaunchArtifacts(): void {
|
|
||||||
if (this.mobileFallbackTimeout) {
|
|
||||||
clearTimeout(this.mobileFallbackTimeout);
|
|
||||||
this.mobileFallbackTimeout = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.removeLaunchFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
private removeLaunchFrame(): void {
|
|
||||||
this.launchFrame?.remove();
|
|
||||||
this.launchFrame = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
private isMobileBrowser(): boolean {
|
private isMobileBrowser(): boolean {
|
||||||
if (typeof navigator === 'undefined') {
|
if (typeof navigator === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user