Switch off camera when user is not focused on WorkAdventure windows
Feature to switch off camera when user is not focused on WorkAdventure windows after 10 seconds
This commit is contained in:
parent
3e41875cd5
commit
199ed1266a
@ -38,6 +38,9 @@ export class MediaManager {
|
|||||||
private cinemaBtn: HTMLDivElement;
|
private cinemaBtn: HTMLDivElement;
|
||||||
private monitorBtn: HTMLDivElement;
|
private monitorBtn: HTMLDivElement;
|
||||||
|
|
||||||
|
private previousConstraint : MediaStreamConstraints;
|
||||||
|
private timeoutBlurWindows?: NodeJS.Timeout;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this.myCamVideo = this.getElementByIdOrFail<HTMLVideoElement>('myCamVideo');
|
this.myCamVideo = this.getElementByIdOrFail<HTMLVideoElement>('myCamVideo');
|
||||||
@ -89,6 +92,23 @@ export class MediaManager {
|
|||||||
this.disableScreenSharing();
|
this.disableScreenSharing();
|
||||||
//update tracking
|
//update tracking
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public onUpdateLocalStream(callback: UpdatedLocalStreamCallback): void {
|
public onUpdateLocalStream(callback: UpdatedLocalStreamCallback): void {
|
||||||
@ -136,9 +156,7 @@ export class MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enableCamera() {
|
private enableCamera() {
|
||||||
this.cinemaClose.style.display = "none";
|
this.enableCameraStyle();
|
||||||
this.cinemaBtn.classList.remove("disabled");
|
|
||||||
this.cinema.style.display = "block";
|
|
||||||
this.constraintsMedia.video = videoConstraint;
|
this.constraintsMedia.video = videoConstraint;
|
||||||
this.getCamera().then((stream: MediaStream) => {
|
this.getCamera().then((stream: MediaStream) => {
|
||||||
this.triggerUpdatedLocalStreamCallbacks(stream);
|
this.triggerUpdatedLocalStreamCallbacks(stream);
|
||||||
@ -146,11 +164,7 @@ export class MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async disableCamera() {
|
private async disableCamera() {
|
||||||
this.cinemaClose.style.display = "block";
|
this.disableCameraStyle();
|
||||||
this.cinema.style.display = "none";
|
|
||||||
this.cinemaBtn.classList.add("disabled");
|
|
||||||
this.constraintsMedia.video = false;
|
|
||||||
this.myCamVideo.srcObject = null;
|
|
||||||
this.stopCamera();
|
this.stopCamera();
|
||||||
|
|
||||||
if (this.constraintsMedia.audio !== false) {
|
if (this.constraintsMedia.audio !== false) {
|
||||||
@ -162,9 +176,7 @@ export class MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enableMicrophone() {
|
private enableMicrophone() {
|
||||||
this.microphoneClose.style.display = "none";
|
this.enableMicrophoneStyle();
|
||||||
this.microphone.style.display = "block";
|
|
||||||
this.microphoneBtn.classList.remove("disabled");
|
|
||||||
this.constraintsMedia.audio = true;
|
this.constraintsMedia.audio = true;
|
||||||
|
|
||||||
this.getCamera().then((stream) => {
|
this.getCamera().then((stream) => {
|
||||||
@ -173,10 +185,7 @@ export class MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async disableMicrophone() {
|
private async disableMicrophone() {
|
||||||
this.microphoneClose.style.display = "block";
|
this.disableMicrophoneStyle();
|
||||||
this.microphone.style.display = "none";
|
|
||||||
this.microphoneBtn.classList.add("disabled");
|
|
||||||
this.constraintsMedia.audio = false;
|
|
||||||
this.stopMicrophone();
|
this.stopMicrophone();
|
||||||
|
|
||||||
if (this.constraintsMedia.video !== false) {
|
if (this.constraintsMedia.video !== false) {
|
||||||
@ -187,6 +196,51 @@ export class MediaManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private applyPreviousConfig() {
|
||||||
|
this.constraintsMedia = this.previousConstraint;
|
||||||
|
if(!this.constraintsMedia.video){
|
||||||
|
this.disableCameraStyle();
|
||||||
|
}else{
|
||||||
|
this.enableCameraStyle();
|
||||||
|
}
|
||||||
|
if(!this.constraintsMedia.audio){
|
||||||
|
this.disableMicrophoneStyle()
|
||||||
|
}else{
|
||||||
|
this.enableMicrophoneStyle()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getCamera().then((stream: MediaStream) => {
|
||||||
|
this.triggerUpdatedLocalStreamCallbacks(stream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private enableCameraStyle(){
|
||||||
|
this.cinemaClose.style.display = "none";
|
||||||
|
this.cinemaBtn.classList.remove("disabled");
|
||||||
|
this.cinema.style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
private disableCameraStyle(){
|
||||||
|
this.cinemaClose.style.display = "block";
|
||||||
|
this.cinema.style.display = "none";
|
||||||
|
this.cinemaBtn.classList.add("disabled");
|
||||||
|
this.constraintsMedia.video = false;
|
||||||
|
this.myCamVideo.srcObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enableMicrophoneStyle(){
|
||||||
|
this.microphoneClose.style.display = "none";
|
||||||
|
this.microphone.style.display = "block";
|
||||||
|
this.microphoneBtn.classList.remove("disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
private disableMicrophoneStyle(){
|
||||||
|
this.microphoneClose.style.display = "block";
|
||||||
|
this.microphone.style.display = "none";
|
||||||
|
this.microphoneBtn.classList.add("disabled");
|
||||||
|
this.constraintsMedia.audio = false;
|
||||||
|
}
|
||||||
|
|
||||||
private enableScreenSharing() {
|
private enableScreenSharing() {
|
||||||
this.monitorClose.style.display = "none";
|
this.monitorClose.style.display = "none";
|
||||||
this.monitor.style.display = "block";
|
this.monitor.style.display = "block";
|
||||||
|
Loading…
Reference in New Issue
Block a user