From 65a710d1f4f0bae88f3d7c28514a4344b0499208 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Mon, 26 Oct 2020 15:07:34 +0100 Subject: [PATCH] disabling audio/video in jitsi carry over to wa --- front/src/WebRtc/JitsiFactory.ts | 25 +++++++++++++++++++++++++ front/src/WebRtc/MediaManager.ts | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/front/src/WebRtc/JitsiFactory.ts b/front/src/WebRtc/JitsiFactory.ts index d0658218..191642fb 100644 --- a/front/src/WebRtc/JitsiFactory.ts +++ b/front/src/WebRtc/JitsiFactory.ts @@ -27,6 +27,9 @@ const interfaceConfig = { class JitsiFactory { private jitsiApi: any; // eslint-disable-line @typescript-eslint/no-explicit-any + private audioCallback = this.onAudioChange.bind(this); + private videoCallback = this.onVideoChange.bind(this); + public start(roomName: string, playerName:string, jwt?: string): void { CoWebsiteManager.insertCoWebsite((cowebsiteDiv => { const domain = JITSI_URL; @@ -48,13 +51,35 @@ class JitsiFactory { } this.jitsiApi = new window.JitsiMeetExternalAPI(domain, options); this.jitsiApi.executeCommand('displayName', playerName); + + this.jitsiApi.addListener('audioMuteStatusChanged', this.audioCallback); + this.jitsiApi.addListener('videoMuteStatusChanged', this.videoCallback); })); } public stop(): void { + this.jitsiApi.removeListener('audioMuteStatusChanged', this.audioCallback); + this.jitsiApi.removeListener('videoMuteStatusChanged', this.videoCallback); this.jitsiApi?.dispose(); CoWebsiteManager.closeCoWebsite(); } + + private onAudioChange({muted}: {muted: boolean}): void { + if (muted && mediaManager.constraintsMedia.audio === true) { + mediaManager.disableMicrophone(); + } else if(!muted && mediaManager.constraintsMedia.audio === false) { + mediaManager.enableMicrophone(); + } + } + + private onVideoChange({muted}: {muted: boolean}): void { + if (muted && mediaManager.constraintsMedia.video !== false) { + mediaManager.disableCamera(); + } else if(!muted && mediaManager.constraintsMedia.video === false) { + mediaManager.enableCamera(); + } + } + } export const jitsiFactory = new JitsiFactory(); \ No newline at end of file diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index 557f12fb..ab6d9a3b 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -135,7 +135,7 @@ export class MediaManager { gameOverlay.classList.remove('active'); } - private enableCamera() { + public enableCamera() { this.cinemaClose.style.display = "none"; this.cinemaBtn.classList.remove("disabled"); this.cinema.style.display = "block"; @@ -145,7 +145,7 @@ export class MediaManager { }); } - private async disableCamera() { + public async disableCamera() { this.cinemaClose.style.display = "block"; this.cinema.style.display = "none"; this.cinemaBtn.classList.add("disabled"); @@ -161,7 +161,7 @@ export class MediaManager { } } - private enableMicrophone() { + public enableMicrophone() { this.microphoneClose.style.display = "none"; this.microphone.style.display = "block"; this.microphoneBtn.classList.remove("disabled"); @@ -172,7 +172,7 @@ export class MediaManager { }); } - private async disableMicrophone() { + public async disableMicrophone() { this.microphoneClose.style.display = "block"; this.microphone.style.display = "none"; this.microphoneBtn.classList.add("disabled");