Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/client/src/helpers/AudioBindingsWatchdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CallingState, CallState } from '../store';
import { createSubscription } from '../store/rxUtils';
import { videoLoggerSystem } from '../logger';
import { Tracer } from '../stats';
import { TrackType } from '../gen/video/sfu/models/models';

const toBindingKey = (
sessionId: string,
Expand Down Expand Up @@ -91,12 +92,23 @@ export class AudioBindingsWatchdog {
const danglingUserIds: string[] = [];
for (const p of this.state.participants) {
if (p.isLocalParticipant) continue;
const { audioStream, screenShareAudioStream, sessionId, userId } = p;
if (audioStream && !this.bindings.has(toBindingKey(sessionId))) {
const {
audioStream,
screenShareAudioStream,
sessionId,
userId,
publishedTracks,
} = p;
if (
audioStream &&
publishedTracks.includes(TrackType.AUDIO) &&
!this.bindings.has(toBindingKey(sessionId))
) {
danglingUserIds.push(userId);
}
if (
screenShareAudioStream &&
publishedTracks.includes(TrackType.SCREEN_SHARE_AUDIO) &&
!this.bindings.has(toBindingKey(sessionId, 'screenShareAudioTrack'))
) {
danglingUserIds.push(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { StreamClient } from '../../coordinator/connection/client';
import { CallingState, StreamVideoWriteableStateStore } from '../../store';
import { noopComparator } from '../../sorting';
import { fromPartial } from '@total-typescript/shoehorn';
import { TrackType } from '../../gen/video/sfu/models/models';

describe('AudioBindingsWatchdog', () => {
let watchdog: AudioBindingsWatchdog;
Expand Down Expand Up @@ -44,12 +45,17 @@ describe('AudioBindingsWatchdog', () => {
screenShareAudioStream?: MediaStream;
},
) => {
const publishedTracks = [];
if (streams?.audioStream) publishedTracks.push(TrackType.AUDIO);
if (streams?.screenShareAudioStream) {
publishedTracks.push(TrackType.SCREEN_SHARE_AUDIO);
}
call.state.updateOrAddParticipant(
sessionId,
fromPartial({
userId,
sessionId,
publishedTracks: [],
publishedTracks,
...streams,
}),
);
Expand Down Expand Up @@ -233,6 +239,26 @@ describe('AudioBindingsWatchdog', () => {
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('user-1'));
});

it('should not warn when audioStream exists but audio is not published', () => {
// @ts-expect-error private property
const warnSpy = vi.spyOn(watchdog.logger, 'warn');

call.state.updateOrAddParticipant(
'session-1',
fromPartial({
userId: 'user-1',
sessionId: 'session-1',
publishedTracks: [],
audioStream: new MediaStream(),
}),
);

call.state.setCallingState(CallingState.JOINED);
vi.advanceTimersByTime(3000);

expect(warnSpy).not.toHaveBeenCalled();
});

it('should not warn when screenShareAudio element is bound', () => {
// @ts-expect-error private property
const warnSpy = vi.spyOn(watchdog.logger, 'warn');
Expand Down
Loading