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's alter browser history
let path = this.room.id; let path = this.room.id;
if (this.room.hash) { if (this.room.hash) {
path += '#'+this.room.hash; path += '#' + this.room.hash;
} }
window.history.pushState({}, 'WorkAdventure', path); window.history.pushState({}, 'WorkAdventure', path);
@ -486,7 +486,7 @@ export class GameScene extends ResizableScene implements CenterListener {
this.stopJitsi(); this.stopJitsi();
} else { } else {
if (JITSI_PRIVATE_MODE) { 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); this.connection.emitQueryJitsiJwtMessage(this.instance.replace('/', '-') + "-" + newValue, adminTag);
} else { } else {
@ -634,7 +634,6 @@ export class GameScene extends ResizableScene implements CenterListener {
this.gameMap.setPosition(event.x, event.y); this.gameMap.setPosition(event.x, event.y);
}) })
this.scene.wake(); this.scene.wake();
this.scene.sleep(ReconnectingSceneName); this.scene.sleep(ReconnectingSceneName);
@ -973,6 +972,8 @@ export class GameScene extends ResizableScene implements CenterListener {
this.scene.remove(this.scene.key); this.scene.remove(this.scene.key);
this.scene.start(nextSceneKey.key); this.scene.start(nextSceneKey.key);
} }
mediaManager.setLastUpdateScene();
} }
private checkToExit(): {key: string, hash: string} | null { private checkToExit(): {key: string, hash: string} | null {

View File

@ -39,7 +39,10 @@ export class MediaManager {
private monitorBtn: HTMLDivElement; private monitorBtn: HTMLDivElement;
private previousConstraint : MediaStreamConstraints; private previousConstraint : MediaStreamConstraints;
private timeoutBlurWindows?: NodeJS.Timeout; private focused : boolean = true;
private lastUpdateScene : Date = new Date();
private setTimeOutlastUpdateScene? : NodeJS.Timeout;
constructor() { constructor() {
@ -94,22 +97,30 @@ export class MediaManager {
}); });
this.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia)); this.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia));
window.addEventListener('blur', () => { this.pingCameraStatus();
if(this.timeoutBlurWindows){
clearTimeout(this.timeoutBlurWindows); 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.previousConstraint = JSON.parse(JSON.stringify(this.constraintsMedia));
this.disableCamera(); this.disableCamera();
}, 10000);
});
window.addEventListener('focus', () => {
if(this.timeoutBlurWindows){
clearTimeout(this.timeoutBlurWindows);
} }
public focusCamera() {
if(this.focused){
return;
}
this.focused = true;
this.applyPreviousConfig(); this.applyPreviousConfig();
});
this.pingCameraStatus();
} }
public onUpdateLocalStream(callback: UpdatedLocalStreamCallback): void { public onUpdateLocalStream(callback: UpdatedLocalStreamCallback): void {
@ -631,7 +642,22 @@ export class MediaManager {
}, 30000); }, 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(); export const mediaManager = new MediaManager();