Merge pull request #327 from vector-im/dbkr/end_talk_sound
Add sound when speaker stops speaking
This commit is contained in:
commit
c13040f0b0
8 changed files with 31 additions and 11 deletions
|
@ -109,8 +109,13 @@ export const PTTCallView: React.FC<Props> = ({
|
||||||
|
|
||||||
const { audioOutput } = useMediaHandler();
|
const { audioOutput } = useMediaHandler();
|
||||||
|
|
||||||
const { startTalkingLocalRef, startTalkingRemoteRef, blockedRef, playClip } =
|
const {
|
||||||
usePTTSounds();
|
startTalkingLocalRef,
|
||||||
|
startTalkingRemoteRef,
|
||||||
|
blockedRef,
|
||||||
|
endTalkingRef,
|
||||||
|
playClip,
|
||||||
|
} = usePTTSounds();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
pttButtonHeld,
|
pttButtonHeld,
|
||||||
|
@ -146,6 +151,7 @@ export const PTTCallView: React.FC<Props> = ({
|
||||||
<PTTClips
|
<PTTClips
|
||||||
startTalkingLocalRef={startTalkingLocalRef}
|
startTalkingLocalRef={startTalkingLocalRef}
|
||||||
startTalkingRemoteRef={startTalkingRemoteRef}
|
startTalkingRemoteRef={startTalkingRemoteRef}
|
||||||
|
endTalkingRef={endTalkingRef}
|
||||||
blockedRef={blockedRef}
|
blockedRef={blockedRef}
|
||||||
/>
|
/>
|
||||||
<Header className={styles.header}>
|
<Header className={styles.header}>
|
||||||
|
|
|
@ -27,17 +27,14 @@ import { PlayClipFunction, PTTClipID } from "../sound/usePttSounds";
|
||||||
function getActiveSpeakerFeed(
|
function getActiveSpeakerFeed(
|
||||||
feeds: CallFeed[],
|
feeds: CallFeed[],
|
||||||
groupCall: GroupCall
|
groupCall: GroupCall
|
||||||
): CallFeed {
|
): CallFeed | null {
|
||||||
const activeSpeakerFeeds = feeds.filter((f) => !f.isAudioMuted());
|
const activeSpeakerFeeds = feeds.filter((f) => !f.isAudioMuted());
|
||||||
|
|
||||||
let activeSpeakerFeed;
|
let activeSpeakerFeed = null;
|
||||||
let highestPowerLevel;
|
let highestPowerLevel = null;
|
||||||
for (const feed of activeSpeakerFeeds) {
|
for (const feed of activeSpeakerFeeds) {
|
||||||
const member = groupCall.room.getMember(feed.userId);
|
const member = groupCall.room.getMember(feed.userId);
|
||||||
if (
|
if (highestPowerLevel === null || member.powerLevel > highestPowerLevel) {
|
||||||
highestPowerLevel === undefined ||
|
|
||||||
member.powerLevel > highestPowerLevel
|
|
||||||
) {
|
|
||||||
highestPowerLevel = member.powerLevel;
|
highestPowerLevel = member.powerLevel;
|
||||||
activeSpeakerFeed = feed;
|
activeSpeakerFeed = feed;
|
||||||
}
|
}
|
||||||
|
@ -110,12 +107,14 @@ export const usePTT = (
|
||||||
const activeSpeakerFeed = getActiveSpeakerFeed(userMediaFeeds, groupCall);
|
const activeSpeakerFeed = getActiveSpeakerFeed(userMediaFeeds, groupCall);
|
||||||
|
|
||||||
let blocked = false;
|
let blocked = false;
|
||||||
if (activeSpeakerUserId === null && activeSpeakerFeed.userId !== null) {
|
if (activeSpeakerUserId === null && activeSpeakerFeed !== null) {
|
||||||
if (activeSpeakerFeed.userId === client.getUserId()) {
|
if (activeSpeakerFeed.userId === client.getUserId()) {
|
||||||
playClip(PTTClipID.START_TALKING_LOCAL);
|
playClip(PTTClipID.START_TALKING_LOCAL);
|
||||||
} else {
|
} else {
|
||||||
playClip(PTTClipID.START_TALKING_REMOTE);
|
playClip(PTTClipID.START_TALKING_REMOTE);
|
||||||
}
|
}
|
||||||
|
} else if (activeSpeakerUserId !== null && activeSpeakerFeed === null) {
|
||||||
|
playClip(PTTClipID.END_TALKING);
|
||||||
} else if (
|
} else if (
|
||||||
pttButtonHeld &&
|
pttButtonHeld &&
|
||||||
activeSpeakerUserId === client.getUserId() &&
|
activeSpeakerUserId === client.getUserId() &&
|
||||||
|
|
|
@ -20,6 +20,8 @@ import startTalkLocalOggUrl from "./start_talk_local.ogg";
|
||||||
import startTalkLocalMp3Url from "./start_talk_local.mp3";
|
import startTalkLocalMp3Url from "./start_talk_local.mp3";
|
||||||
import startTalkRemoteOggUrl from "./start_talk_remote.ogg";
|
import startTalkRemoteOggUrl from "./start_talk_remote.ogg";
|
||||||
import startTalkRemoteMp3Url from "./start_talk_remote.mp3";
|
import startTalkRemoteMp3Url from "./start_talk_remote.mp3";
|
||||||
|
import endTalkOggUrl from "./end_talk.ogg";
|
||||||
|
import endTalkMp3Url from "./end_talk.mp3";
|
||||||
import blockedOggUrl from "./blocked.ogg";
|
import blockedOggUrl from "./blocked.ogg";
|
||||||
import blockedMp3Url from "./blocked.mp3";
|
import blockedMp3Url from "./blocked.mp3";
|
||||||
import styles from "./PTTClips.module.css";
|
import styles from "./PTTClips.module.css";
|
||||||
|
@ -27,12 +29,14 @@ import styles from "./PTTClips.module.css";
|
||||||
interface Props {
|
interface Props {
|
||||||
startTalkingLocalRef: React.RefObject<HTMLAudioElement>;
|
startTalkingLocalRef: React.RefObject<HTMLAudioElement>;
|
||||||
startTalkingRemoteRef: React.RefObject<HTMLAudioElement>;
|
startTalkingRemoteRef: React.RefObject<HTMLAudioElement>;
|
||||||
|
endTalkingRef: React.RefObject<HTMLAudioElement>;
|
||||||
blockedRef: React.RefObject<HTMLAudioElement>;
|
blockedRef: React.RefObject<HTMLAudioElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PTTClips: React.FC<Props> = ({
|
export const PTTClips: React.FC<Props> = ({
|
||||||
startTalkingLocalRef,
|
startTalkingLocalRef,
|
||||||
startTalkingRemoteRef,
|
startTalkingRemoteRef,
|
||||||
|
endTalkingRef,
|
||||||
blockedRef,
|
blockedRef,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
|
@ -53,6 +57,10 @@ export const PTTClips: React.FC<Props> = ({
|
||||||
<source type="audio/ogg" src={startTalkRemoteOggUrl} />
|
<source type="audio/ogg" src={startTalkRemoteOggUrl} />
|
||||||
<source type="audio/mpeg" src={startTalkRemoteMp3Url} />
|
<source type="audio/mpeg" src={startTalkRemoteMp3Url} />
|
||||||
</audio>
|
</audio>
|
||||||
|
<audio preload="true" className={styles.pttClip} ref={endTalkingRef}>
|
||||||
|
<source type="audio/ogg" src={endTalkOggUrl} />
|
||||||
|
<source type="audio/mpeg" src={endTalkMp3Url} />
|
||||||
|
</audio>
|
||||||
<audio preload="true" className={styles.pttClip} ref={blockedRef}>
|
<audio preload="true" className={styles.pttClip} ref={blockedRef}>
|
||||||
<source type="audio/ogg" src={blockedOggUrl} />
|
<source type="audio/ogg" src={blockedOggUrl} />
|
||||||
<source type="audio/mpeg" src={blockedMp3Url} />
|
<source type="audio/mpeg" src={blockedMp3Url} />
|
||||||
|
|
Binary file not shown.
Binary file not shown.
BIN
src/sound/end_talk.mp3
Normal file
BIN
src/sound/end_talk.mp3
Normal file
Binary file not shown.
BIN
src/sound/end_talk.ogg
Normal file
BIN
src/sound/end_talk.ogg
Normal file
Binary file not shown.
|
@ -19,6 +19,7 @@ import React, { useCallback, useState } from "react";
|
||||||
export enum PTTClipID {
|
export enum PTTClipID {
|
||||||
START_TALKING_LOCAL,
|
START_TALKING_LOCAL,
|
||||||
START_TALKING_REMOTE,
|
START_TALKING_REMOTE,
|
||||||
|
END_TALKING,
|
||||||
BLOCKED,
|
BLOCKED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ export type PlayClipFunction = (clipID: PTTClipID) => void;
|
||||||
interface PTTSounds {
|
interface PTTSounds {
|
||||||
startTalkingLocalRef: React.RefObject<HTMLAudioElement>;
|
startTalkingLocalRef: React.RefObject<HTMLAudioElement>;
|
||||||
startTalkingRemoteRef: React.RefObject<HTMLAudioElement>;
|
startTalkingRemoteRef: React.RefObject<HTMLAudioElement>;
|
||||||
|
endTalkingRef: React.RefObject<HTMLAudioElement>;
|
||||||
blockedRef: React.RefObject<HTMLAudioElement>;
|
blockedRef: React.RefObject<HTMLAudioElement>;
|
||||||
playClip: PlayClipFunction;
|
playClip: PlayClipFunction;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,7 @@ interface PTTSounds {
|
||||||
export const usePTTSounds = (): PTTSounds => {
|
export const usePTTSounds = (): PTTSounds => {
|
||||||
const [startTalkingLocalRef] = useState(React.createRef<HTMLAudioElement>());
|
const [startTalkingLocalRef] = useState(React.createRef<HTMLAudioElement>());
|
||||||
const [startTalkingRemoteRef] = useState(React.createRef<HTMLAudioElement>());
|
const [startTalkingRemoteRef] = useState(React.createRef<HTMLAudioElement>());
|
||||||
|
const [endTalkingRef] = useState(React.createRef<HTMLAudioElement>());
|
||||||
const [blockedRef] = useState(React.createRef<HTMLAudioElement>());
|
const [blockedRef] = useState(React.createRef<HTMLAudioElement>());
|
||||||
|
|
||||||
const playClip = useCallback(
|
const playClip = useCallback(
|
||||||
|
@ -47,6 +50,9 @@ export const usePTTSounds = (): PTTSounds => {
|
||||||
case PTTClipID.START_TALKING_REMOTE:
|
case PTTClipID.START_TALKING_REMOTE:
|
||||||
ref = startTalkingRemoteRef;
|
ref = startTalkingRemoteRef;
|
||||||
break;
|
break;
|
||||||
|
case PTTClipID.END_TALKING:
|
||||||
|
ref = endTalkingRef;
|
||||||
|
break;
|
||||||
case PTTClipID.BLOCKED:
|
case PTTClipID.BLOCKED:
|
||||||
ref = blockedRef;
|
ref = blockedRef;
|
||||||
break;
|
break;
|
||||||
|
@ -58,12 +64,13 @@ export const usePTTSounds = (): PTTSounds => {
|
||||||
console.log("No media element found");
|
console.log("No media element found");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[startTalkingLocalRef, startTalkingRemoteRef, blockedRef]
|
[startTalkingLocalRef, startTalkingRemoteRef, endTalkingRef, blockedRef]
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startTalkingLocalRef,
|
startTalkingLocalRef,
|
||||||
startTalkingRemoteRef,
|
startTalkingRemoteRef,
|
||||||
|
endTalkingRef,
|
||||||
blockedRef,
|
blockedRef,
|
||||||
playClip,
|
playClip,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue