stormcloud-video-player 0.2.16 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -282,6 +282,14 @@ function createImaController(video, options) {
282
282
  function makeAdsRequest(google, vastTagUrl) {
283
283
  const adsRequest = new google.ima.AdsRequest();
284
284
  adsRequest.adTagUrl = vastTagUrl;
285
+ const videoWidth = video.offsetWidth || video.clientWidth || 640;
286
+ const videoHeight = video.offsetHeight || video.clientHeight || 360;
287
+ adsRequest.linearAdSlotWidth = videoWidth;
288
+ adsRequest.linearAdSlotHeight = videoHeight;
289
+ adsRequest.nonLinearAdSlotWidth = videoWidth;
290
+ adsRequest.nonLinearAdSlotHeight = videoHeight;
291
+ adsRequest.vastLoadTimeout = 5e3;
292
+ console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
285
293
  adsLoader.requestAds(adsRequest);
286
294
  }
287
295
  function destroyAdsManager() {
@@ -328,6 +336,18 @@ function createImaController(video, options) {
328
336
  },
329
337
  async requestAds(vastTagUrl) {
330
338
  console.log("[IMA] Requesting ads:", vastTagUrl);
339
+ if (!vastTagUrl || vastTagUrl.trim() === "") {
340
+ const error = new Error("VAST tag URL is empty or undefined");
341
+ console.warn("[IMA]", error.message);
342
+ return Promise.reject(error);
343
+ }
344
+ try {
345
+ new URL(vastTagUrl);
346
+ } catch (e) {
347
+ const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
348
+ console.warn("[IMA]", error.message);
349
+ return Promise.reject(error);
350
+ }
331
351
  if (adPlaying) {
332
352
  console.warn(
333
353
  "[IMA] Cannot request new ads while an ad is playing. Call stop() first."
@@ -389,6 +409,18 @@ function createImaController(video, options) {
389
409
  );
390
410
  }
391
411
  }
412
+ const videoWidth = video.offsetWidth || video.clientWidth;
413
+ const videoHeight = video.offsetHeight || video.clientHeight;
414
+ if (!videoWidth || !videoHeight || videoWidth === 0 || videoHeight === 0) {
415
+ const error = new Error(
416
+ `Invalid video dimensions: ${videoWidth}x${videoHeight}. Cannot initialize ads.`
417
+ );
418
+ console.warn("[IMA]", error.message);
419
+ currentReject == null ? void 0 : currentReject(error);
420
+ adsLoadedReject = void 0;
421
+ adsLoadedResolve = void 0;
422
+ return Promise.reject(error);
423
+ }
392
424
  if (!adsLoader) {
393
425
  console.log("[IMA] Creating ads loader");
394
426
  const adsLoaderCls = new google.ima.AdsLoader(adDisplayContainer);
@@ -437,7 +469,9 @@ function createImaController(video, options) {
437
469
  emit("ad_error");
438
470
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
439
471
  if (video.paused) {
440
- console.log("[IMA] Resuming paused video after ad error");
472
+ console.log(
473
+ "[IMA] Resuming paused video after ad error"
474
+ );
441
475
  (_a = video.play()) == null ? void 0 : _a.catch(() => {
442
476
  });
443
477
  }
@@ -539,7 +573,9 @@ function createImaController(video, options) {
539
573
  }
540
574
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
541
575
  if (video.paused) {
542
- console.log("[IMA] Resuming paused video after setup error");
576
+ console.log(
577
+ "[IMA] Resuming paused video after setup error"
578
+ );
543
579
  video.play().catch(() => {
544
580
  });
545
581
  }