diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index c76c43f829..1fd5e2f149 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -80,9 +80,6 @@ declare global { mxMatrixClientPeg: IMatrixClientPeg; mxReactSdkConfig: DeepReadonly; - // Needed for Safari, unknown to TypeScript - webkitAudioContext: typeof AudioContext; - // https://docs.microsoft.com/en-us/previous-versions/hh772328(v=vs.85) // we only ever check for its existence, so we can ignore its actual type MSStream?: unknown; diff --git a/src/audio/Playback.ts b/src/audio/Playback.ts index af777a8c01..fef1b9c1dc 100644 --- a/src/audio/Playback.ts +++ b/src/audio/Playback.ts @@ -164,36 +164,21 @@ export class Playback extends EventEmitter implements IDestroyable, PlaybackInte this.element.src = URL.createObjectURL(new Blob([this.buf])); await deferred.promise; // make sure the audio element is ready for us } else { - // Safari compat: promise API not supported on this function - this.audioBuf = await new Promise((resolve, reject) => { - this.context.decodeAudioData( - this.buf, - (b) => resolve(b), - async (e): Promise => { - try { - // This error handler is largely for Safari as well, which doesn't support Opus/Ogg - // very well. - logger.error("Error decoding recording: ", e); - logger.warn("Trying to re-encode to WAV instead..."); + try { + this.audioBuf = await this.context.decodeAudioData(this.buf); + } catch (e) { + logger.error("Error decoding recording:", e); + logger.warn("Trying to re-encode to WAV instead..."); - const wav = await decodeOgg(this.buf); - - // noinspection ES6MissingAwait - not needed when using callbacks - this.context.decodeAudioData( - wav, - (b) => resolve(b), - (e) => { - logger.error("Still failed to decode recording: ", e); - reject(e); - }, - ); - } catch (e) { - logger.error("Caught decoding error:", e); - reject(e); - } - }, - ); - }); + try { + // This error handler is largely for Safari, which doesn't support Opus/Ogg very well. + const wav = await decodeOgg(this.buf); + this.audioBuf = await this.context.decodeAudioData(wav); + } catch (e) { + logger.error("Error decoding recording:", e); + throw e; + } + } // Update the waveform to the real waveform once we have channel data to use. We don't // exactly trust the user-provided waveform to be accurate... diff --git a/src/audio/compat.ts b/src/audio/compat.ts index 7af6ef68b2..099c614c98 100644 --- a/src/audio/compat.ts +++ b/src/audio/compat.ts @@ -17,11 +17,6 @@ import { SAMPLE_RATE } from "./VoiceRecording"; export function createAudioContext(opts?: AudioContextOptions): AudioContext { if (window.AudioContext) { return new AudioContext(opts); - } else if (window.webkitAudioContext) { - // While the linter is correct that "a constructor name should not start with - // a lowercase letter", it's also wrong to think that we have control over this. - // eslint-disable-next-line new-cap - return new window.webkitAudioContext(opts); } else { throw new Error("Unsupported browser"); }