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

util.js "reject is not defined" #4

Closed
ivangusev opened this issue Nov 13, 2023 · 9 comments
Closed

util.js "reject is not defined" #4

ivangusev opened this issue Nov 13, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@ivangusev
Copy link

If we pass non-mp3 (jpeg for example) we get "ReferenceError: reject is not defined" in checkRemoteResource()
Also please handle the case of rejected promise in Audio.js load(), otherwise the whole application is crashed without catching the error.
Ideally i should get this error in:

video.on("error", (err) => {
    console.error(err);
});
@Vinlic
Copy link
Owner

Vinlic commented Nov 13, 2023

Oh! Yes, this seems to be a legacy code error that has been corrected and will be fixed on 0.0.21.

@Vinlic Vinlic added the bug Something isn't working label Nov 13, 2023
@Vinlic Vinlic closed this as completed Nov 13, 2023
@ivangusev
Copy link
Author

@Vinlic, thanks for the fix, and what about catching the error?

@Vinlic
Copy link
Owner

Vinlic commented Nov 13, 2023

Now you can listen for errors through the "error" event. :D

@ivangusev
Copy link
Author

@Vinlic , unfortunately i can't confirm. If you just replace reject() with "throw" it's not enough, because in Audio.js load() you return a promise. So you need to handle when it's rejected.

@Vinlic
Copy link
Owner

Vinlic commented Nov 13, 2023

@ivangusev
This rejected promise will eventually be captured by the global asynchronous method in the Synthesizer.start() function and passed through _emitError(err) thrown to your listening callback function.
Synthesizer.js

...
start() {
    ...
    (async () => {
        ...
        await this.#waitForAudiosLoaded();  // Waiting for all audio to load here.
        ...
    })()
    .catch(err => this._emitError(err));  // Will notify you of the error here
}
...

@ivangusev
Copy link
Author

@Vinlic , i think it's not the only place where it's called. I'm adding audio like this:

const video = wvc.createSingleVideo({
    content: content,
    pageWaitForOptions: {
      waitUntil:'networkidle0'
    }
    ...
});
video.on("error", (err) => {
  console.error(err);
});
video.addAudio({
      url: req.body.mp3,
));
await video.startAndWait();

And error is not captured. Synthesizer.start() is not even reached to the time of error.

@Vinlic
Copy link
Owner

Vinlic commented Nov 13, 2023

@ivangusev
I understand now. In the addAudio function, I added audio.load(), which triggers preloading when adding audio. Now I may consider removing it or changing it to audio.load().catch(err => this._emitError(err)) (which will trigger two error events)

@ivangusev
Copy link
Author

@Vinlic , yes, that's what i meant: audio.load().catch(err => this._emitError(err))

@Vinlic
Copy link
Owner

Vinlic commented Nov 13, 2023

@ivangusev
I have made changes and this update will be included in the next release version. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants