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

@ -324,7 +324,7 @@ export class GameScene extends ResizableScene implements CenterListener {
// Let's alter browser history
let path = this.room.id;
if (this.room.hash) {
path += '#'+this.room.hash;
path += '#' + this.room.hash;
}
window.history.pushState({}, 'WorkAdventure', path);
@ -486,7 +486,7 @@ export class GameScene extends ResizableScene implements CenterListener {
this.stopJitsi();
} else {
if (JITSI_PRIVATE_MODE) {
const adminTag = allProps.get("jitsiRoomAdminTag") as string|undefined;
const adminTag = allProps.get("jitsiRoomAdminTag") as string | undefined;
this.connection.emitQueryJitsiJwtMessage(this.instance.replace('/', '-') + "-" + newValue, adminTag);
} else {
@ -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.timeoutBlurWindows = setTimeout(() => {
this.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia));
this.disableCamera();
}, 10000);
});
window.addEventListener('focus', () => {
if(this.timeoutBlurWindows){
clearTimeout(this.timeoutBlurWindows);
}
this.applyPreviousConfig();
});
this.pingCameraStatus();
this.checkActiveUser();
}
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();
}
public focusCamera() {
if(this.focused){
return;
}
this.focused = true;
this.applyPreviousConfig();
}
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();