Skip to content

Commit f901e7a

Browse files
make setter function more readable
1 parent e1db9ea commit f901e7a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/mediasources.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ function MediaSources() {
200200
return current === SourceType.AUDIO_DESCRIBED
201201
}
202202

203-
function setAudioDescribed(to: boolean): Promise<void> {
204-
current = to ? SourceType.AUDIO_DESCRIBED : SourceType.MEDIA
203+
function setAudioDescribed(enable: boolean): Promise<void> {
204+
current = enable ? SourceType.AUDIO_DESCRIBED : SourceType.MEDIA
205205

206206
updateDebugOutput()
207207

src/playercomponent.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function PlayerComponent(
133133
return genericADAvailable ? genericADEnabled : playbackStrategyProvidedAD()
134134
}
135135

136-
function genericAudioDescribedSwitch(to) {
136+
function genericAudioDescribedSwitch(enable) {
137137
const wasPaused = isPaused()
138138
const presentationTimeInSeconds = getCurrentTime()
139139
const availabilityTimeInMilliseconds = presentationTimeToAvailabilityTimeInMilliseconds(
@@ -142,7 +142,7 @@ function PlayerComponent(
142142
)
143143

144144
return mediaSources
145-
.setAudioDescribed(to)
145+
.setAudioDescribed(enable)
146146
.then(() => {
147147
const presentationTimeInSeconds = availabilityTimeToPresentationTimeInSeconds(
148148
availabilityTimeInMilliseconds,
@@ -155,16 +155,20 @@ function PlayerComponent(
155155
.catch(() => {
156156
bubbleFatalError(false, {
157157
code: "0000",
158-
message: `error switching ${to ? "to" : "from"} audio described`,
158+
message: `error switching ${enable ? "to" : "from"} audio described`,
159159
})
160160
})
161161
}
162162

163-
function setAudioDescribed(to) {
164-
if (mediaSources.isAudioDescribedAvailable()) return genericAudioDescribedSwitch(to)
165-
if (!(playbackStrategy && playbackStrategy.isAudioDescribedAvailable?.())) return Promise.resolve()
163+
function setAudioDescribed(enable) {
164+
if (mediaSources.isAudioDescribedAvailable()) return genericAudioDescribedSwitch(enable)
165+
166+
if (playbackStrategy) {
167+
if (!playbackStrategy.isAudioDescribedAvailable?.()) return Promise.resolve()
168+
169+
enable ? playbackStrategy.setAudioDescribedOn?.() : playbackStrategy.setAudioDescribedOff?.()
170+
}
166171

167-
playbackStrategy && playbackStrategy[to ? "setAudioDescribedOn" : "setAudioDescribedOff"]?.()
168172
return Promise.resolve()
169173
}
170174

0 commit comments

Comments
 (0)