Skip to content

Commit

Permalink
UI: Server Time refresh prevents the Keycloak idle process #3150
Browse files Browse the repository at this point in the history
  • Loading branch information
shral committed Apr 20, 2021
1 parent 2061b48 commit 01e0195
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions dcm4chee-arc-ui2/src/app/app.component.ts
Expand Up @@ -25,6 +25,7 @@ import {LanguageConfig, LanguageObject, LocalLanguageObject} from "./interfaces"
import {AppRequestsService} from "./app-requests.service";
declare var DCM4CHE: any;
declare var Keycloak: any;
const worker = new Worker('./server-time.worker', { type: 'module' });

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -163,10 +164,21 @@ export class AppComponent implements OnInit {
});*/
this.initGetPDQServices();
this.startTime();
document.addEventListener("visibilitychange", () => {
if(document.visibilityState === "visible"){
this.startTime();
}else{
if(worker){
worker.postMessage({
serverTime:this.currentServerTime,
idle:document.hidden
});
}
}
});
}
startTime(){
if (typeof Worker !== 'undefined') {
const worker = new Worker('./server-time.worker', { type: 'module' });
worker.onmessage = ({data}) => {
try{
this.currentServerTime = new Date(data.serverTime);
Expand All @@ -183,7 +195,9 @@ export class AppComponent implements OnInit {
}else{
console.log("worker not available");
}

}

refreshTime(worker){
let currentBrowserTime = new Date().getTime();
this.appRequests.getServerTime()
Expand All @@ -193,7 +207,8 @@ export class AppComponent implements OnInit {
this.timeZone = serverTimeObject.timeZone;
this.mainservice.timeZone = this.timeZone;
worker.postMessage({
serverTime:new Date(serverTimeObject.time).getTime()+((new Date().getTime()-currentBrowserTime)/2)
serverTime:new Date(serverTimeObject.time).getTime()+((new Date().getTime()-currentBrowserTime)/2),
idle:document.hidden
});
this.hideExtendedClock();
}
Expand Down

0 comments on commit 01e0195

Please sign in to comment.