-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
CanvasRenderingContext2D.prototype.drawImage is now asynchronous #676
Comments
render.save is async, i dont see how i can make it sync unfortunately. |
Sorry, I’m not asking for it to be made sync. It would just be nice if it returned a promise that resolved when it was done. That way I would be able to do something when the operation is complete, instead of relying on an arbitrary timeout. |
The following is a little example of how you could return a promise if (arg instanceof HTMLVideoElement && arg.render) {
return new Promise<void>((resolve, reject) => {
...[Removing code for clarity]...
// Reject the promise if it doesn't complete in some amount of time.
setTimeout(() => {
reject(new Error('Draw image timed out!'))
}, 500)
arg.render.save(function (data) {
var onLoad = function () {
img.removeEventListener('load', onLoad);
drawImage.apply(context, args);
URL.revokeObjectURL(temp);
// Resolve the promise once the operation is complete.
resolve();
};
img.addEventListener('load', onLoad);
img.setAttribute('src', temp);
});
});
} else { Then, it makes something like this possible await ctx.drawImage(this._video, 0, 0, this._video.videoWidth, this._video.videoHeight);
const data = ctx.getImageData(0, 0, 3, 3).data;
console.log('This is data that was just drawn to the canvas!', data) Otherwise, you have to use an arbitrary setTimeout to call |
No problem with promise, will do and keep you posted. |
PR would be welcome @NAllred91 |
YOU MUST read first!
Please use Community Forum for general technical discussions and questions.
extra/renderer-and-libwebrtc-tests.js
file).Note: If the checkboxes above are not checked (which you do after the issue is posted), the issue will be closed, removing this checkbox will result in automatic closed issue.
Versions affected
Description
The following patch of CanvasRenderingContext2D.prototype.drawImage has made
drawImage
asynchronous. This presents a problem when you want to callgetImageData
immediately afterdrawImage
. Using a setTimeout to callgetImageData
will kind of work, but it might be better ifdrawImage
returned a promise after it has been patched?Referenced comment
6.0.15 support CanvasRenderingContext2D.drawImage on VideoElement with iosrtc MediaStream
03e4a0d
Originally posted by @hthetiot in #116 (comment)
The text was updated successfully, but these errors were encountered: