Files
jitsi-meet/react/features/face-landmarks/createImageBitmap.js
Saúl Ibarra Corretgé ef748c576d fix(face-landmarks) fix createImageBitMap polyfill on Safari 14
The polyfill returns an Image object instead of an ImageBitmap. The
latter has a close method, however, which we call.

Make sure we provide a dummy close method to avoid errors.
2022-08-08 17:03:48 +02:00

29 lines
887 B
JavaScript

/*
* Safari < 15 polyfill for createImageBitmap
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap
*
* Support source image types: Canvas.
*/
if (!('createImageBitmap' in window)) {
window.createImageBitmap = async function(data) {
return new Promise((resolve, reject) => {
let dataURL;
if (data instanceof HTMLCanvasElement) {
dataURL = data.toDataURL();
} else {
reject(new Error('createImageBitmap does not handle the provided image source type'));
}
const img = document.createElement('img');
// eslint-disable-next-line no-empty-function
img.close = () => {};
img.addEventListener('load', () => {
resolve(img);
});
img.src = dataURL;
});
};
}