Update to use update function scene

This commit is contained in:
Gregoire Parant 2020-10-26 22:39:52 +01:00
parent 69f3e511ab
commit 997acd17ad
2 changed files with 47 additions and 20 deletions

View File

@ -634,7 +634,6 @@ export class GameScene extends ResizableScene implements CenterListener {
this.gameMap.setPosition(event.x, event.y);
})
this.scene.wake();
this.scene.sleep(ReconnectingSceneName);
@ -973,6 +972,8 @@ export class GameScene extends ResizableScene implements CenterListener {
this.scene.remove(this.scene.key);
this.scene.start(nextSceneKey.key);
}
mediaManager.setLastUpdateScene();
}
private checkToExit(): {key: string, hash: string} | null {

View File

@ -39,7 +39,10 @@ export class MediaManager {
private monitorBtn: HTMLDivElement;
private previousConstraint : MediaStreamConstraints;
private timeoutBlurWindows?: NodeJS.Timeout;
private focused : boolean = true;
private lastUpdateScene : Date = new Date();
private setTimeOutlastUpdateScene? : NodeJS.Timeout;
constructor() {
@ -94,22 +97,30 @@ export class MediaManager {
});
this.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia));
window.addEventListener('blur', () => {
if(this.timeoutBlurWindows){
clearTimeout(this.timeoutBlurWindows);
this.pingCameraStatus();
this.checkActiveUser();
}
this.timeoutBlurWindows = setTimeout(() => {
public setLastUpdateScene(){
this.lastUpdateScene = new Date();
}
public blurCamera() {
if(!this.focused){
return;
}
this.focused = false;
this.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia));
this.disableCamera();
}, 10000);
});
window.addEventListener('focus', () => {
if(this.timeoutBlurWindows){
clearTimeout(this.timeoutBlurWindows);
}
public focusCamera() {
if(this.focused){
return;
}
this.focused = true;
this.applyPreviousConfig();
});
this.pingCameraStatus();
}
public onUpdateLocalStream(callback: UpdatedLocalStreamCallback): void {
@ -631,7 +642,22 @@ export class MediaManager {
}, 30000);
}
//check if user is active
private checkActiveUser(){
if(this.setTimeOutlastUpdateScene){
clearTimeout(this.setTimeOutlastUpdateScene);
}
this.setTimeOutlastUpdateScene = setTimeout(() => {
const now = new Date();
//if last update is more of 10 sec
if( (now.getTime() - this.lastUpdateScene.getTime()) > 10000) {
this.blurCamera();
}else{
this.focusCamera();
}
this.checkActiveUser();
}, this.focused ? 10000 : 1000);
}
}
export const mediaManager = new MediaManager();