diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8799b133d..aabd35774 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: - name: Extract version id: version run: | - OLD_VERSION=$(npm show wavesurfer.js version) + OLD_VERSION=$(npm show . version) NEW_VERSION=$(node -p 'require("./package.json").version') if [ $NEW_VERSION != $OLD_VERSION ]; then echo "New version $NEW_VERSION detected" @@ -55,9 +55,8 @@ jobs: node-version: '16.x' registry-url: 'https://registry.npmjs.org' - - name: Install dependencies + - uses: ./.github/workflows/yarn if: ${{ steps.version.outputs.version }} - run: npm install --legacy-peer-deps - name: Publish to NPM if: ${{ steps.version.outputs.version }} diff --git a/package.json b/package.json index f432e1ec6..c888c0d8c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "7.6.0", "license": "BSD-3-Clause", "author": "katspaugh", - "description": "Navigable audio waveform player", + "description": "Audio waveform player", "homepage": "https://wavesurfer.xyz", "keywords": [ "waveform", @@ -15,7 +15,7 @@ ], "repository": { "type": "git", - "url": "git@github.com:wavesurfer-js/wavesurfer.js.git" + "url": "git@github.com:katspaugh/wavesurfer.js.git" }, "type": "module", "files": [ diff --git a/rollup.config.js b/rollup.config.js index 66b725797..83822a2dc 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -13,7 +13,7 @@ export default [ file: 'dist/wavesurfer.esm.js', format: 'esm', }, - plugins: [typescript(), terser()], + plugins, }, // CommonJS module (Node.js) { diff --git a/src/wavesurfer.ts b/src/wavesurfer.ts index 6e660f05d..83239b5c7 100644 --- a/src/wavesurfer.ts +++ b/src/wavesurfer.ts @@ -89,6 +89,8 @@ const defaultOptions = { } export type WaveSurferEvents = { + /** After wavesurfer is created */ + init: [] /** When audio starts loading */ load: [url: string] /** During audio loading */ @@ -165,12 +167,17 @@ class WaveSurfer extends Player { this.initTimerEvents() this.initPlugins() - // Load audio if URL or an external media with an src is passed, - // of render w/o audio if pre-decoded peaks and duration are provided - const url = this.options.url || this.getSrc() || '' - if (url || (this.options.peaks && this.options.duration)) { - this.load(url, this.options.peaks, this.options.duration) - } + // Init and load async to allow external events to be registered + Promise.resolve().then(() => { + this.emit('init') + + // Load audio if URL or an external media with an src is passed, + // of render w/o audio if pre-decoded peaks and duration are provided + const url = this.options.url || this.getSrc() || '' + if (url || (this.options.peaks && this.options.duration)) { + this.load(url, this.options.peaks, this.options.duration) + } + }) } private initTimerEvents() { @@ -349,9 +356,9 @@ class WaveSurfer extends Player { this.setSrc(url, blob) // Wait for the audio duration - // It should be a promise to allow event listeners to subscribe to the ready and decode events const audioDuration = - (await Promise.resolve(duration || this.getDuration())) || + duration || + this.getDuration() || (await new Promise((resolve) => { this.onceMediaEvent('loadedmetadata', () => resolve(this.getDuration())) }))