Skip to content

Commit

Permalink
Only trigger AudioPlaybackFailed when it's NotAllowed (#615)
Browse files Browse the repository at this point in the history
Other errors could be raised when playing back an audio track.
For example: a user could attach to another track, aborting the current
attempt.

In those cases, we do not want to fire AudioPlaybackFailed incorrectly.
  • Loading branch information
davidzhao committed Mar 10, 2023
1 parent 347c497 commit 505a78e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/ten-timers-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Only trigger AudioPlaybackFailed when error is NotAllowed
7 changes: 6 additions & 1 deletion src/room/track/Track.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventEmitter } from 'events';
import type TypedEventEmitter from 'typed-emitter';
import type { SignalClient } from '../../api/SignalClient';
import log from '../../logger';
import { TrackSource, TrackType } from '../../proto/livekit_models';
import { StreamState as ProtoStreamState } from '../../proto/livekit_rtc';
import { TrackEvent } from '../events';
Expand Down Expand Up @@ -132,7 +133,11 @@ export abstract class Track extends (EventEmitter as new () => TypedEventEmitter
this.emit(TrackEvent.AudioPlaybackStarted);
})
.catch((e) => {
this.emit(TrackEvent.AudioPlaybackFailed, e);
if (e.name === 'NotAllowedError') {
this.emit(TrackEvent.AudioPlaybackFailed, e);
} else {
log.warn('could not playback audio', e);
}
// If audio playback isn't allowed make sure we still play back the video
if (
element &&
Expand Down

0 comments on commit 505a78e

Please sign in to comment.