I can paste in some %raw
js, but curious if there’s a way to do this without resorting to that:
type audioContext
let createAudioContext: unit => option<audioContext> = () => {
let audioContext = %raw(`typeof AudioContext !== "undefined" ? AudioContext :
typeof webkitAudioContext !== "undefined" ? webkitAudioContext :
typeof mozAudioContext !== "undefined" ? mozAudioContext : null`)
let instance = %raw(`function (AudioContext) { return !!AudioContext ? new AudioContext() : null}`)(
audioContext,
)
instance
}
I need to use new
to instantiate the class, but I don’t know the exact name ahead of time, and I can’t rely on any of them being there (assuming e.g. SSR).