Return to normal state when time limit reached
This commit is contained in:
@@ -16,6 +16,7 @@ import { Timer } from "./Timer";
|
|||||||
import { Toggle } from "../input/Toggle";
|
import { Toggle } from "../input/Toggle";
|
||||||
import { getAvatarUrl } from "../matrix-utils";
|
import { getAvatarUrl } from "../matrix-utils";
|
||||||
import { ReactComponent as AudioIcon } from "../icons/Audio.svg";
|
import { ReactComponent as AudioIcon } from "../icons/Audio.svg";
|
||||||
|
import { OtherUserSpeakingError } from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
|
|
||||||
export function PTTCallView({
|
export function PTTCallView({
|
||||||
client,
|
client,
|
||||||
@@ -47,21 +48,22 @@ export function PTTCallView({
|
|||||||
activeSpeakerUserId,
|
activeSpeakerUserId,
|
||||||
startTalking,
|
startTalking,
|
||||||
stopTalking,
|
stopTalking,
|
||||||
|
unmuteError,
|
||||||
} = usePTT(client, groupCall, userMediaFeeds);
|
} = usePTT(client, groupCall, userMediaFeeds);
|
||||||
|
|
||||||
|
const showTalkOverError = pttButtonHeld && unmuteError instanceof OtherUserSpeakingError;
|
||||||
|
|
||||||
const activeSpeakerIsLocalUser =
|
const activeSpeakerIsLocalUser =
|
||||||
activeSpeakerUserId && client.getUserId() === activeSpeakerUserId;
|
activeSpeakerUserId && client.getUserId() === activeSpeakerUserId;
|
||||||
const showTalkOverError =
|
|
||||||
pttButtonHeld && !activeSpeakerIsLocalUser && !talkOverEnabled;
|
|
||||||
const activeSpeakerUser = activeSpeakerUserId
|
const activeSpeakerUser = activeSpeakerUserId
|
||||||
? client.getUser(activeSpeakerUserId)
|
? client.getUser(activeSpeakerUserId)
|
||||||
: null;
|
: null;
|
||||||
const activeSpeakerAvatarUrl = activeSpeakerUser
|
const activeSpeakerAvatarUrl = activeSpeakerUser
|
||||||
? getAvatarUrl(
|
? getAvatarUrl(
|
||||||
client,
|
client,
|
||||||
activeSpeakerUser.avatarUrl,
|
activeSpeakerUser.avatarUrl,
|
||||||
pttButtonSize - pttBorderWidth * 2
|
pttButtonSize - pttBorderWidth * 2
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
const activeSpeakerDisplayName = activeSpeakerUser
|
const activeSpeakerDisplayName = activeSpeakerUser
|
||||||
? activeSpeakerUser.displayName
|
? activeSpeakerUser.displayName
|
||||||
@@ -77,9 +79,8 @@ export function PTTCallView({
|
|||||||
</Header>
|
</Header>
|
||||||
<div className={styles.center}>
|
<div className={styles.center}>
|
||||||
<div className={styles.participants}>
|
<div className={styles.participants}>
|
||||||
<p>{`${participants.length} ${
|
<p>{`${participants.length} ${participants.length > 1 ? "people" : "person"
|
||||||
participants.length > 1 ? "people" : "person"
|
} connected`}</p>
|
||||||
} connected`}</p>
|
|
||||||
<Facepile
|
<Facepile
|
||||||
size={facepileSize}
|
size={facepileSize}
|
||||||
max={8}
|
max={8}
|
||||||
@@ -123,13 +124,13 @@ export function PTTCallView({
|
|||||||
<p className={styles.actionTip}>
|
<p className={styles.actionTip}>
|
||||||
{showTalkOverError
|
{showTalkOverError
|
||||||
? "You can't talk at the same time"
|
? "You can't talk at the same time"
|
||||||
: pttButtonHeld
|
: pttButtonHeld && activeSpeakerIsLocalUser
|
||||||
? "Release spacebar key to stop"
|
? "Release spacebar key to stop"
|
||||||
: talkOverEnabled &&
|
: talkOverEnabled &&
|
||||||
activeSpeakerUserId &&
|
activeSpeakerUserId &&
|
||||||
!activeSpeakerIsLocalUser
|
!activeSpeakerIsLocalUser
|
||||||
? `Press and hold spacebar to talk over ${activeSpeakerDisplayName}`
|
? `Press and hold spacebar to talk over ${activeSpeakerDisplayName}`
|
||||||
: "Press and hold spacebar to talk"}
|
: "Press and hold spacebar to talk"}
|
||||||
</p>
|
</p>
|
||||||
{userMediaFeeds.map((callFeed) => (
|
{userMediaFeeds.map((callFeed) => (
|
||||||
<PTTFeed
|
<PTTFeed
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ export function usePTT(client, groupCall, userMediaFeeds) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [unmuteError, setUnmuteError] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onMuteStateChanged(...args) {
|
function onMuteStateChanged(...args) {
|
||||||
const activeSpeakerFeed = userMediaFeeds.find((f) => !f.isAudioMuted());
|
const activeSpeakerFeed = userMediaFeeds.find((f) => !f.isAudioMuted());
|
||||||
@@ -47,22 +49,26 @@ export function usePTT(client, groupCall, userMediaFeeds) {
|
|||||||
};
|
};
|
||||||
}, [userMediaFeeds]);
|
}, [userMediaFeeds]);
|
||||||
|
|
||||||
const startTalking = useCallback(() => {
|
const startTalking = useCallback(async () => {
|
||||||
|
setState((prevState) => ({ ...prevState, pttButtonHeld: true }));
|
||||||
|
setUnmuteError(null);
|
||||||
if (!activeSpeakerUserId || isAdmin || talkOverEnabled) {
|
if (!activeSpeakerUserId || isAdmin || talkOverEnabled) {
|
||||||
if (groupCall.isMicrophoneMuted()) {
|
if (groupCall.isMicrophoneMuted()) {
|
||||||
groupCall.setMicrophoneMuted(false);
|
try {
|
||||||
|
await groupCall.setMicrophoneMuted(false);
|
||||||
|
} catch (e) {
|
||||||
|
setUnmuteError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setState((prevState) => ({ ...prevState, pttButtonHeld: true }));
|
|
||||||
}
|
}
|
||||||
}, []);
|
}, [setUnmuteError]);
|
||||||
|
|
||||||
const stopTalking = useCallback(() => {
|
const stopTalking = useCallback(() => {
|
||||||
|
setState((prevState) => ({ ...prevState, pttButtonHeld: false }));
|
||||||
|
|
||||||
if (!groupCall.isMicrophoneMuted()) {
|
if (!groupCall.isMicrophoneMuted()) {
|
||||||
groupCall.setMicrophoneMuted(true);
|
groupCall.setMicrophoneMuted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState((prevState) => ({ ...prevState, pttButtonHeld: false }));
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -70,6 +76,8 @@ export function usePTT(client, groupCall, userMediaFeeds) {
|
|||||||
if (event.code === "Space") {
|
if (event.code === "Space") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (pttButtonHeld) return;
|
||||||
|
|
||||||
startTalking();
|
startTalking();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +108,7 @@ export function usePTT(client, groupCall, userMediaFeeds) {
|
|||||||
window.removeEventListener("keyup", onKeyUp);
|
window.removeEventListener("keyup", onKeyUp);
|
||||||
window.removeEventListener("blur", onBlur);
|
window.removeEventListener("blur", onBlur);
|
||||||
};
|
};
|
||||||
}, [activeSpeakerUserId, isAdmin, talkOverEnabled]);
|
}, [activeSpeakerUserId, isAdmin, talkOverEnabled, pttButtonHeld]);
|
||||||
|
|
||||||
const setTalkOverEnabled = useCallback((talkOverEnabled) => {
|
const setTalkOverEnabled = useCallback((talkOverEnabled) => {
|
||||||
setState((prevState) => ({
|
setState((prevState) => ({
|
||||||
@@ -117,5 +125,6 @@ export function usePTT(client, groupCall, userMediaFeeds) {
|
|||||||
activeSpeakerUserId,
|
activeSpeakerUserId,
|
||||||
startTalking,
|
startTalking,
|
||||||
stopTalking,
|
stopTalking,
|
||||||
|
unmuteError,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user