@quintype/components 3.4.4-test-4.0 → 3.4.4

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/dist/cjs/index.js CHANGED
@@ -929,7 +929,7 @@ function removeDuplicateStories(existingStories, newStories) {
929
929
  }
930
930
  function getAssociatedTemplate(_ref) {
931
931
  var associatedMetadata = _ref["associated-metadata"];
932
- return associatedMetadata ? associatedMetadata.layout : 'default';
932
+ return associatedMetadata ? associatedMetadata.layout : "default";
933
933
  } // FIXME: TEST THIS
934
934
 
935
935
  function replaceAllStoriesInCollection(collection, story) {
@@ -973,12 +973,12 @@ var getQliticsSchema = function getQliticsSchema() {
973
973
  }); //Display warning to make debugging easier
974
974
 
975
975
  return {
976
- 'story-content-id': story['story-content-id'],
977
- 'story-version-id': story['story-version-id'],
978
- 'card-content-id': card['content-id'],
979
- 'card-version-id': card['content-version-id'],
980
- 'story-element-id': element.id,
981
- 'story-element-type': element.subtype || element.type
976
+ "story-content-id": story["story-content-id"],
977
+ "story-version-id": story["story-version-id"],
978
+ "card-content-id": card["content-id"],
979
+ "card-version-id": card["content-version-id"],
980
+ "story-element-id": element.id,
981
+ "story-element-type": element.subtype || element.type
982
982
  };
983
983
  };
984
984
  var computeAccess = function computeAccess(previousState, currentState) {
@@ -997,6 +997,16 @@ var computeAccess = function computeAccess(previousState, currentState) {
997
997
 
998
998
  return _objectSpread$6(_objectSpread$6({}, previousState), currentAccess);
999
999
  };
1000
+ function initiateNewObserver(targetElement, intersectionCallBack) {
1001
+ var intersectionObserver = new IntersectionObserver(intersectionCallBack, {
1002
+ threshold: 0.75
1003
+ });
1004
+ intersectionObserver.observe(targetElement);
1005
+ return intersectionObserver;
1006
+ }
1007
+ function disconnectObserver(observer) {
1008
+ if (observer) observer.disconnect();
1009
+ }
1000
1010
 
1001
1011
  function _createSuper$l(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$l(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
1002
1012
 
@@ -2381,6 +2391,21 @@ var BrightcoveElement = function BrightcoveElement(props) {
2381
2391
  posterImage = _useState4[0],
2382
2392
  setPosterImage = _useState4[1];
2383
2393
 
2394
+ var _useState5 = React.useState(null),
2395
+ _useState6 = _slicedToArray__default["default"](_useState5, 2),
2396
+ myPlayer = _useState6[0],
2397
+ setMyPlayer = _useState6[1];
2398
+
2399
+ var _useState7 = React.useState(false),
2400
+ _useState8 = _slicedToArray__default["default"](_useState7, 2),
2401
+ thumbnailClicked = _useState8[0],
2402
+ setThumbnailClicked = _useState8[1];
2403
+
2404
+ var videoRef = React.useRef();
2405
+ var videoPausedByObserver = React.useRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
2406
+
2407
+ var observerRef = React.useRef(); // To Observe video element for intersection
2408
+
2384
2409
  var loadLibrary = function loadLibrary() {
2385
2410
  var _window;
2386
2411
 
@@ -2404,11 +2429,53 @@ var BrightcoveElement = function BrightcoveElement(props) {
2404
2429
  loadLibrary();
2405
2430
  }
2406
2431
  }, [loadIframeOnClick]);
2432
+ React.useEffect(function () {
2433
+ if (!myPlayer) return;
2434
+ myPlayer.on("play", startObserver);
2435
+ myPlayer.on("pause", handleVideoPause);
2436
+ if (thumbnailClicked) myPlayer.play();
2437
+ return function () {
2438
+ myPlayer && myPlayer.off("play");
2439
+ myPlayer && myPlayer.off("pause");
2440
+ observerRef.current && disconnectObserver(observerRef.current);
2441
+ };
2442
+ }, [myPlayer, thumbnailClicked]);
2443
+
2444
+ function intersectionCallback(entries) {
2445
+ var videoInViewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
2446
+ if (videoInViewPort) myPlayer.play();else {
2447
+ videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
2448
+
2449
+ myPlayer.pause();
2450
+ }
2451
+ }
2452
+
2453
+ function startObserver() {
2454
+ var targetElement = videoRef.current;
2455
+ var observer = observerRef.current;
2456
+
2457
+ if (observer) {
2458
+ observer.observe(targetElement);
2459
+ } else {
2460
+ var intersectionObserver = initiateNewObserver(targetElement, intersectionCallback);
2461
+ observerRef.current = intersectionObserver;
2462
+ }
2463
+ }
2464
+
2465
+ function handleVideoPause() {
2466
+ var observer = observerRef.current;
2467
+ var isVideoPausedByObserver = videoPausedByObserver.current;
2468
+
2469
+ if (isVideoPausedByObserver) {
2470
+ videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
2471
+ } else {
2472
+ disconnectObserver(observer);
2473
+ }
2474
+ }
2407
2475
 
2408
2476
  var brightcoveIframe = function brightcoveIframe() {
2409
2477
  var _window2;
2410
2478
 
2411
- var autoplay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2412
2479
  var BrightcovePlayerLoader = (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.BrightcovePlayerLoader;
2413
2480
  return /*#__PURE__*/React__default["default"].createElement(BrightcovePlayerLoader, {
2414
2481
  accountId: accountId,
@@ -2418,13 +2485,7 @@ var BrightcoveElement = function BrightcoveElement(props) {
2418
2485
  className: "brightcove-player"
2419
2486
  },
2420
2487
  onSuccess: function onSuccess(success) {
2421
- if (autoplay) {
2422
- var myPlayer = success.ref;
2423
- myPlayer.ready(function () {
2424
- myPlayer.muted(true);
2425
- myPlayer.play();
2426
- });
2427
- }
2488
+ return setMyPlayer(success.ref);
2428
2489
  },
2429
2490
  onFailure: function onFailure() {
2430
2491
  return console.log("brightcove failed to load");
@@ -2440,31 +2501,28 @@ var BrightcoveElement = function BrightcoveElement(props) {
2440
2501
  while (1) {
2441
2502
  switch (_context.prev = _context.next) {
2442
2503
  case 0:
2443
- console.log("accountId", accountId, videoId);
2444
- console.log("policyKey", policyKey);
2445
-
2446
2504
  if (posterImage) {
2447
- _context.next = 10;
2505
+ _context.next = 8;
2448
2506
  break;
2449
2507
  }
2450
2508
 
2451
- _context.next = 5;
2509
+ _context.next = 3;
2452
2510
  return fetch("https://edge.api.brightcove.com/playback/v1/accounts/".concat(accountId, "/videos?q=id:").concat(videoId), {
2453
2511
  headers: {
2454
2512
  "BCOV-Policy": policyKey
2455
2513
  }
2456
2514
  });
2457
2515
 
2458
- case 5:
2459
- _context.next = 7;
2516
+ case 3:
2517
+ _context.next = 5;
2460
2518
  return _context.sent.json();
2461
2519
 
2462
- case 7:
2520
+ case 5:
2463
2521
  _yield$yield$fetch$js = _context.sent;
2464
2522
  videos = _yield$yield$fetch$js.videos;
2465
2523
  setPosterImage(videos[0].poster || "");
2466
2524
 
2467
- case 10:
2525
+ case 8:
2468
2526
  case "end":
2469
2527
  return _context.stop();
2470
2528
  }
@@ -2480,37 +2538,48 @@ var BrightcoveElement = function BrightcoveElement(props) {
2480
2538
  if (loadIframeOnClick) {
2481
2539
  var _window3;
2482
2540
 
2483
- console.log("coming in if");
2484
-
2485
2541
  if (!showVideo) {
2486
2542
  getPoster();
2487
2543
  }
2488
2544
 
2489
2545
  return /*#__PURE__*/React__default["default"].createElement("div", {
2490
- className: "brightcove-wrapper"
2491
- }, !showVideo && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("button", {
2546
+ className: "brightcove-wrapper",
2547
+ ref: videoRef
2548
+ }, !showVideo && /*#__PURE__*/React__default["default"].createElement("div", {
2549
+ onClick: /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
2550
+ return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
2551
+ while (1) {
2552
+ switch (_context2.prev = _context2.next) {
2553
+ case 0:
2554
+ _context2.next = 2;
2555
+ return loadLibrary();
2556
+
2557
+ case 2:
2558
+ setThumbnailClicked(true);
2559
+
2560
+ case 3:
2561
+ case "end":
2562
+ return _context2.stop();
2563
+ }
2564
+ }
2565
+ }, _callee2);
2566
+ }))
2567
+ }, /*#__PURE__*/React__default["default"].createElement("button", {
2492
2568
  className: "brightcove-playBtn",
2493
- onClick: function onClick() {
2494
- return loadLibrary();
2495
- },
2496
2569
  "aria-label": "Play Video"
2497
2570
  }), posterImage ? /*#__PURE__*/React__default["default"].createElement("img", {
2498
2571
  className: "brightcove-poster",
2499
- onClick: function onClick() {
2500
- return loadLibrary();
2501
- },
2502
2572
  src: posterImage,
2503
2573
  alt: "video"
2504
2574
  }) : /*#__PURE__*/React__default["default"].createElement("div", {
2505
2575
  className: "brightcove-poster-fallback"
2506
- })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe(true));
2576
+ })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe());
2507
2577
  } else if (!loadIframeOnClick && (_window4 = window) !== null && _window4 !== void 0 && _window4.BrightcovePlayerLoader) {
2508
- console.log("coming in else if");
2509
2578
  return /*#__PURE__*/React__default["default"].createElement("div", {
2510
- className: "brightcove-wrapper"
2579
+ className: "brightcove-wrapper",
2580
+ ref: videoRef
2511
2581
  }, brightcoveIframe());
2512
2582
  } else {
2513
- console.log("coming in else");
2514
2583
  return null;
2515
2584
  }
2516
2585
  };
@@ -2560,12 +2629,57 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2560
2629
 
2561
2630
  _this = _super.call(this, props);
2562
2631
 
2632
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "startObserver", function (targetElement) {
2633
+ if (_this.intersectionObserver) {
2634
+ _this.intersectionObserver.observe(targetElement);
2635
+ } else {
2636
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
2637
+ }
2638
+ });
2639
+
2640
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onAdPlayCallback", function (event) {
2641
+ var targetElement = event.target;
2642
+ _this.videoRef.current = targetElement;
2643
+
2644
+ _this.startObserver(targetElement);
2645
+ });
2646
+
2563
2647
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPlayCallback", function (event) {
2564
2648
  _this.props.onPlay === "function" && _this.props.onPlay(event);
2649
+ var targetElement = event.target;
2650
+ _this.videoRef.current = targetElement;
2651
+
2652
+ _this.startObserver(targetElement);
2653
+ });
2654
+
2655
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "handleVideoPause", function () {
2656
+ var videoPausedByObserver = _this.videoPausedByObserver.current;
2657
+
2658
+ if (videoPausedByObserver) {
2659
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
2660
+ } else {
2661
+ disconnectObserver(_this.intersectionObserver);
2662
+ }
2663
+ });
2664
+
2665
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "intersectionCallback", function (entries) {
2666
+ var player = _this.videoRef.current;
2667
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
2668
+ if (videoInVewPort) player.play();else {
2669
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
2670
+
2671
+ player.pause();
2672
+ }
2565
2673
  });
2566
2674
 
2567
2675
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPauseCallback", function (event) {
2568
2676
  _this.props.onPause === "function" && _this.props.onPause(event);
2677
+
2678
+ _this.handleVideoPause();
2679
+ });
2680
+
2681
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onAdPauseCallback", function () {
2682
+ _this.handleVideoPause();
2569
2683
  });
2570
2684
 
2571
2685
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onEndCallback", function (event) {
@@ -2579,11 +2693,6 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2579
2693
  });
2580
2694
  });
2581
2695
 
2582
- _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPlayerReady", function (event) {
2583
- event.target.setVolume(100);
2584
- event.target.playVideo();
2585
- });
2586
-
2587
2696
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "renderVideo", function () {
2588
2697
  _this.triggerIframe();
2589
2698
 
@@ -2600,6 +2709,9 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2600
2709
  autoplay: 0
2601
2710
  }
2602
2711
  };
2712
+ _this.videoRef = /*#__PURE__*/React__default["default"].createRef();
2713
+ _this.videoPausedByObserver = /*#__PURE__*/React__default["default"].createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
2714
+
2603
2715
  return _this;
2604
2716
  }
2605
2717
 
@@ -2614,6 +2726,7 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2614
2726
  key: "componentWillUnmount",
2615
2727
  value: function componentWillUnmount() {
2616
2728
  this._isMounted = false;
2729
+ disconnectObserver(this.intersectionObserver);
2617
2730
  }
2618
2731
  }, {
2619
2732
  key: "render",
@@ -2624,13 +2737,19 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2624
2737
  videoId = _getVideoID.id;
2625
2738
 
2626
2739
  var dailymotionIframe = function dailymotionIframe() {
2740
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false,
2741
+ autoplay = _ref.autoplay;
2742
+
2627
2743
  return /*#__PURE__*/React__default["default"].createElement(DailyMotion$1, {
2628
2744
  video: videoId,
2629
2745
  opts: _this2.opts,
2630
2746
  onPlay: _this2.onPlayCallback,
2631
2747
  onPause: _this2.onPauseCallback,
2632
2748
  onEnd: _this2.onEndCallback,
2633
- autoplay: true
2749
+ onAdPlay: _this2.onAdPlayCallback,
2750
+ onAdPause: _this2.onAdPauseCallback,
2751
+ autoplay: autoplay,
2752
+ ref: _this2.videoRef
2634
2753
  });
2635
2754
  };
2636
2755
 
@@ -2650,13 +2769,7 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2650
2769
  className: "dailymotion-iframe-wrapper"
2651
2770
  }, dailymotionIframe()));
2652
2771
  } else if (!this.props.loadIframeOnClick && isLibraryLoaded$1()) {
2653
- return /*#__PURE__*/React__default["default"].createElement(DailyMotion$1, {
2654
- video: videoId,
2655
- opts: this.opts,
2656
- onPlay: this.onPlayCallback,
2657
- onPause: this.onPauseCallback,
2658
- onEnd: this.onEndCallback
2659
- });
2772
+ return dailymotionIframe();
2660
2773
  } else return /*#__PURE__*/React__default["default"].createElement("div", null);
2661
2774
  }
2662
2775
  }]);
@@ -2696,6 +2809,36 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2696
2809
  });
2697
2810
  });
2698
2811
 
2812
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "intersectionCallback", function (entries) {
2813
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
2814
+ var player = _this.state.dmPlayer;
2815
+ if (videoInVewPort) player.play();else {
2816
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
2817
+
2818
+ player.pause();
2819
+ }
2820
+ });
2821
+
2822
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "startObserver", function () {
2823
+ var targetElement = _this.observerRef.current;
2824
+
2825
+ if (_this.intersectionObserver) {
2826
+ _this.intersectionObserver.observe(targetElement);
2827
+ } else {
2828
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
2829
+ }
2830
+ });
2831
+
2832
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "handleVideoPause", function () {
2833
+ var isVideoPausedByObserver = _this.videoPausedByObserver.current;
2834
+
2835
+ if (isVideoPausedByObserver) {
2836
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
2837
+ } else {
2838
+ disconnectObserver(_this.intersectionObserver);
2839
+ }
2840
+ });
2841
+
2699
2842
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "addScript", function () {
2700
2843
  var _this$props$element$m = _this.props.element.metadata,
2701
2844
  videoId = _this$props$element$m["video-id"],
@@ -2705,11 +2848,28 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2705
2848
  script.dataset.video = videoId;
2706
2849
 
2707
2850
  _this.containerRef.current.appendChild(script);
2851
+
2852
+ script.onload = function () {
2853
+ window.dailymotion.createPlayer(_this.containerRef.current.id, {
2854
+ video: videoId,
2855
+ player: playerId
2856
+ }).then(function (player) {
2857
+ _this.setState({
2858
+ dmPlayer: player
2859
+ });
2860
+ })["catch"](function (e) {
2861
+ return console.error("dm--error", e);
2862
+ });
2863
+ };
2708
2864
  });
2709
2865
 
2710
2866
  _this.containerRef = /*#__PURE__*/React__default["default"].createRef();
2867
+ _this.observerRef = /*#__PURE__*/React__default["default"].createRef();
2868
+ _this.videoPausedByObserver = /*#__PURE__*/React__default["default"].createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
2869
+
2711
2870
  _this.state = {
2712
- showVideo: false
2871
+ showVideo: false,
2872
+ dmPlayer: null
2713
2873
  };
2714
2874
  return _this;
2715
2875
  }
@@ -2721,6 +2881,22 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2721
2881
  this.addScript();
2722
2882
  }
2723
2883
  }
2884
+ }, {
2885
+ key: "componentDidUpdate",
2886
+ value: function componentDidUpdate() {
2887
+ var player = this.state.dmPlayer;
2888
+ if (!player) return;
2889
+ if (!this.observerRef.current) return;
2890
+ player.on("ad_play", this.startObserver);
2891
+ player.on("ad_pause", this.handleVideoPause);
2892
+ player.on("play", this.startObserver);
2893
+ player.on("pause", this.handleVideoPause);
2894
+ }
2895
+ }, {
2896
+ key: "componentWillUnmount",
2897
+ value: function componentWillUnmount() {
2898
+ disconnectObserver(this.intersectionObserver);
2899
+ }
2724
2900
  }, {
2725
2901
  key: "render",
2726
2902
  value: function render() {
@@ -2739,14 +2915,20 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2739
2915
  src: "https://www.dailymotion.com/thumbnail/video/".concat(videoId),
2740
2916
  alt: "daily-motion-video"
2741
2917
  })), this.state.showVideo && /*#__PURE__*/React__default["default"].createElement("div", {
2918
+ ref: this.observerRef
2919
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2742
2920
  className: "dailymotion-embed-wrapper dm-embed-integration",
2743
- ref: this.containerRef
2744
- }));
2921
+ ref: this.containerRef,
2922
+ id: "dm-embed-container-id-".concat(videoId)
2923
+ })));
2745
2924
  } else if (!this.props.loadIframeOnClick) {
2746
2925
  return /*#__PURE__*/React__default["default"].createElement("div", {
2926
+ ref: this.observerRef
2927
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2747
2928
  className: "dailymotion-embed-wrapper dm-embed-integration",
2748
- ref: this.containerRef
2749
- });
2929
+ ref: this.containerRef,
2930
+ id: "dm-embed-container-id-".concat(videoId)
2931
+ }));
2750
2932
  }
2751
2933
  }
2752
2934
  }]);
@@ -3058,6 +3240,16 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3058
3240
 
3059
3241
  _this = _super.call(this, props);
3060
3242
 
3243
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "initiateObserver", function (targetElement) {
3244
+ _this.removeObserverIfExists();
3245
+
3246
+ _this.intersectionObserver = new IntersectionObserver(_this.intersectionCallback, {
3247
+ threshold: 0.75
3248
+ });
3249
+
3250
+ _this.intersectionObserver.observe(targetElement);
3251
+ });
3252
+
3061
3253
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "triggerQlitics", function (action) {
3062
3254
  if (_this.props.disableAnalytics === true) return false;
3063
3255
  var _this$props = _this.props,
@@ -3087,12 +3279,38 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3087
3279
  _this.triggerQlitics("play");
3088
3280
 
3089
3281
  _this.props.onPlay === "function" && _this.props.onPlay(event);
3282
+ _this.videoRef.current = event.target;
3283
+
3284
+ var targetElement = _this.videoRef.current.getIframe();
3285
+
3286
+ if (_this.intersectionObserver) {
3287
+ _this.intersectionObserver.observe(targetElement);
3288
+ } else {
3289
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
3290
+ }
3291
+ });
3292
+
3293
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "intersectionCallback", function (entries) {
3294
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
3295
+ var player = _this.videoRef.current;
3296
+ if (videoInVewPort) player.playVideo();else {
3297
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
3298
+
3299
+ player.pauseVideo();
3300
+ }
3090
3301
  });
3091
3302
 
3092
3303
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPauseCallback", function (event) {
3093
3304
  _this.triggerQlitics("pause");
3094
3305
 
3095
3306
  _this.props.onPause === "function" && _this.props.onPause(event);
3307
+ var videoPausedByObserver = _this.videoPausedByObserver.current;
3308
+
3309
+ if (videoPausedByObserver) {
3310
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
3311
+ } else {
3312
+ disconnectObserver(_this.intersectionObserver);
3313
+ }
3096
3314
  });
3097
3315
 
3098
3316
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onEndCallback", function (event) {
@@ -3129,6 +3347,9 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3129
3347
  autoplay: 0
3130
3348
  }
3131
3349
  };
3350
+ _this.videoRef = /*#__PURE__*/React__default["default"].createRef();
3351
+ _this.videoPausedByObserver = /*#__PURE__*/React__default["default"].createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
3352
+
3132
3353
  return _this;
3133
3354
  }
3134
3355
 
@@ -3143,6 +3364,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3143
3364
  key: "componentWillUnmount",
3144
3365
  value: function componentWillUnmount() {
3145
3366
  this._isMounted = false;
3367
+ disconnectObserver(this.intersectionObserver);
3146
3368
  }
3147
3369
  }, {
3148
3370
  key: "render",
@@ -3156,7 +3378,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3156
3378
  onPlay: _this2.onPlayCallback,
3157
3379
  onPause: _this2.onPauseCallback,
3158
3380
  onEnd: _this2.onEndCallback,
3159
- onReady: _this2.onPlayerReady
3381
+ onReady: _this2.onPlayerReady,
3382
+ ref: _this2.videoRef
3160
3383
  });
3161
3384
  };
3162
3385
 
@@ -3176,13 +3399,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3176
3399
  className: "youtube-iframe-wrapper"
3177
3400
  }, youtubeIframe()));
3178
3401
  } else if (!this.props.loadIframeOnClick && isLibraryLoaded()) {
3179
- return /*#__PURE__*/React__default["default"].createElement(YouTube, {
3180
- videoId: getYouTubeID__default["default"](this.props.element.url),
3181
- opts: this.opts,
3182
- onPlay: this.onPlayCallback,
3183
- onPause: this.onPauseCallback,
3184
- onEnd: this.onEndCallback
3185
- });
3402
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, youtubeIframe());
3186
3403
  } else return /*#__PURE__*/React__default["default"].createElement("div", null);
3187
3404
  }
3188
3405
  }]);
@@ -5217,39 +5434,34 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
5217
5434
  while (1) {
5218
5435
  switch (_context9.prev = _context9.next) {
5219
5436
  case 0:
5220
- console.log("getSubscriptionForUser");
5221
-
5222
5437
  if (global.AccessType) {
5223
- _context9.next = 3;
5438
+ _context9.next = 2;
5224
5439
  break;
5225
5440
  }
5226
5441
 
5227
5442
  return _context9.abrupt("return", {});
5228
5443
 
5229
- case 3:
5230
- console.log("accesstype available");
5231
- _context9.next = 6;
5444
+ case 2:
5445
+ _context9.next = 4;
5232
5446
  return awaitHelper(global.AccessType.getSubscriptions());
5233
5447
 
5234
- case 6:
5448
+ case 4:
5235
5449
  _yield$awaitHelper8 = _context9.sent;
5236
5450
  error = _yield$awaitHelper8.error;
5237
5451
  _yield$awaitHelper8$d = _yield$awaitHelper8.data;
5238
5452
  subscriptions = _yield$awaitHelper8$d === void 0 ? [] : _yield$awaitHelper8$d;
5239
5453
 
5240
5454
  if (!error) {
5241
- _context9.next = 13;
5455
+ _context9.next = 10;
5242
5456
  break;
5243
5457
  }
5244
5458
 
5245
- console.log("coming in error", error);
5246
5459
  return _context9.abrupt("return", error);
5247
5460
 
5248
- case 13:
5249
- console.log("coming in subscriptions", subscriptions);
5461
+ case 10:
5250
5462
  return _context9.abrupt("return", subscriptions);
5251
5463
 
5252
- case 15:
5464
+ case 11:
5253
5465
  case "end":
5254
5466
  return _context9.stop();
5255
5467
  }
@@ -6443,8 +6655,10 @@ exports.awaitHelper = awaitHelper;
6443
6655
  exports.collectionToStories = collectionToStories;
6444
6656
  exports.computeAccess = computeAccess;
6445
6657
  exports.createDfpAdComponent = createDfpAdComponent;
6658
+ exports.disconnectObserver = disconnectObserver;
6446
6659
  exports.getAssociatedTemplate = getAssociatedTemplate;
6447
6660
  exports.getQliticsSchema = getQliticsSchema;
6661
+ exports.initiateNewObserver = initiateNewObserver;
6448
6662
  exports.refreshDfpAds = refreshDfpAds;
6449
6663
  exports.removeDuplicateStories = removeDuplicateStories;
6450
6664
  exports.replaceAllStoriesInCollection = replaceAllStoriesInCollection;
@@ -480,39 +480,34 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
480
480
  while (1) {
481
481
  switch (_context9.prev = _context9.next) {
482
482
  case 0:
483
- console.log("getSubscriptionForUser");
484
-
485
483
  if (global.AccessType) {
486
- _context9.next = 3;
484
+ _context9.next = 2;
487
485
  break;
488
486
  }
489
487
 
490
488
  return _context9.abrupt("return", {});
491
489
 
492
- case 3:
493
- console.log("accesstype available");
494
- _context9.next = 6;
490
+ case 2:
491
+ _context9.next = 4;
495
492
  return awaitHelper(global.AccessType.getSubscriptions());
496
493
 
497
- case 6:
494
+ case 4:
498
495
  _yield$awaitHelper8 = _context9.sent;
499
496
  error = _yield$awaitHelper8.error;
500
497
  _yield$awaitHelper8$d = _yield$awaitHelper8.data;
501
498
  subscriptions = _yield$awaitHelper8$d === void 0 ? [] : _yield$awaitHelper8$d;
502
499
 
503
500
  if (!error) {
504
- _context9.next = 13;
501
+ _context9.next = 10;
505
502
  break;
506
503
  }
507
504
 
508
- console.log("coming in error", error);
509
505
  return _context9.abrupt("return", error);
510
506
 
511
- case 13:
512
- console.log("coming in subscriptions", subscriptions);
507
+ case 10:
513
508
  return _context9.abrupt("return", subscriptions);
514
509
 
515
- case 15:
510
+ case 11:
516
511
  case "end":
517
512
  return _context9.stop();
518
513
  }
@@ -3,7 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import get from "lodash/get";
5
5
  import { bool, object } from "prop-types";
6
- import React, { useEffect, useState } from "react";
6
+ import React, { useEffect, useRef, useState } from "react";
7
+ import { disconnectObserver, initiateNewObserver } from "../../utils";
7
8
  import { WithLazy } from "../with-lazy";
8
9
 
9
10
  var BrightcoveElement = function BrightcoveElement(props) {
@@ -30,6 +31,21 @@ var BrightcoveElement = function BrightcoveElement(props) {
30
31
  posterImage = _useState4[0],
31
32
  setPosterImage = _useState4[1];
32
33
 
34
+ var _useState5 = useState(null),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ myPlayer = _useState6[0],
37
+ setMyPlayer = _useState6[1];
38
+
39
+ var _useState7 = useState(false),
40
+ _useState8 = _slicedToArray(_useState7, 2),
41
+ thumbnailClicked = _useState8[0],
42
+ setThumbnailClicked = _useState8[1];
43
+
44
+ var videoRef = useRef();
45
+ var videoPausedByObserver = useRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
46
+
47
+ var observerRef = useRef(); // To Observe video element for intersection
48
+
33
49
  var loadLibrary = function loadLibrary() {
34
50
  var _window;
35
51
 
@@ -53,11 +69,53 @@ var BrightcoveElement = function BrightcoveElement(props) {
53
69
  loadLibrary();
54
70
  }
55
71
  }, [loadIframeOnClick]);
72
+ useEffect(function () {
73
+ if (!myPlayer) return;
74
+ myPlayer.on("play", startObserver);
75
+ myPlayer.on("pause", handleVideoPause);
76
+ if (thumbnailClicked) myPlayer.play();
77
+ return function () {
78
+ myPlayer && myPlayer.off("play");
79
+ myPlayer && myPlayer.off("pause");
80
+ observerRef.current && disconnectObserver(observerRef.current);
81
+ };
82
+ }, [myPlayer, thumbnailClicked]);
83
+
84
+ function intersectionCallback(entries) {
85
+ var videoInViewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
86
+ if (videoInViewPort) myPlayer.play();else {
87
+ videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
88
+
89
+ myPlayer.pause();
90
+ }
91
+ }
92
+
93
+ function startObserver() {
94
+ var targetElement = videoRef.current;
95
+ var observer = observerRef.current;
96
+
97
+ if (observer) {
98
+ observer.observe(targetElement);
99
+ } else {
100
+ var intersectionObserver = initiateNewObserver(targetElement, intersectionCallback);
101
+ observerRef.current = intersectionObserver;
102
+ }
103
+ }
104
+
105
+ function handleVideoPause() {
106
+ var observer = observerRef.current;
107
+ var isVideoPausedByObserver = videoPausedByObserver.current;
108
+
109
+ if (isVideoPausedByObserver) {
110
+ videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
111
+ } else {
112
+ disconnectObserver(observer);
113
+ }
114
+ }
56
115
 
57
116
  var brightcoveIframe = function brightcoveIframe() {
58
117
  var _window2;
59
118
 
60
- var autoplay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
61
119
  var BrightcovePlayerLoader = (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.BrightcovePlayerLoader;
62
120
  return /*#__PURE__*/React.createElement(BrightcovePlayerLoader, {
63
121
  accountId: accountId,
@@ -67,13 +125,7 @@ var BrightcoveElement = function BrightcoveElement(props) {
67
125
  className: "brightcove-player"
68
126
  },
69
127
  onSuccess: function onSuccess(success) {
70
- if (autoplay) {
71
- var myPlayer = success.ref;
72
- myPlayer.ready(function () {
73
- myPlayer.muted(true);
74
- myPlayer.play();
75
- });
76
- }
128
+ return setMyPlayer(success.ref);
77
129
  },
78
130
  onFailure: function onFailure() {
79
131
  return console.log("brightcove failed to load");
@@ -89,31 +141,28 @@ var BrightcoveElement = function BrightcoveElement(props) {
89
141
  while (1) {
90
142
  switch (_context.prev = _context.next) {
91
143
  case 0:
92
- console.log("accountId", accountId, videoId);
93
- console.log("policyKey", policyKey);
94
-
95
144
  if (posterImage) {
96
- _context.next = 10;
145
+ _context.next = 8;
97
146
  break;
98
147
  }
99
148
 
100
- _context.next = 5;
149
+ _context.next = 3;
101
150
  return fetch("https://edge.api.brightcove.com/playback/v1/accounts/".concat(accountId, "/videos?q=id:").concat(videoId), {
102
151
  headers: {
103
152
  "BCOV-Policy": policyKey
104
153
  }
105
154
  });
106
155
 
107
- case 5:
108
- _context.next = 7;
156
+ case 3:
157
+ _context.next = 5;
109
158
  return _context.sent.json();
110
159
 
111
- case 7:
160
+ case 5:
112
161
  _yield$yield$fetch$js = _context.sent;
113
162
  videos = _yield$yield$fetch$js.videos;
114
163
  setPosterImage(videos[0].poster || "");
115
164
 
116
- case 10:
165
+ case 8:
117
166
  case "end":
118
167
  return _context.stop();
119
168
  }
@@ -129,37 +178,48 @@ var BrightcoveElement = function BrightcoveElement(props) {
129
178
  if (loadIframeOnClick) {
130
179
  var _window3;
131
180
 
132
- console.log("coming in if");
133
-
134
181
  if (!showVideo) {
135
182
  getPoster();
136
183
  }
137
184
 
138
185
  return /*#__PURE__*/React.createElement("div", {
139
- className: "brightcove-wrapper"
140
- }, !showVideo && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
186
+ className: "brightcove-wrapper",
187
+ ref: videoRef
188
+ }, !showVideo && /*#__PURE__*/React.createElement("div", {
189
+ onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
190
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
191
+ while (1) {
192
+ switch (_context2.prev = _context2.next) {
193
+ case 0:
194
+ _context2.next = 2;
195
+ return loadLibrary();
196
+
197
+ case 2:
198
+ setThumbnailClicked(true);
199
+
200
+ case 3:
201
+ case "end":
202
+ return _context2.stop();
203
+ }
204
+ }
205
+ }, _callee2);
206
+ }))
207
+ }, /*#__PURE__*/React.createElement("button", {
141
208
  className: "brightcove-playBtn",
142
- onClick: function onClick() {
143
- return loadLibrary();
144
- },
145
209
  "aria-label": "Play Video"
146
210
  }), posterImage ? /*#__PURE__*/React.createElement("img", {
147
211
  className: "brightcove-poster",
148
- onClick: function onClick() {
149
- return loadLibrary();
150
- },
151
212
  src: posterImage,
152
213
  alt: "video"
153
214
  }) : /*#__PURE__*/React.createElement("div", {
154
215
  className: "brightcove-poster-fallback"
155
216
  })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe(true));
156
217
  } else if (!loadIframeOnClick && (_window4 = window) !== null && _window4 !== void 0 && _window4.BrightcovePlayerLoader) {
157
- console.log("coming in else if");
158
218
  return /*#__PURE__*/React.createElement("div", {
159
- className: "brightcove-wrapper"
219
+ className: "brightcove-wrapper",
220
+ ref: videoRef
160
221
  }, brightcoveIframe());
161
222
  } else {
162
- console.log("coming in else");
163
223
  return null;
164
224
  }
165
225
  };
@@ -11,6 +11,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
11
11
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
12
 
13
13
  import React from "react";
14
+ import { disconnectObserver, initiateNewObserver } from "../../utils";
14
15
  import { WithLazy } from "../with-lazy";
15
16
 
16
17
  var DailyMotion = /*#__PURE__*/function (_React$Component) {
@@ -33,6 +34,36 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
33
34
  });
34
35
  });
35
36
 
37
+ _defineProperty(_assertThisInitialized(_this), "intersectionCallback", function (entries) {
38
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
39
+ var player = _this.state.dmPlayer;
40
+ if (videoInVewPort) player.play();else {
41
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
42
+
43
+ player.pause();
44
+ }
45
+ });
46
+
47
+ _defineProperty(_assertThisInitialized(_this), "startObserver", function () {
48
+ var targetElement = _this.observerRef.current;
49
+
50
+ if (_this.intersectionObserver) {
51
+ _this.intersectionObserver.observe(targetElement);
52
+ } else {
53
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
54
+ }
55
+ });
56
+
57
+ _defineProperty(_assertThisInitialized(_this), "handleVideoPause", function () {
58
+ var isVideoPausedByObserver = _this.videoPausedByObserver.current;
59
+
60
+ if (isVideoPausedByObserver) {
61
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
62
+ } else {
63
+ disconnectObserver(_this.intersectionObserver);
64
+ }
65
+ });
66
+
36
67
  _defineProperty(_assertThisInitialized(_this), "addScript", function () {
37
68
  var _this$props$element$m = _this.props.element.metadata,
38
69
  videoId = _this$props$element$m["video-id"],
@@ -42,11 +73,28 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
42
73
  script.dataset.video = videoId;
43
74
 
44
75
  _this.containerRef.current.appendChild(script);
76
+
77
+ script.onload = function () {
78
+ window.dailymotion.createPlayer(_this.containerRef.current.id, {
79
+ video: videoId,
80
+ player: playerId
81
+ }).then(function (player) {
82
+ _this.setState({
83
+ dmPlayer: player
84
+ });
85
+ })["catch"](function (e) {
86
+ return console.error("dm--error", e);
87
+ });
88
+ };
45
89
  });
46
90
 
47
91
  _this.containerRef = /*#__PURE__*/React.createRef();
92
+ _this.observerRef = /*#__PURE__*/React.createRef();
93
+ _this.videoPausedByObserver = /*#__PURE__*/React.createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
94
+
48
95
  _this.state = {
49
- showVideo: false
96
+ showVideo: false,
97
+ dmPlayer: null
50
98
  };
51
99
  return _this;
52
100
  }
@@ -58,6 +106,22 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
58
106
  this.addScript();
59
107
  }
60
108
  }
109
+ }, {
110
+ key: "componentDidUpdate",
111
+ value: function componentDidUpdate() {
112
+ var player = this.state.dmPlayer;
113
+ if (!player) return;
114
+ if (!this.observerRef.current) return;
115
+ player.on("ad_play", this.startObserver);
116
+ player.on("ad_pause", this.handleVideoPause);
117
+ player.on("play", this.startObserver);
118
+ player.on("pause", this.handleVideoPause);
119
+ }
120
+ }, {
121
+ key: "componentWillUnmount",
122
+ value: function componentWillUnmount() {
123
+ disconnectObserver(this.intersectionObserver);
124
+ }
61
125
  }, {
62
126
  key: "render",
63
127
  value: function render() {
@@ -76,14 +140,20 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
76
140
  src: "https://www.dailymotion.com/thumbnail/video/".concat(videoId),
77
141
  alt: "daily-motion-video"
78
142
  })), this.state.showVideo && /*#__PURE__*/React.createElement("div", {
143
+ ref: this.observerRef
144
+ }, /*#__PURE__*/React.createElement("div", {
79
145
  className: "dailymotion-embed-wrapper dm-embed-integration",
80
- ref: this.containerRef
81
- }));
146
+ ref: this.containerRef,
147
+ id: "dm-embed-container-id-".concat(videoId)
148
+ })));
82
149
  } else if (!this.props.loadIframeOnClick) {
83
150
  return /*#__PURE__*/React.createElement("div", {
151
+ ref: this.observerRef
152
+ }, /*#__PURE__*/React.createElement("div", {
84
153
  className: "dailymotion-embed-wrapper dm-embed-integration",
85
- ref: this.containerRef
86
- });
154
+ ref: this.containerRef,
155
+ id: "dm-embed-container-id-".concat(videoId)
156
+ }));
87
157
  }
88
158
  }
89
159
  }]);
@@ -13,6 +13,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
13
13
  import getVideoID from "get-video-id";
14
14
  import { bool, func, object } from "prop-types";
15
15
  import React from "react";
16
+ import { disconnectObserver, initiateNewObserver } from "../../utils";
16
17
  import { WithLazy } from "../with-lazy";
17
18
  var DailyMotion = null;
18
19
  var loaderPromise = null;
@@ -48,12 +49,57 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
48
49
 
49
50
  _this = _super.call(this, props);
50
51
 
52
+ _defineProperty(_assertThisInitialized(_this), "startObserver", function (targetElement) {
53
+ if (_this.intersectionObserver) {
54
+ _this.intersectionObserver.observe(targetElement);
55
+ } else {
56
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
57
+ }
58
+ });
59
+
60
+ _defineProperty(_assertThisInitialized(_this), "onAdPlayCallback", function (event) {
61
+ var targetElement = event.target;
62
+ _this.videoRef.current = targetElement;
63
+
64
+ _this.startObserver(targetElement);
65
+ });
66
+
51
67
  _defineProperty(_assertThisInitialized(_this), "onPlayCallback", function (event) {
52
68
  _this.props.onPlay === "function" && _this.props.onPlay(event);
69
+ var targetElement = event.target;
70
+ _this.videoRef.current = targetElement;
71
+
72
+ _this.startObserver(targetElement);
73
+ });
74
+
75
+ _defineProperty(_assertThisInitialized(_this), "handleVideoPause", function () {
76
+ var videoPausedByObserver = _this.videoPausedByObserver.current;
77
+
78
+ if (videoPausedByObserver) {
79
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
80
+ } else {
81
+ disconnectObserver(_this.intersectionObserver);
82
+ }
83
+ });
84
+
85
+ _defineProperty(_assertThisInitialized(_this), "intersectionCallback", function (entries) {
86
+ var player = _this.videoRef.current;
87
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
88
+ if (videoInVewPort) player.play();else {
89
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
90
+
91
+ player.pause();
92
+ }
53
93
  });
54
94
 
55
95
  _defineProperty(_assertThisInitialized(_this), "onPauseCallback", function (event) {
56
96
  _this.props.onPause === "function" && _this.props.onPause(event);
97
+
98
+ _this.handleVideoPause();
99
+ });
100
+
101
+ _defineProperty(_assertThisInitialized(_this), "onAdPauseCallback", function () {
102
+ _this.handleVideoPause();
57
103
  });
58
104
 
59
105
  _defineProperty(_assertThisInitialized(_this), "onEndCallback", function (event) {
@@ -67,11 +113,6 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
67
113
  });
68
114
  });
69
115
 
70
- _defineProperty(_assertThisInitialized(_this), "onPlayerReady", function (event) {
71
- event.target.setVolume(100);
72
- event.target.playVideo();
73
- });
74
-
75
116
  _defineProperty(_assertThisInitialized(_this), "renderVideo", function () {
76
117
  _this.triggerIframe();
77
118
 
@@ -88,6 +129,9 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
88
129
  autoplay: 0
89
130
  }
90
131
  };
132
+ _this.videoRef = /*#__PURE__*/React.createRef();
133
+ _this.videoPausedByObserver = /*#__PURE__*/React.createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
134
+
91
135
  return _this;
92
136
  }
93
137
 
@@ -102,6 +146,7 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
102
146
  key: "componentWillUnmount",
103
147
  value: function componentWillUnmount() {
104
148
  this._isMounted = false;
149
+ disconnectObserver(this.intersectionObserver);
105
150
  }
106
151
  }, {
107
152
  key: "render",
@@ -112,13 +157,19 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
112
157
  videoId = _getVideoID.id;
113
158
 
114
159
  var dailymotionIframe = function dailymotionIframe() {
160
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false,
161
+ autoplay = _ref.autoplay;
162
+
115
163
  return /*#__PURE__*/React.createElement(DailyMotion, {
116
164
  video: videoId,
117
165
  opts: _this2.opts,
118
166
  onPlay: _this2.onPlayCallback,
119
167
  onPause: _this2.onPauseCallback,
120
168
  onEnd: _this2.onEndCallback,
121
- autoplay: true
169
+ onAdPlay: _this2.onAdPlayCallback,
170
+ onAdPause: _this2.onAdPauseCallback,
171
+ autoplay: autoplay,
172
+ ref: _this2.videoRef
122
173
  });
123
174
  };
124
175
 
@@ -138,13 +189,7 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
138
189
  className: "dailymotion-iframe-wrapper"
139
190
  }, dailymotionIframe()));
140
191
  } else if (!this.props.loadIframeOnClick && isLibraryLoaded()) {
141
- return /*#__PURE__*/React.createElement(DailyMotion, {
142
- video: videoId,
143
- opts: this.opts,
144
- onPlay: this.onPlayCallback,
145
- onPause: this.onPauseCallback,
146
- onEnd: this.onEndCallback
147
- });
192
+ return dailymotionIframe();
148
193
  } else return /*#__PURE__*/React.createElement("div", null);
149
194
  }
150
195
  }]);
@@ -17,7 +17,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
17
17
  import getYouTubeID from "get-youtube-id";
18
18
  import { bool, func, object } from "prop-types";
19
19
  import React from "react";
20
- import { getQliticsSchema } from "../../utils";
20
+ import { disconnectObserver, getQliticsSchema, initiateNewObserver } from "../../utils";
21
21
  import { WithLazy } from "../with-lazy";
22
22
  var YouTube = null;
23
23
  var loaderPromise = null;
@@ -53,6 +53,16 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
53
53
 
54
54
  _this = _super.call(this, props);
55
55
 
56
+ _defineProperty(_assertThisInitialized(_this), "initiateObserver", function (targetElement) {
57
+ _this.removeObserverIfExists();
58
+
59
+ _this.intersectionObserver = new IntersectionObserver(_this.intersectionCallback, {
60
+ threshold: 0.75
61
+ });
62
+
63
+ _this.intersectionObserver.observe(targetElement);
64
+ });
65
+
56
66
  _defineProperty(_assertThisInitialized(_this), "triggerQlitics", function (action) {
57
67
  if (_this.props.disableAnalytics === true) return false;
58
68
  var _this$props = _this.props,
@@ -82,12 +92,38 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
82
92
  _this.triggerQlitics("play");
83
93
 
84
94
  _this.props.onPlay === "function" && _this.props.onPlay(event);
95
+ _this.videoRef.current = event.target;
96
+
97
+ var targetElement = _this.videoRef.current.getIframe();
98
+
99
+ if (_this.intersectionObserver) {
100
+ _this.intersectionObserver.observe(targetElement);
101
+ } else {
102
+ _this.intersectionObserver = initiateNewObserver(targetElement, _this.intersectionCallback);
103
+ }
104
+ });
105
+
106
+ _defineProperty(_assertThisInitialized(_this), "intersectionCallback", function (entries) {
107
+ var videoInVewPort = entries === null || entries === void 0 ? void 0 : entries[0].isIntersecting;
108
+ var player = _this.videoRef.current;
109
+ if (videoInVewPort) player.playVideo();else {
110
+ _this.videoPausedByObserver.current = true; // before the below line fires the pause event we set the videoPausedByObserver Ref to true, this lets the pause events callback to know that the video is not click-paused by the user but paused by the intersection observer
111
+
112
+ player.pauseVideo();
113
+ }
85
114
  });
86
115
 
87
116
  _defineProperty(_assertThisInitialized(_this), "onPauseCallback", function (event) {
88
117
  _this.triggerQlitics("pause");
89
118
 
90
119
  _this.props.onPause === "function" && _this.props.onPause(event);
120
+ var videoPausedByObserver = _this.videoPausedByObserver.current;
121
+
122
+ if (videoPausedByObserver) {
123
+ _this.videoPausedByObserver.current = false; // This is a clean up to set videoPausedByObserver back to false
124
+ } else {
125
+ disconnectObserver(_this.intersectionObserver);
126
+ }
91
127
  });
92
128
 
93
129
  _defineProperty(_assertThisInitialized(_this), "onEndCallback", function (event) {
@@ -124,6 +160,9 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
124
160
  autoplay: 0
125
161
  }
126
162
  };
163
+ _this.videoRef = /*#__PURE__*/React.createRef();
164
+ _this.videoPausedByObserver = /*#__PURE__*/React.createRef(); // To check if the video is not click paused by user but paused by intersection observer, Its implemented this way because we cannot capture the click-pause event as videos are playing in iframe
165
+
127
166
  return _this;
128
167
  }
129
168
 
@@ -138,6 +177,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
138
177
  key: "componentWillUnmount",
139
178
  value: function componentWillUnmount() {
140
179
  this._isMounted = false;
180
+ disconnectObserver(this.intersectionObserver);
141
181
  }
142
182
  }, {
143
183
  key: "render",
@@ -151,7 +191,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
151
191
  onPlay: _this2.onPlayCallback,
152
192
  onPause: _this2.onPauseCallback,
153
193
  onEnd: _this2.onEndCallback,
154
- onReady: _this2.onPlayerReady
194
+ onReady: _this2.onPlayerReady,
195
+ ref: _this2.videoRef
155
196
  });
156
197
  };
157
198
 
@@ -171,13 +212,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
171
212
  className: "youtube-iframe-wrapper"
172
213
  }, youtubeIframe()));
173
214
  } else if (!this.props.loadIframeOnClick && isLibraryLoaded()) {
174
- return /*#__PURE__*/React.createElement(YouTube, {
175
- videoId: getYouTubeID(this.props.element.url),
176
- opts: this.opts,
177
- onPlay: this.onPlayCallback,
178
- onPause: this.onPauseCallback,
179
- onEnd: this.onEndCallback
180
- });
215
+ return /*#__PURE__*/React.createElement(React.Fragment, null, youtubeIframe());
181
216
  } else return /*#__PURE__*/React.createElement("div", null);
182
217
  }
183
218
  }]);
package/dist/es/utils.js CHANGED
@@ -17,7 +17,7 @@ export function removeDuplicateStories(existingStories, newStories) {
17
17
  }
18
18
  export function getAssociatedTemplate(_ref) {
19
19
  var associatedMetadata = _ref["associated-metadata"];
20
- return associatedMetadata ? associatedMetadata.layout : 'default';
20
+ return associatedMetadata ? associatedMetadata.layout : "default";
21
21
  } // FIXME: TEST THIS
22
22
 
23
23
  export function replaceAllStoriesInCollection(collection, story) {
@@ -61,12 +61,12 @@ export var getQliticsSchema = function getQliticsSchema() {
61
61
  }); //Display warning to make debugging easier
62
62
 
63
63
  return {
64
- 'story-content-id': story['story-content-id'],
65
- 'story-version-id': story['story-version-id'],
66
- 'card-content-id': card['content-id'],
67
- 'card-version-id': card['content-version-id'],
68
- 'story-element-id': element.id,
69
- 'story-element-type': element.subtype || element.type
64
+ "story-content-id": story["story-content-id"],
65
+ "story-version-id": story["story-version-id"],
66
+ "card-content-id": card["content-id"],
67
+ "card-version-id": card["content-version-id"],
68
+ "story-element-id": element.id,
69
+ "story-element-type": element.subtype || element.type
70
70
  };
71
71
  };
72
72
  export var computeAccess = function computeAccess(previousState, currentState) {
@@ -84,4 +84,14 @@ export var computeAccess = function computeAccess(previousState, currentState) {
84
84
  }
85
85
 
86
86
  return _objectSpread(_objectSpread({}, previousState), currentAccess);
87
- };
87
+ };
88
+ export function initiateNewObserver(targetElement, intersectionCallBack) {
89
+ var intersectionObserver = new IntersectionObserver(intersectionCallBack, {
90
+ threshold: 0.75
91
+ });
92
+ intersectionObserver.observe(targetElement);
93
+ return intersectionObserver;
94
+ }
95
+ export function disconnectObserver(observer) {
96
+ if (observer) observer.disconnect();
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/components",
3
- "version": "3.4.4-test-4.0",
3
+ "version": "3.4.4",
4
4
  "description": "Components to help build Quintype Node.js apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",