Files
jitsi-meet/react/features/base/participants/preloadImage.web.js

25 lines
522 B
JavaScript
Raw Normal View History

2019-06-26 16:08:23 +02:00
// @flow
2019-07-16 11:23:01 +01:00
import { isIconUrl } from './functions';
2019-06-26 16:08:23 +02:00
/**
* Tries to preload an image.
*
2019-08-30 18:39:06 +02:00
* @param {string | Object} src - Source of the avatar.
2019-06-26 16:08:23 +02:00
* @returns {Promise}
*/
2019-08-30 18:39:06 +02:00
export function preloadImage(src: string | Object): Promise<string> {
2019-07-16 11:23:01 +01:00
if (isIconUrl(src)) {
return Promise.resolve(src);
}
2019-06-26 16:08:23 +02:00
return new Promise((resolve, reject) => {
const image = document.createElement('img');
image.onload = () => resolve(src);
image.onerror = reject;
image.src = src;
});
}