show voice indicator above alpha-male (dominant) jitsi speaker

This commit is contained in:
Piotr 'pwh' Hanusiak
2022-04-06 14:16:41 +02:00
committed by David Négrier
parent 4bd8be89c1
commit 0cce2a7ab8
3 changed files with 46 additions and 11 deletions
+23
View File
@@ -3,6 +3,8 @@ import { coWebsiteManager } from "./CoWebsiteManager";
import { requestedCameraState, requestedMicrophoneState } from "../Stores/MediaStore";
import { get } from "svelte/store";
import CancelablePromise from "cancelable-promise";
import { gameManager } from "../Phaser/Game/GameManager";
import { userIsJitsiDominantSpeakerStore } from "../Stores/GameStore";
interface jitsiConfigInterface {
startWithAudioMuted: boolean;
@@ -126,6 +128,7 @@ class JitsiFactory {
private jitsiApi?: JitsiApi;
private audioCallback = this.onAudioChange.bind(this);
private videoCallback = this.onVideoChange.bind(this);
private dominantSpeakerChangedCallback = this.onDominantSpeakerChanged.bind(this);
private jitsiScriptLoaded: boolean = false;
/**
@@ -204,6 +207,7 @@ class JitsiFactory {
this.jitsiApi.addListener("audioMuteStatusChanged", this.audioCallback);
this.jitsiApi.addListener("videoMuteStatusChanged", this.videoCallback);
this.jitsiApi.addListener("dominantSpeakerChanged", this.dominantSpeakerChangedCallback);
});
cancel(() => {
@@ -262,6 +266,25 @@ class JitsiFactory {
}
}
private onDominantSpeakerChanged(data: { id: string }): void {
userIsJitsiDominantSpeakerStore.set(
//@ts-ignore
data.id === this.getCurrentParticipantId(this.jitsiApi?.getParticipantsInfo())
);
}
private getCurrentParticipantId(
participants: { displayName: string; participantId: string }[]
): string | undefined {
const currentPlayerName = gameManager.getPlayerName();
for (const participant of participants) {
if (participant.displayName === currentPlayerName) {
return participant.participantId;
}
}
return;
}
private loadJitsiScript(domain: string): CancelablePromise<void> {
return new CancelablePromise<void>((resolve, reject, cancel) => {
if (this.jitsiScriptLoaded) {