@quintype/components 3.4.4-debug.0 → 3.4.4-infiniteScroll-videos.2

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
@@ -2381,6 +2381,23 @@ var BrightcoveElement = function BrightcoveElement(props) {
2381
2381
  posterImage = _useState4[0],
2382
2382
  setPosterImage = _useState4[1];
2383
2383
 
2384
+ var _useState5 = React.useState(null),
2385
+ _useState6 = _slicedToArray__default["default"](_useState5, 2),
2386
+ myPlayer = _useState6[0],
2387
+ setMyPlayer = _useState6[1];
2388
+
2389
+ var _useState7 = React.useState(null),
2390
+ _useState8 = _slicedToArray__default["default"](_useState7, 2),
2391
+ observer = _useState8[0],
2392
+ setObserver = _useState8[1];
2393
+
2394
+ var _useState9 = React.useState(false),
2395
+ _useState10 = _slicedToArray__default["default"](_useState9, 2),
2396
+ thumbnailClicked = _useState10[0],
2397
+ setThumbnailClicked = _useState10[1];
2398
+
2399
+ var videoRef = React.useRef();
2400
+
2384
2401
  var loadLibrary = function loadLibrary() {
2385
2402
  var _window;
2386
2403
 
@@ -2404,11 +2421,34 @@ var BrightcoveElement = function BrightcoveElement(props) {
2404
2421
  loadLibrary();
2405
2422
  }
2406
2423
  }, [loadIframeOnClick]);
2424
+ React.useEffect(function () {
2425
+ if (!myPlayer) return;
2426
+ myPlayer.on("play", startObserver);
2427
+ if (thumbnailClicked) myPlayer.play();
2428
+ return function () {
2429
+ myPlayer && myPlayer.off("play");
2430
+ observer && observer.disconnect();
2431
+ };
2432
+ }, [myPlayer, thumbnailClicked]);
2433
+
2434
+ function handleIntersection(entries) {
2435
+ if (!(entries !== null && entries !== void 0 && entries[0])) return;
2436
+ if (entries[0].isIntersecting) myPlayer.play();else myPlayer.pause();
2437
+ }
2438
+
2439
+ function startObserver() {
2440
+ var intersectionObserver = new IntersectionObserver(function (entries) {
2441
+ return handleIntersection(entries);
2442
+ }, {
2443
+ threshold: 0.75
2444
+ });
2445
+ intersectionObserver.observe(videoRef.current);
2446
+ setObserver(intersectionObserver);
2447
+ }
2407
2448
 
2408
2449
  var brightcoveIframe = function brightcoveIframe() {
2409
2450
  var _window2;
2410
2451
 
2411
- var autoplay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2412
2452
  var BrightcovePlayerLoader = (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.BrightcovePlayerLoader;
2413
2453
  return /*#__PURE__*/React__default["default"].createElement(BrightcovePlayerLoader, {
2414
2454
  accountId: accountId,
@@ -2418,13 +2458,7 @@ var BrightcoveElement = function BrightcoveElement(props) {
2418
2458
  className: "brightcove-player"
2419
2459
  },
2420
2460
  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
- }
2461
+ return setMyPlayer(success.ref);
2428
2462
  },
2429
2463
  onFailure: function onFailure() {
2430
2464
  return console.log("brightcove failed to load");
@@ -2482,26 +2516,30 @@ var BrightcoveElement = function BrightcoveElement(props) {
2482
2516
  }
2483
2517
 
2484
2518
  return /*#__PURE__*/React__default["default"].createElement("div", {
2485
- className: "brightcove-wrapper"
2519
+ className: "brightcove-wrapper",
2520
+ ref: videoRef
2486
2521
  }, !showVideo && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("button", {
2487
2522
  className: "brightcove-playBtn",
2488
2523
  onClick: function onClick() {
2489
- return loadLibrary();
2524
+ loadLibrary();
2525
+ setThumbnailClicked(true);
2490
2526
  },
2491
2527
  "aria-label": "Play Video"
2492
2528
  }), posterImage ? /*#__PURE__*/React__default["default"].createElement("img", {
2493
2529
  className: "brightcove-poster",
2494
2530
  onClick: function onClick() {
2495
- return loadLibrary();
2531
+ loadLibrary();
2532
+ setThumbnailClicked(true);
2496
2533
  },
2497
2534
  src: posterImage,
2498
2535
  alt: "video"
2499
2536
  }) : /*#__PURE__*/React__default["default"].createElement("div", {
2500
2537
  className: "brightcove-poster-fallback"
2501
- })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe(true));
2538
+ })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe());
2502
2539
  } else if (!loadIframeOnClick && (_window4 = window) !== null && _window4 !== void 0 && _window4.BrightcovePlayerLoader) {
2503
2540
  return /*#__PURE__*/React__default["default"].createElement("div", {
2504
- className: "brightcove-wrapper"
2541
+ className: "brightcove-wrapper",
2542
+ ref: videoRef
2505
2543
  }, brightcoveIframe());
2506
2544
  } else {
2507
2545
  return null;
@@ -2553,8 +2591,23 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2553
2591
 
2554
2592
  _this = _super.call(this, props);
2555
2593
 
2594
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onAdStart", function (event) {
2595
+ _this.startObserver(event);
2596
+ });
2597
+
2556
2598
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPlayCallback", function (event) {
2557
2599
  _this.props.onPlay === "function" && _this.props.onPlay(event);
2600
+
2601
+ if (!_this.state.observerInitialized) {
2602
+ _this.startObserver(event);
2603
+ }
2604
+ });
2605
+
2606
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "handleIntersection", function (entries) {
2607
+ var _this$videoRef;
2608
+
2609
+ if (!((_this$videoRef = _this.videoRef) !== null && _this$videoRef !== void 0 && _this$videoRef.current)) return;
2610
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.videoRef.current.play();else _this.videoRef.current.pause();
2558
2611
  });
2559
2612
 
2560
2613
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPauseCallback", function (event) {
@@ -2586,13 +2639,15 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2586
2639
  });
2587
2640
 
2588
2641
  _this.state = {
2589
- showVideo: false
2642
+ showVideo: false,
2643
+ observerInitialized: false
2590
2644
  };
2591
2645
  _this.opts = {
2592
2646
  playerVars: {
2593
2647
  autoplay: 0
2594
2648
  }
2595
2649
  };
2650
+ _this.videoRef = /*#__PURE__*/React__default["default"].createRef();
2596
2651
  return _this;
2597
2652
  }
2598
2653
 
@@ -2607,6 +2662,20 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2607
2662
  key: "componentWillUnmount",
2608
2663
  value: function componentWillUnmount() {
2609
2664
  this._isMounted = false;
2665
+
2666
+ if (this.intersectionObserver) {
2667
+ this.intersectionObserver.disconnect();
2668
+ }
2669
+ }
2670
+ }, {
2671
+ key: "startObserver",
2672
+ value: function startObserver(event) {
2673
+ this.videoRef.current = event.target;
2674
+ this.intersectionObserver = new IntersectionObserver(this.handleIntersection, {
2675
+ threshold: 0.75
2676
+ });
2677
+ this.intersectionObserver.observe(this.videoRef.current);
2678
+ this.state.observerInitialized = true;
2610
2679
  }
2611
2680
  }, {
2612
2681
  key: "render",
@@ -2623,7 +2692,9 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2623
2692
  onPlay: _this2.onPlayCallback,
2624
2693
  onPause: _this2.onPauseCallback,
2625
2694
  onEnd: _this2.onEndCallback,
2626
- autoplay: true
2695
+ onAdStart: _this2.onAdStart,
2696
+ autoplay: true,
2697
+ ref: _this2.videoRef
2627
2698
  });
2628
2699
  };
2629
2700
 
@@ -2648,7 +2719,10 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
2648
2719
  opts: this.opts,
2649
2720
  onPlay: this.onPlayCallback,
2650
2721
  onPause: this.onPauseCallback,
2651
- onEnd: this.onEndCallback
2722
+ onEnd: this.onEndCallback,
2723
+ onAdStart: this.onAdStart,
2724
+ autoplay: false,
2725
+ ref: this.videoRef
2652
2726
  });
2653
2727
  } else return /*#__PURE__*/React__default["default"].createElement("div", null);
2654
2728
  }
@@ -2689,6 +2763,10 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2689
2763
  });
2690
2764
  });
2691
2765
 
2766
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "handleIntersection", function (entries) {
2767
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.state.dmPlayer.play();else _this.state.dmPlayer.pause();
2768
+ });
2769
+
2692
2770
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "addScript", function () {
2693
2771
  var _this$props$element$m = _this.props.element.metadata,
2694
2772
  videoId = _this$props$element$m["video-id"],
@@ -2698,11 +2776,31 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2698
2776
  script.dataset.video = videoId;
2699
2777
 
2700
2778
  _this.containerRef.current.appendChild(script);
2779
+
2780
+ script.onload = function () {
2781
+ _this.setState({
2782
+ scriptLoaded: true
2783
+ });
2784
+
2785
+ window.dailymotion.createPlayer(_this.containerRef.current.id, {
2786
+ video: videoId,
2787
+ player: playerId
2788
+ }).then(function (player) {
2789
+ _this.setState({
2790
+ dmPlayer: player
2791
+ });
2792
+ })["catch"](function (e) {
2793
+ return console.error("dm--error", e);
2794
+ });
2795
+ };
2701
2796
  });
2702
2797
 
2703
2798
  _this.containerRef = /*#__PURE__*/React__default["default"].createRef();
2799
+ _this.observerRef = /*#__PURE__*/React__default["default"].createRef();
2704
2800
  _this.state = {
2705
- showVideo: false
2801
+ showVideo: false,
2802
+ scriptLoaded: false,
2803
+ dmPlayer: null
2706
2804
  };
2707
2805
  return _this;
2708
2806
  }
@@ -2714,6 +2812,31 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2714
2812
  this.addScript();
2715
2813
  }
2716
2814
  }
2815
+ }, {
2816
+ key: "startObserver",
2817
+ value: function startObserver() {
2818
+ this.intersectionObserver = new IntersectionObserver(this.handleIntersection, {
2819
+ threshold: 0.75
2820
+ });
2821
+ this.intersectionObserver.observe(this.observerRef.current);
2822
+ }
2823
+ }, {
2824
+ key: "componentDidUpdate",
2825
+ value: function componentDidUpdate() {
2826
+ var _this2 = this;
2827
+
2828
+ if (!this.observerRef.current) return;
2829
+ if (!this.state.dmPlayer) return;
2830
+ if (!this.state.scriptLoaded) return;
2831
+ this.state.dmPlayer.on("start", function () {
2832
+ return _this2.startObserver();
2833
+ });
2834
+ }
2835
+ }, {
2836
+ key: "componentWillUnmount",
2837
+ value: function componentWillUnmount() {
2838
+ if (this.observerRef.current) this.intersectionObserver.disconnect();
2839
+ }
2717
2840
  }, {
2718
2841
  key: "render",
2719
2842
  value: function render() {
@@ -2732,14 +2855,20 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
2732
2855
  src: "https://www.dailymotion.com/thumbnail/video/".concat(videoId),
2733
2856
  alt: "daily-motion-video"
2734
2857
  })), this.state.showVideo && /*#__PURE__*/React__default["default"].createElement("div", {
2858
+ ref: this.observerRef
2859
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2735
2860
  className: "dailymotion-embed-wrapper dm-embed-integration",
2736
- ref: this.containerRef
2737
- }));
2861
+ ref: this.containerRef,
2862
+ id: "dm-embed-container-id-".concat(videoId)
2863
+ })));
2738
2864
  } else if (!this.props.loadIframeOnClick) {
2739
2865
  return /*#__PURE__*/React__default["default"].createElement("div", {
2866
+ ref: this.observerRef
2867
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2740
2868
  className: "dailymotion-embed-wrapper dm-embed-integration",
2741
- ref: this.containerRef
2742
- });
2869
+ ref: this.containerRef,
2870
+ id: "dm-embed-container-id-".concat(videoId)
2871
+ }));
2743
2872
  }
2744
2873
  }
2745
2874
  }]);
@@ -3104,6 +3233,19 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3104
3233
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "onPlayerReady", function (event) {
3105
3234
  event.target.setVolume(100);
3106
3235
  event.target.playVideo();
3236
+ _this.videoRef.current = event.target;
3237
+ _this.intersectionObserver = new IntersectionObserver(_this.handleIntersection, {
3238
+ threshold: 0.75
3239
+ });
3240
+
3241
+ _this.intersectionObserver.observe(_this.videoRef.current.getIframe());
3242
+ });
3243
+
3244
+ _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "handleIntersection", function (entries) {
3245
+ var _this$videoRef;
3246
+
3247
+ if (!((_this$videoRef = _this.videoRef) !== null && _this$videoRef !== void 0 && _this$videoRef.current)) return;
3248
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.videoRef.current.playVideo();else _this.videoRef.current.pauseVideo();
3107
3249
  });
3108
3250
 
3109
3251
  _defineProperty__default["default"](_assertThisInitialized__default["default"](_this), "renderVideo", function () {
@@ -3122,6 +3264,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3122
3264
  autoplay: 0
3123
3265
  }
3124
3266
  };
3267
+ _this.videoRef = /*#__PURE__*/React__default["default"].createRef();
3125
3268
  return _this;
3126
3269
  }
3127
3270
 
@@ -3136,6 +3279,10 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3136
3279
  key: "componentWillUnmount",
3137
3280
  value: function componentWillUnmount() {
3138
3281
  this._isMounted = false;
3282
+
3283
+ if (this.intersectionObserver) {
3284
+ this.intersectionObserver.disconnect();
3285
+ }
3139
3286
  }
3140
3287
  }, {
3141
3288
  key: "render",
@@ -3149,7 +3296,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3149
3296
  onPlay: _this2.onPlayCallback,
3150
3297
  onPause: _this2.onPauseCallback,
3151
3298
  onEnd: _this2.onEndCallback,
3152
- onReady: _this2.onPlayerReady
3299
+ onReady: _this2.onPlayerReady,
3300
+ ref: _this2.videoRef
3153
3301
  });
3154
3302
  };
3155
3303
 
@@ -3174,7 +3322,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
3174
3322
  opts: this.opts,
3175
3323
  onPlay: this.onPlayCallback,
3176
3324
  onPause: this.onPauseCallback,
3177
- onEnd: this.onEndCallback
3325
+ onEnd: this.onEndCallback,
3326
+ ref: this.videoRef
3178
3327
  });
3179
3328
  } else return /*#__PURE__*/React__default["default"].createElement("div", null);
3180
3329
  }
@@ -5163,11 +5312,10 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
5163
5312
 
5164
5313
  case 3:
5165
5314
  jwtResponse = _context8.sent;
5166
- console.log("\n\n*** jwtResponse >> ", jwtResponse, "\n\n");
5167
- _context8.next = 7;
5315
+ _context8.next = 6;
5168
5316
  return awaitHelper(_this.setUser(_this.props.email, _this.props.phone, jwtResponse.headers.get("x-integration-token"), !!jwtResponse.headers.get("x-integration-token")));
5169
5317
 
5170
- case 7:
5318
+ case 6:
5171
5319
  _yield$awaitHelper7 = _context8.sent;
5172
5320
  error = _yield$awaitHelper7.error;
5173
5321
 
@@ -5196,7 +5344,7 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
5196
5344
  }
5197
5345
  }
5198
5346
 
5199
- case 10:
5347
+ case 9:
5200
5348
  case "end":
5201
5349
  return _context8.stop();
5202
5350
  }
@@ -433,11 +433,10 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
433
433
 
434
434
  case 3:
435
435
  jwtResponse = _context8.sent;
436
- console.log("\n\n*** jwtResponse >> ", jwtResponse, "\n\n");
437
- _context8.next = 7;
436
+ _context8.next = 6;
438
437
  return awaitHelper(_this.setUser(_this.props.email, _this.props.phone, jwtResponse.headers.get("x-integration-token"), !!jwtResponse.headers.get("x-integration-token")));
439
438
 
440
- case 7:
439
+ case 6:
441
440
  _yield$awaitHelper7 = _context8.sent;
442
441
  error = _yield$awaitHelper7.error;
443
442
 
@@ -466,7 +465,7 @@ var AccessTypeBase = /*#__PURE__*/function (_React$Component) {
466
465
  }
467
466
  }
468
467
 
469
- case 10:
468
+ case 9:
470
469
  case "end":
471
470
  return _context8.stop();
472
471
  }
@@ -3,7 +3,7 @@ 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
7
  import { WithLazy } from "../with-lazy";
8
8
 
9
9
  var BrightcoveElement = function BrightcoveElement(props) {
@@ -30,6 +30,23 @@ var BrightcoveElement = function BrightcoveElement(props) {
30
30
  posterImage = _useState4[0],
31
31
  setPosterImage = _useState4[1];
32
32
 
33
+ var _useState5 = useState(null),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ myPlayer = _useState6[0],
36
+ setMyPlayer = _useState6[1];
37
+
38
+ var _useState7 = useState(null),
39
+ _useState8 = _slicedToArray(_useState7, 2),
40
+ observer = _useState8[0],
41
+ setObserver = _useState8[1];
42
+
43
+ var _useState9 = useState(false),
44
+ _useState10 = _slicedToArray(_useState9, 2),
45
+ thumbnailClicked = _useState10[0],
46
+ setThumbnailClicked = _useState10[1];
47
+
48
+ var videoRef = useRef();
49
+
33
50
  var loadLibrary = function loadLibrary() {
34
51
  var _window;
35
52
 
@@ -53,11 +70,34 @@ var BrightcoveElement = function BrightcoveElement(props) {
53
70
  loadLibrary();
54
71
  }
55
72
  }, [loadIframeOnClick]);
73
+ useEffect(function () {
74
+ if (!myPlayer) return;
75
+ myPlayer.on("play", startObserver);
76
+ if (thumbnailClicked) myPlayer.play();
77
+ return function () {
78
+ myPlayer && myPlayer.off("play");
79
+ observer && observer.disconnect();
80
+ };
81
+ }, [myPlayer, thumbnailClicked]);
82
+
83
+ function handleIntersection(entries) {
84
+ if (!(entries !== null && entries !== void 0 && entries[0])) return;
85
+ if (entries[0].isIntersecting) myPlayer.play();else myPlayer.pause();
86
+ }
87
+
88
+ function startObserver() {
89
+ var intersectionObserver = new IntersectionObserver(function (entries) {
90
+ return handleIntersection(entries);
91
+ }, {
92
+ threshold: 0.75
93
+ });
94
+ intersectionObserver.observe(videoRef.current);
95
+ setObserver(intersectionObserver);
96
+ }
56
97
 
57
98
  var brightcoveIframe = function brightcoveIframe() {
58
99
  var _window2;
59
100
 
60
- var autoplay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
61
101
  var BrightcovePlayerLoader = (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.BrightcovePlayerLoader;
62
102
  return /*#__PURE__*/React.createElement(BrightcovePlayerLoader, {
63
103
  accountId: accountId,
@@ -67,13 +107,7 @@ var BrightcoveElement = function BrightcoveElement(props) {
67
107
  className: "brightcove-player"
68
108
  },
69
109
  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
- }
110
+ return setMyPlayer(success.ref);
77
111
  },
78
112
  onFailure: function onFailure() {
79
113
  return console.log("brightcove failed to load");
@@ -131,17 +165,20 @@ var BrightcoveElement = function BrightcoveElement(props) {
131
165
  }
132
166
 
133
167
  return /*#__PURE__*/React.createElement("div", {
134
- className: "brightcove-wrapper"
168
+ className: "brightcove-wrapper",
169
+ ref: videoRef
135
170
  }, !showVideo && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
136
171
  className: "brightcove-playBtn",
137
172
  onClick: function onClick() {
138
- return loadLibrary();
173
+ loadLibrary();
174
+ setThumbnailClicked(true);
139
175
  },
140
176
  "aria-label": "Play Video"
141
177
  }), posterImage ? /*#__PURE__*/React.createElement("img", {
142
178
  className: "brightcove-poster",
143
179
  onClick: function onClick() {
144
- return loadLibrary();
180
+ loadLibrary();
181
+ setThumbnailClicked(true);
145
182
  },
146
183
  src: posterImage,
147
184
  alt: "video"
@@ -150,7 +187,8 @@ var BrightcoveElement = function BrightcoveElement(props) {
150
187
  })), showVideo && ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.BrightcovePlayerLoader) && brightcoveIframe(true));
151
188
  } else if (!loadIframeOnClick && (_window4 = window) !== null && _window4 !== void 0 && _window4.BrightcovePlayerLoader) {
152
189
  return /*#__PURE__*/React.createElement("div", {
153
- className: "brightcove-wrapper"
190
+ className: "brightcove-wrapper",
191
+ ref: videoRef
154
192
  }, brightcoveIframe());
155
193
  } else {
156
194
  return null;
@@ -33,6 +33,10 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
33
33
  });
34
34
  });
35
35
 
36
+ _defineProperty(_assertThisInitialized(_this), "handleIntersection", function (entries) {
37
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.state.dmPlayer.play();else _this.state.dmPlayer.pause();
38
+ });
39
+
36
40
  _defineProperty(_assertThisInitialized(_this), "addScript", function () {
37
41
  var _this$props$element$m = _this.props.element.metadata,
38
42
  videoId = _this$props$element$m["video-id"],
@@ -42,11 +46,31 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
42
46
  script.dataset.video = videoId;
43
47
 
44
48
  _this.containerRef.current.appendChild(script);
49
+
50
+ script.onload = function () {
51
+ _this.setState({
52
+ scriptLoaded: true
53
+ });
54
+
55
+ window.dailymotion.createPlayer(_this.containerRef.current.id, {
56
+ video: videoId,
57
+ player: playerId
58
+ }).then(function (player) {
59
+ _this.setState({
60
+ dmPlayer: player
61
+ });
62
+ })["catch"](function (e) {
63
+ return console.error("dm--error", e);
64
+ });
65
+ };
45
66
  });
46
67
 
47
68
  _this.containerRef = /*#__PURE__*/React.createRef();
69
+ _this.observerRef = /*#__PURE__*/React.createRef();
48
70
  _this.state = {
49
- showVideo: false
71
+ showVideo: false,
72
+ scriptLoaded: false,
73
+ dmPlayer: null
50
74
  };
51
75
  return _this;
52
76
  }
@@ -58,6 +82,31 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
58
82
  this.addScript();
59
83
  }
60
84
  }
85
+ }, {
86
+ key: "startObserver",
87
+ value: function startObserver() {
88
+ this.intersectionObserver = new IntersectionObserver(this.handleIntersection, {
89
+ threshold: 0.75
90
+ });
91
+ this.intersectionObserver.observe(this.observerRef.current);
92
+ }
93
+ }, {
94
+ key: "componentDidUpdate",
95
+ value: function componentDidUpdate() {
96
+ var _this2 = this;
97
+
98
+ if (!this.observerRef.current) return;
99
+ if (!this.state.dmPlayer) return;
100
+ if (!this.state.scriptLoaded) return;
101
+ this.state.dmPlayer.on("start", function () {
102
+ return _this2.startObserver();
103
+ });
104
+ }
105
+ }, {
106
+ key: "componentWillUnmount",
107
+ value: function componentWillUnmount() {
108
+ if (this.observerRef.current) this.intersectionObserver.disconnect();
109
+ }
61
110
  }, {
62
111
  key: "render",
63
112
  value: function render() {
@@ -76,14 +125,20 @@ var DailyMotion = /*#__PURE__*/function (_React$Component) {
76
125
  src: "https://www.dailymotion.com/thumbnail/video/".concat(videoId),
77
126
  alt: "daily-motion-video"
78
127
  })), this.state.showVideo && /*#__PURE__*/React.createElement("div", {
128
+ ref: this.observerRef
129
+ }, /*#__PURE__*/React.createElement("div", {
79
130
  className: "dailymotion-embed-wrapper dm-embed-integration",
80
- ref: this.containerRef
81
- }));
131
+ ref: this.containerRef,
132
+ id: "dm-embed-container-id-".concat(videoId)
133
+ })));
82
134
  } else if (!this.props.loadIframeOnClick) {
83
135
  return /*#__PURE__*/React.createElement("div", {
136
+ ref: this.observerRef
137
+ }, /*#__PURE__*/React.createElement("div", {
84
138
  className: "dailymotion-embed-wrapper dm-embed-integration",
85
- ref: this.containerRef
86
- });
139
+ ref: this.containerRef,
140
+ id: "dm-embed-container-id-".concat(videoId)
141
+ }));
87
142
  }
88
143
  }
89
144
  }]);
@@ -48,8 +48,23 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
48
48
 
49
49
  _this = _super.call(this, props);
50
50
 
51
+ _defineProperty(_assertThisInitialized(_this), "onAdStart", function (event) {
52
+ _this.startObserver(event);
53
+ });
54
+
51
55
  _defineProperty(_assertThisInitialized(_this), "onPlayCallback", function (event) {
52
56
  _this.props.onPlay === "function" && _this.props.onPlay(event);
57
+
58
+ if (!_this.state.observerInitialized) {
59
+ _this.startObserver(event);
60
+ }
61
+ });
62
+
63
+ _defineProperty(_assertThisInitialized(_this), "handleIntersection", function (entries) {
64
+ var _this$videoRef;
65
+
66
+ if (!((_this$videoRef = _this.videoRef) !== null && _this$videoRef !== void 0 && _this$videoRef.current)) return;
67
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.videoRef.current.play();else _this.videoRef.current.pause();
53
68
  });
54
69
 
55
70
  _defineProperty(_assertThisInitialized(_this), "onPauseCallback", function (event) {
@@ -81,13 +96,15 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
81
96
  });
82
97
 
83
98
  _this.state = {
84
- showVideo: false
99
+ showVideo: false,
100
+ observerInitialized: false
85
101
  };
86
102
  _this.opts = {
87
103
  playerVars: {
88
104
  autoplay: 0
89
105
  }
90
106
  };
107
+ _this.videoRef = /*#__PURE__*/React.createRef();
91
108
  return _this;
92
109
  }
93
110
 
@@ -102,6 +119,20 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
102
119
  key: "componentWillUnmount",
103
120
  value: function componentWillUnmount() {
104
121
  this._isMounted = false;
122
+
123
+ if (this.intersectionObserver) {
124
+ this.intersectionObserver.disconnect();
125
+ }
126
+ }
127
+ }, {
128
+ key: "startObserver",
129
+ value: function startObserver(event) {
130
+ this.videoRef.current = event.target;
131
+ this.intersectionObserver = new IntersectionObserver(this.handleIntersection, {
132
+ threshold: 0.75
133
+ });
134
+ this.intersectionObserver.observe(this.videoRef.current);
135
+ this.state.observerInitialized = true;
105
136
  }
106
137
  }, {
107
138
  key: "render",
@@ -118,7 +149,9 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
118
149
  onPlay: _this2.onPlayCallback,
119
150
  onPause: _this2.onPauseCallback,
120
151
  onEnd: _this2.onEndCallback,
121
- autoplay: true
152
+ onAdStart: _this2.onAdStart,
153
+ autoplay: true,
154
+ ref: _this2.videoRef
122
155
  });
123
156
  };
124
157
 
@@ -143,7 +176,10 @@ var CustomStoryElementDailyMotion = /*#__PURE__*/function (_React$Component) {
143
176
  opts: this.opts,
144
177
  onPlay: this.onPlayCallback,
145
178
  onPause: this.onPauseCallback,
146
- onEnd: this.onEndCallback
179
+ onEnd: this.onEndCallback,
180
+ onAdStart: this.onAdStart,
181
+ autoplay: false,
182
+ ref: this.videoRef
147
183
  });
148
184
  } else return /*#__PURE__*/React.createElement("div", null);
149
185
  }
@@ -106,6 +106,19 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
106
106
  _defineProperty(_assertThisInitialized(_this), "onPlayerReady", function (event) {
107
107
  event.target.setVolume(100);
108
108
  event.target.playVideo();
109
+ _this.videoRef.current = event.target;
110
+ _this.intersectionObserver = new IntersectionObserver(_this.handleIntersection, {
111
+ threshold: 0.75
112
+ });
113
+
114
+ _this.intersectionObserver.observe(_this.videoRef.current.getIframe());
115
+ });
116
+
117
+ _defineProperty(_assertThisInitialized(_this), "handleIntersection", function (entries) {
118
+ var _this$videoRef;
119
+
120
+ if (!((_this$videoRef = _this.videoRef) !== null && _this$videoRef !== void 0 && _this$videoRef.current)) return;
121
+ if (entries !== null && entries !== void 0 && entries[0].isIntersecting) _this.videoRef.current.playVideo();else _this.videoRef.current.pauseVideo();
109
122
  });
110
123
 
111
124
  _defineProperty(_assertThisInitialized(_this), "renderVideo", function () {
@@ -124,6 +137,7 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
124
137
  autoplay: 0
125
138
  }
126
139
  };
140
+ _this.videoRef = /*#__PURE__*/React.createRef();
127
141
  return _this;
128
142
  }
129
143
 
@@ -138,6 +152,10 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
138
152
  key: "componentWillUnmount",
139
153
  value: function componentWillUnmount() {
140
154
  this._isMounted = false;
155
+
156
+ if (this.intersectionObserver) {
157
+ this.intersectionObserver.disconnect();
158
+ }
141
159
  }
142
160
  }, {
143
161
  key: "render",
@@ -151,7 +169,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
151
169
  onPlay: _this2.onPlayCallback,
152
170
  onPause: _this2.onPauseCallback,
153
171
  onEnd: _this2.onEndCallback,
154
- onReady: _this2.onPlayerReady
172
+ onReady: _this2.onPlayerReady,
173
+ ref: _this2.videoRef
155
174
  });
156
175
  };
157
176
 
@@ -176,7 +195,8 @@ var CustomStoryElementYoutube = /*#__PURE__*/function (_React$Component) {
176
195
  opts: this.opts,
177
196
  onPlay: this.onPlayCallback,
178
197
  onPause: this.onPauseCallback,
179
- onEnd: this.onEndCallback
198
+ onEnd: this.onEndCallback,
199
+ ref: this.videoRef
180
200
  });
181
201
  } else return /*#__PURE__*/React.createElement("div", null);
182
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/components",
3
- "version": "3.4.4-debug.0",
3
+ "version": "3.4.4-infiniteScroll-videos.2",
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",