Ensure leave sound does not play

This commit is contained in:
Half-Shot
2025-09-12 15:11:12 +01:00
parent 5536f559a3
commit fadc8c4afd
2 changed files with 27 additions and 13 deletions

View File

@@ -117,7 +117,6 @@ import { Avatar, Size as AvatarSize } from "../Avatar";
import waitingStyles from "./WaitingForJoin.module.css";
import { prefetchSounds } from "../soundUtils";
import { useAudioContext } from "../useAudioContext";
import ringtoneMp3 from "../sound/ringtone.mp3?url";
import ringtoneOgg from "../sound/ringtone.ogg?url";
import declineMp3 from "../sound/call_declined.mp3?url";

View File

@@ -37,6 +37,7 @@ import {
concat,
distinctUntilChanged,
endWith,
every,
filter,
forkJoin,
fromEvent,
@@ -49,6 +50,7 @@ import {
race,
scan,
skip,
skipWhile,
startWith,
switchAll,
switchMap,
@@ -853,17 +855,6 @@ export class CallViewModel extends ViewModel {
throttleTime(THROTTLE_SOUND_EFFECT_MS),
);
public readonly leaveSoundEffect$ = this.userMedia$.pipe(
pairwise(),
filter(
([prev, current]) =>
current.length <= MAX_PARTICIPANT_COUNT_FOR_SOUND &&
current.length < prev.length,
),
map(() => {}),
throttleTime(THROTTLE_SOUND_EFFECT_MS),
);
/**
* The number of participants currently in the call.
*
@@ -963,7 +954,9 @@ export class CallViewModel extends ViewModel {
* - "success": Someone else joined. The call is in a normal state. No audiovisual feedback.
* - null: EC is configured to never show any waiting for answer state.
*/
public readonly callPickupState$ = this.options.waitForCallPickup
public readonly callPickupState$: Behavior<
"unknown" | "ringing" | "timeout" | "decline" | "success" | null
> = this.options.waitForCallPickup
? this.scope.behavior<
"unknown" | "ringing" | "timeout" | "decline" | "success"
>(
@@ -983,6 +976,28 @@ export class CallViewModel extends ViewModel {
)
: constant(null);
public readonly callWasSuccessful$ = this.callPickupState$.pipe(
every((x) => x !== "success"),
map((v) => !v),
);
public readonly leaveSoundEffect$ = combineLatest([
this.callWasSuccessful$,
this.userMedia$,
]).pipe(
// Until the call is successful, do not play a leave sound.
skipWhile(([c]) => c === false),
map(([, userMedia]) => userMedia),
pairwise(),
filter(
([prev, current]) =>
current.length <= MAX_PARTICIPANT_COUNT_FOR_SOUND &&
current.length < prev.length,
),
map(() => {}),
throttleTime(THROTTLE_SOUND_EFFECT_MS),
);
/**
* List of MediaItems that we want to display, that are of type ScreenShare
*/