Add server polling

This commit is contained in:
balazs 2019-01-22 13:57:43 +01:00
parent e0025e9451
commit 0269512b76
3 changed files with 51 additions and 19 deletions

View File

@ -36,7 +36,7 @@ export const config = {
'FAILED': 'Deployment failed. Retry'
},
showDeployButton: true,
reloadIframeOnDeploy: false,
reloadIframeOnDeploy: true,
showConsoleOnDeploy: true,
autoDetectFileLanguage: true,
showMiniMap: false

View File

@ -10,7 +10,7 @@
<app-messages (newMessageEvent)="scrollMessagesToBottom()"></app-messages>
</div>
<div class="tfw-web tao-grid-top-left"
[ngClass]="{'deploy-blur': deploying}">
[ngClass]="{'deploy-blur': deploying || polling}">
<app-web *ngIf="!iframeUrl"></app-web>
<div *ngIf="iframeUrl" class="iframe-container">
<div class="urlbar-container">

View File

@ -1,15 +1,17 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { Component, OnDestroy, OnInit, ChangeDetectorRef, ElementRef, ViewChild } from '@angular/core';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { Subscription } from 'rxjs';
import { WebSocketService } from '../services/websocket.service';
import { HideMessagesCommand, LayoutCommand, TerminalMenuItemCommand } from '../message-types/dashboard-commands';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../message-types/log-message';
import { CommandMessage } from '../message-types/command-message';
import {ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {DeploymentNotificationService} from '../services/deployment-notification.service';
import {Subscription} from 'rxjs';
import {WebSocketService} from '../services/websocket.service';
import {HideMessagesCommand, LayoutCommand, TerminalMenuItemCommand} from '../message-types/dashboard-commands';
import {config} from '../config';
import {ProcessLogService} from '../services/processlog.service';
import {LogMessage} from '../message-types/log-message';
import {CommandMessage} from '../message-types/command-message';
import {HttpClient} from '@angular/common/http';
import {delay, retryWhen, tap} from 'rxjs/operators';
@Component({
selector: 'app-dashboard',
@ -18,6 +20,7 @@ import { CommandMessage } from '../message-types/command-message';
})
export class DashboardComponent implements OnInit, OnDestroy {
deploying = false;
polling = false;
deploymentNotificationSubscription: Subscription;
@ViewChild('webiframe') webiframe: ElementRef;
@ViewChild('tfwmessages') messages: ElementRef;
@ -28,6 +31,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
iframeUrl: string = config.dashboard.iframeUrl;
actualIframeUrl: string = this.iframeUrl;
selectedTerminalMenuItem: string = config.dashboard.terminalOrConsole;
iframeReloadSubscription: Subscription;
command_handlers = {
'layout': this.layoutHandler.bind(this),
@ -39,7 +43,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
constructor(private deploymentNotificationService: DeploymentNotificationService,
private webSocketService: WebSocketService,
private changeDetectorRef: ChangeDetectorRef,
private processLogService: ProcessLogService) {}
private processLogService: ProcessLogService,
private http: HttpClient) {}
ngOnInit() {
this.webSocketService.connect();
@ -61,7 +66,10 @@ export class DashboardComponent implements OnInit, OnDestroy {
(deploying) => {
this.deploying = deploying;
if (!deploying && config.ide.reloadIframeOnDeploy) {
this.reloadIframe();
if (this.polling) {
this.iframeReloadSubscription.unsubscribe();
}
this.pollingServerForIframeReload();
}
});
}
@ -110,12 +118,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
setTimeout(() => window.dispatchEvent(new Event('resize', {force: true} as any)), 0);
}
ngOnDestroy() {
if (this.deploymentNotificationSubscription) {
this.deploymentNotificationSubscription.unsubscribe();
}
}
reloadIframe() {
setTimeout(() => {
this.webiframe.nativeElement.contentWindow.location.reload(true);
@ -152,4 +154,34 @@ export class DashboardComponent implements OnInit, OnDestroy {
changeIframeURL() {
this.webiframe.nativeElement.contentWindow.frames.location.pathname = this.actualIframeUrl;
}
pollingServerForIframeReload() {
this.polling = true;
this.iframeReloadSubscription = this.http.get(this.actualIframeUrl, {observe: 'response'}).pipe(
retryWhen(errors =>
errors.pipe(
tap(
response => {
if (response.status === 200) {
this.iframeReloadSubscription.unsubscribe();
this.polling = false;
this.reloadIframe();
}
}
),
delay(1000)
)
)
).subscribe();
}
ngOnDestroy() {
if (this.deploymentNotificationSubscription) {
this.deploymentNotificationSubscription.unsubscribe();
}
if (this.iframeReloadSubscription) {
this.iframeReloadSubscription.unsubscribe();
}
}
}