UNPKG

@alugha/ima

Version:

A library for asynchronously loading the Google IMA SDK with static typing for the SDK

22 lines (21 loc) 693 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const loadScript_1 = require("./loadScript"); const imaSdkSrc = "https://imasdk.googleapis.com/js/sdkloader/ima3.js"; let pendingPromise = null; const promiseFinished = () => { pendingPromise = null; }; const loadImaSdk = () => { const w = window; if (w.google && w.google.ima) { return Promise.resolve(w.google.ima); } if (pendingPromise) { return pendingPromise; } pendingPromise = (0, loadScript_1.default)(imaSdkSrc).then(() => w.google.ima); pendingPromise.then(promiseFinished).catch(promiseFinished); return pendingPromise; }; exports.default = loadImaSdk;