Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/audio: fix AudioOptions #4884

Merged
merged 1 commit into from
Jan 23, 2024
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
4 changes: 2 additions & 2 deletions packages/@uppy/audio/src/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

interface AudioOptions extends UIPluginOptions {
target?: HTMLElement | string
showAudioSourceDropdown: boolean
showAudioSourceDropdown?: boolean
}
interface AudioState {
audioReady: boolean
Expand Down Expand Up @@ -58,7 +58,7 @@

#supportsUserMedia

constructor(uppy: Uppy<M, B>, opts: AudioOptions) {
constructor(uppy: Uppy<M, B>, opts?: AudioOptions) {
super(uppy, opts)
this.#mediaDevices = navigator.mediaDevices
this.#supportsUserMedia = this.#mediaDevices != null
Expand Down Expand Up @@ -159,26 +159,26 @@
#startRecording = (): void => {
// only used if supportsMediaRecorder() returned true
// eslint-disable-next-line compat/compat
this.#recorder = new MediaRecorder(this.#stream!)

Check warning on line 162 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
this.#recordingChunks = []
let stoppingBecauseOfMaxSize = false
this.#recorder.addEventListener('dataavailable', (event) => {
this.#recordingChunks!.push(event.data)

Check warning on line 166 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion

const { restrictions } = this.uppy.opts
if (
this.#recordingChunks!.length > 1 &&

Check warning on line 170 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
restrictions.maxFileSize != null &&
!stoppingBecauseOfMaxSize
) {
const totalSize = this.#recordingChunks!.reduce(

Check warning on line 174 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
(acc, chunk) => acc + chunk.size,
0,
)
// Exclude the initial chunk from the average size calculation because it is likely to be a very small outlier
const averageChunkSize =
(totalSize - this.#recordingChunks![0].size) /

Check warning on line 180 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
(this.#recordingChunks!.length - 1)

Check warning on line 181 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
const expectedEndChunkSize = averageChunkSize * 3
const maxSize = Math.max(
0,
Expand Down Expand Up @@ -214,10 +214,10 @@

#stopRecording = (): Promise<void> => {
const stopped = new Promise<void>((resolve) => {
this.#recorder!.addEventListener('stop', () => {

Check warning on line 217 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
resolve()
})
this.#recorder!.stop()

Check warning on line 220 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion

clearInterval(this.recordingLengthTimer)
this.setPluginState({ recordingLengthSeconds: 0 })
Expand Down Expand Up @@ -283,8 +283,8 @@

if (this.#recorder) {
await new Promise((resolve) => {
this.#recorder!.addEventListener('stop', resolve, { once: true })

Check warning on line 286 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion
this.#recorder!.stop()

Check warning on line 287 in packages/@uppy/audio/src/Audio.tsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Forbidden non-null assertion

clearInterval(this.recordingLengthTimer)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/audio/src/RecordingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface RecordingScreenProps extends AudioSourceSelectProps {
recordedAudio: string
recording: boolean
supportsRecording: boolean
showAudioSourceDropdown: boolean
showAudioSourceDropdown: boolean | undefined
onSubmit: () => void
i18n: I18n
onStartRecording: () => void
Expand Down