-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix #133 #136
Fix #133 #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,24 +82,26 @@ module.exports = function patchOfflineAudioContext(jsExport, nativeBinding) { | |
|
||
// Add function to Napi object to bridge from Rust events to JS EventTarget | ||
// They will be effectively registered on rust side when `startRendering` is called | ||
this[kNapiObj][kOnStateChange] = (function(err, rawEvent) { | ||
this[kNapiObj][kOnStateChange] = (function(_err, rawEvent) { | ||
const event = new Event(rawEvent.type); | ||
propagateEvent(this, event); | ||
}).bind(this); | ||
|
||
// This event is, per spec, the last trigerred one | ||
this[kNapiObj][kOnComplete] = (function(err, rawEvent) { | ||
// workaround the fact that this event seems to be triggered before | ||
// workaround the fact that the oncomplete event is triggered before | ||
// startRendering fulfills and that we want to return the exact same instance | ||
if (this.#renderedBuffer === null) { | ||
this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: rawEvent.renderedBuffer }); | ||
} | ||
this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: rawEvent.renderedBuffer }); | ||
|
||
const event = new jsExport.OfflineAudioCompletionEvent(rawEvent.type, { | ||
renderedBuffer: this.#renderedBuffer, | ||
}); | ||
|
||
propagateEvent(this, event); | ||
// delay event propagation to next tick that it is executed after startRendering fulfills | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup thanks, sure I have been misleaded by mdn which marks it deprecated but it doesn't stand in node context |
||
propagateEvent(this, event); | ||
this.#renderedBuffer = null; | ||
}, 0); | ||
}).bind(this); | ||
} | ||
|
||
|
@@ -145,15 +147,9 @@ module.exports = function patchOfflineAudioContext(jsExport, nativeBinding) { | |
throwSanitizedError(err); | ||
} | ||
|
||
// release audio worklet, if any | ||
// release audio worklets | ||
await this.audioWorklet[kWorkletRelease](); | ||
|
||
// workaround the fact that this event seems to be triggered before | ||
// startRendering fulfills and that we want to return the exact same instance | ||
if (this.#renderedBuffer === null) { | ||
this.#renderedBuffer = new jsExport.AudioBuffer({ [kNapiObj]: nativeAudioBuffer }); | ||
} | ||
|
||
return this.#renderedBuffer; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh, I think this is a napi issue causing false positive in clippy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup I agree, let's see if the problem disappear in a future napi-rs release, I opened an issue to not forget that
cf. #137