@realsee/vreo 2.6.4-alpha.1 → 2.6.4-alpha.3

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.
Files changed (136) hide show
  1. package/lib/PlayController/createHTMLAudioElement.js +10 -14
  2. package/lib/PlayController/index.js +63 -73
  3. package/lib/Player/App.js +2 -2
  4. package/lib/Player/Controller.d.ts +7 -1
  5. package/lib/Player/Controller.js +112 -75
  6. package/lib/Player/PlaybackLifecycle.d.ts +25 -0
  7. package/lib/Player/PlaybackLifecycle.js +117 -0
  8. package/lib/Player/custom/SpatialScenePanel/index.js +34 -11
  9. package/lib/Player/index.d.ts +7 -2
  10. package/lib/Player/index.js +198 -126
  11. package/lib/Player/modules/Drawer/index.js +1 -2
  12. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +13 -1
  13. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +209 -204
  14. package/lib/Player/modules/VideoAgent/VideoAgentScene.d.ts +1 -0
  15. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +6 -2
  16. package/lib/Player/modules/VideoAgent/index.js +10 -2
  17. package/lib/Player/modules/keyframes/BgMusic/index.js +50 -74
  18. package/lib/Player/modules/keyframes/CameraMovement/index.js +43 -45
  19. package/lib/Player/modules/keyframes/InfoPanel/index.js +45 -35
  20. package/lib/Player/modules/keyframes/ModelVideo/index.js +95 -57
  21. package/lib/Player/modules/keyframes/PanoTag/index.js +4 -2
  22. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +3 -3
  23. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +3 -3
  24. package/lib/Player/modules/keyframes/VideoEffect/index.js +93 -79
  25. package/lib/Player/playback-types.d.ts +21 -0
  26. package/lib/Player/playback-types.js +1 -0
  27. package/lib/Player/typings.d.ts +3 -0
  28. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +6 -6
  29. package/lib/fivePlugins/CameraMovementPlugin/index.js +173 -180
  30. package/lib/fivePlugins/CameraMovementPlugin/typings.js +6 -6
  31. package/lib/fivePlugins/ModelTVVideoPlugin/index.d.ts +3 -0
  32. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +182 -75
  33. package/lib/index.d.ts +1 -0
  34. package/lib/react/index.js +1 -1
  35. package/lib/shared-utils/Audio.js +55 -57
  36. package/lib/shared-utils/AudioLike.js +12 -14
  37. package/lib/shared-utils/animationFrame/BetterTween.js +13 -15
  38. package/lib/shared-utils/animationFrame/tween.js +1 -3
  39. package/lib/shared-utils/getMediaInfo.js +0 -1
  40. package/lib/typings/VreoUnit.js +134 -27
  41. package/package.json +6 -4
  42. package/docs/.nojekyll +0 -1
  43. package/docs/assets/custom.css +0 -78
  44. package/docs/assets/hierarchy.js +0 -1
  45. package/docs/assets/highlight.css +0 -127
  46. package/docs/assets/icons.js +0 -18
  47. package/docs/assets/icons.svg +0 -1
  48. package/docs/assets/main.js +0 -60
  49. package/docs/assets/navigation.js +0 -1
  50. package/docs/assets/search.js +0 -1
  51. package/docs/assets/style.css +0 -1640
  52. package/docs/classes/Player.AudioLike.html +0 -15
  53. package/docs/classes/Player.Controller.html +0 -87
  54. package/docs/classes/Player.Player.html +0 -54
  55. package/docs/classes/Player.VideoAgentMesh.html +0 -72
  56. package/docs/classes/Player.VideoAgentScene.html +0 -9
  57. package/docs/demo/assets/AppReact-CkuqZtcS.js +0 -1
  58. package/docs/demo/assets/default-BQGCQRLt.css +0 -1
  59. package/docs/demo/assets/default-CVvVdmSW.js +0 -5540
  60. package/docs/demo/assets/dynamic-CO5wq52h.js +0 -1
  61. package/docs/demo/assets/examples-BCLzFApO.css +0 -1
  62. package/docs/demo/assets/examples-DfiAz2fR.js +0 -25
  63. package/docs/demo/assets/index-CBBSwaYT.js +0 -1
  64. package/docs/demo/assets/index-CmEXi2sK.css +0 -1
  65. package/docs/demo/assets/main-BF1tvUg-.js +0 -25
  66. package/docs/demo/assets/react-BnzBLum3.css +0 -1
  67. package/docs/demo/assets/react-C4h9qndP.js +0 -25
  68. package/docs/demo/examples.html +0 -16
  69. package/docs/demo/index-react-dynamic.html +0 -18
  70. package/docs/demo/index-react.html +0 -19
  71. package/docs/demo/index.html +0 -19
  72. package/docs/enums/Player.InfoPanelStyleEnum.html +0 -3
  73. package/docs/enums/Player.InfoPanelTypeEnum.html +0 -4
  74. package/docs/enums/Player.PanoEffectEnum.html +0 -4
  75. package/docs/enums/Player.PanoTagEnum.html +0 -4
  76. package/docs/enums/Player.PanoTagStyleEnum.html +0 -6
  77. package/docs/enums/Player.VreoKeyframeEnum.html +0 -25
  78. package/docs/enums/fivePlugins.CameraMovementEffect.html +0 -3
  79. package/docs/enums/fivePlugins.Rotation.html +0 -4
  80. package/docs/functions/custom.SpatialScenePanel.html +0 -2
  81. package/docs/functions/react.useVreoAction.html +0 -8
  82. package/docs/functions/react.useVreoEventCallback.html +0 -10
  83. package/docs/functions/react.useVreoPausedState.html +0 -8
  84. package/docs/hierarchy.html +0 -1
  85. package/docs/index.html +0 -160
  86. package/docs/interfaces/Player.Appearance.html +0 -2
  87. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +0 -3
  88. package/docs/interfaces/Player.PlayerConfigs.html +0 -20
  89. package/docs/interfaces/Player.Vertex.html +0 -5
  90. package/docs/interfaces/Player.VideoAgentMeshOptions.html +0 -9
  91. package/docs/interfaces/Player.VreoKeyframe.html +0 -8
  92. package/docs/interfaces/Player.VreoUnit.html +0 -9
  93. package/docs/interfaces/Player.VreoVideo.html +0 -7
  94. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +0 -8
  95. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +0 -3
  96. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +0 -5
  97. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +0 -1
  98. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +0 -5
  99. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +0 -4
  100. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +0 -2
  101. package/docs/interfaces/fivePlugins.Vector3Position.html +0 -5
  102. package/docs/interfaces/react.VreoActionCallbacks.html +0 -18
  103. package/docs/interfaces/react.VreoProviderProps.html +0 -6
  104. package/docs/modules/Player.html +0 -1
  105. package/docs/modules/custom.html +0 -1
  106. package/docs/modules/fivePlugins.html +0 -1
  107. package/docs/modules/react.html +0 -1
  108. package/docs/modules.html +0 -1
  109. package/docs/types/Player.AppSize.html +0 -1
  110. package/docs/types/Player.AudioLikeEvent.html +0 -6
  111. package/docs/types/Player.CameraMovementData.html +0 -2
  112. package/docs/types/Player.CustomData.html +0 -2
  113. package/docs/types/Player.InfoPanelData.html +0 -7
  114. package/docs/types/Player.ModelVideoData.html +0 -9
  115. package/docs/types/Player.PanoEffectData.html +0 -4
  116. package/docs/types/Player.PanoTagData.html +0 -6
  117. package/docs/types/Player.PanoTextLabelData.html +0 -7
  118. package/docs/types/Player.PrompterData.html +0 -3
  119. package/docs/types/Player.QuadrangleVertexs.html +0 -2
  120. package/docs/types/Player.Quaternion.html +0 -6
  121. package/docs/types/Player.UpdateVRPanoramaData.html +0 -7
  122. package/docs/types/Player.Vertexs.html +0 -2
  123. package/docs/types/Player.VideoEffectData.html +0 -7
  124. package/docs/types/Player.VreoKeyframeEvent.html +0 -2
  125. package/docs/types/Player.VreoKeyframeMap.html +0 -6
  126. package/docs/types/Player.VreoSubscribe.html +0 -1
  127. package/docs/types/Player.WaveAppearance.html +0 -1
  128. package/docs/types/fivePlugins.CSS3DRenderPluginParameterType.html +0 -1
  129. package/docs/types/fivePlugins.MoveArgs.html +0 -1
  130. package/docs/types/fivePlugins.MoveOpts.html +0 -1
  131. package/docs/types/fivePlugins.RotateArgs.html +0 -1
  132. package/docs/types/fivePlugins.RotateOpts.html +0 -1
  133. package/docs/variables/fivePlugins.CSS3DRenderPlugin.html +0 -3
  134. package/docs/variables/fivePlugins.CameraMovementPlugin.html +0 -2
  135. package/docs/variables/fivePlugins.ModelTVVideoPlugin.html +0 -1
  136. package/docs/variables/react.VreoProvider.html +0 -9
@@ -1,13 +1,18 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _readOnlyError from "@babel/runtime/helpers/esm/readOnlyError";
2
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/esm/inherits";
6
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
6
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
- 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; } }
7
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
13
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
14
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
15
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
16
  import * as THREE from 'three';
12
17
  import { Preloader } from "../../../shared-utils/Preloader.js";
13
18
  import { makeObservable, observable, runInAction } from 'mobx';
@@ -17,7 +22,6 @@ var vertexShader = "\nvarying vec2 vUv;\nvarying vec2 vColorUv;\nvarying vec2 vM
17
22
  var fragmentShaderTpl = function fragmentShaderTpl() {
18
23
  return "\nuniform int enable;\nuniform sampler2D map;\nvarying vec2 vUv;\nvarying vec2 vColorUv;\nvarying vec2 vMaskUv;\n\nvec3 hsv2rgb(vec3 c) {\n const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\nvec3 rgb2hsv(vec3 c) {\n const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 0.001)), d / (q.x + 0.001), q.x);\n}\n\nvoid main(void) {\n vec3 color = texture2D(map, vUv).xyz;\n float amask = 1.0;\n\n float ref = color.r;\n if (ref < color.b) ref = color.b;\n amask = color.g - ref + 0.1;\n amask = smoothstep(0.1, 0.3, amask);\n amask = 1.0 - amask;\n\n vec3 target = rgb2hsv(vec3(0.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0));\n vec3 hsv = rgb2hsv(color);\n float distance = abs(hsv.x - target.x);\n if (distance < 0.15) {\n hsv.y = 0.0;\n }\n color = hsv2rgb(hsv);\n\n gl_FragColor = vec4(color.rgb, amask * float(enable));\n}\n";
19
24
  };
20
- var cacheInstance = {};
21
25
 
22
26
  /**
23
27
  * 视频经纪人贴片的配置选项
@@ -53,8 +57,6 @@ var cacheInstance = {};
53
57
  * ```
54
58
  */
55
59
  export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
56
- _inherits(VideoAgentMesh, _THREE$Mesh);
57
- var _super = _createSuper(VideoAgentMesh);
58
60
  /**
59
61
  * 创建视频经纪人贴片实例
60
62
  *
@@ -79,20 +81,14 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
79
81
  preload: true
80
82
  };
81
83
  _classCallCheck(this, VideoAgentMesh);
84
+ var ownsVideo = !options.videoInstance;
82
85
  if (!options.videoInstance) {
83
- if (cacheInstance.videoInstance) {
84
- options.videoInstance = cacheInstance.videoInstance;
85
- } else {
86
- var videoInstance = document.createElement('video');
87
- videoInstance.style.opacity = '0';
88
- videoInstance.style.pointerEvents = 'none';
89
- videoInstance.style.display = 'none';
90
- document.body.append(videoInstance);
91
- options.videoInstance = videoInstance;
92
- cacheInstance.videoInstance = videoInstance;
93
- videoInstance.playsInline = true;
94
- videoInstance.controls = false;
95
- }
86
+ var videoInstance = document.createElement('video');
87
+ videoInstance.style.display = 'none';
88
+ videoInstance.playsInline = true;
89
+ videoInstance.muted = true;
90
+ document.body.append(videoInstance);
91
+ options.videoInstance = videoInstance;
96
92
  }
97
93
  var geometry = new THREE.PlaneGeometry(width, height, widthSegments, heightSegments);
98
94
  var videoTexture = new THREE.VideoTexture(options.videoInstance);
@@ -109,29 +105,31 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
109
105
  fragmentShader: fragmentShaderTpl(),
110
106
  transparent: true
111
107
  });
112
- _this = _super.call(this, geometry, material);
108
+ _this = _callSuper(this, VideoAgentMesh, [geometry, material]);
109
+ /** 配置选项 */
110
+ /** 当前视频URL */
111
+ /** 是否冻结状态 */
112
+ /** 是否暂停状态 */
113
+ /** 音频实例 */
114
+ _defineProperty(_this, "outputs", new Map());
115
+ _defineProperty(_this, "ownsVideo", false);
116
+ _defineProperty(_this, "ownsAudio", false);
117
+ _defineProperty(_this, "generation", 0);
118
+ _this.ownsVideo = ownsVideo;
119
+ _this.ownsAudio = !options.audioInstance;
113
120
  _this.options = options;
114
121
  _this.freeze = false;
115
122
  _this.paused = true;
116
123
  if (!options.audioInstance) {
117
- if (cacheInstance.audioInstance) {
118
- _this.audioInstance = cacheInstance.audioInstance;
119
- } else {
120
- var audioInstance = document.createElement('audio');
121
- audioInstance.crossOrigin = '';
122
- // videoInstance.muted = true
123
- audioInstance.muted = false;
124
- audioInstance.autoplay = false;
125
- audioInstance.style.display = 'none';
126
- document.body.appendChild(audioInstance);
127
- _this.audioInstance = audioInstance;
128
- cacheInstance.audioInstance = audioInstance;
129
- }
124
+ _this.audioInstance = document.createElement('audio');
125
+ _this.audioInstance.crossOrigin = '';
126
+ _this.audioInstance.muted = true;
127
+ _this.audioInstance.autoplay = false;
130
128
  } else {
131
129
  _this.audioInstance = options.audioInstance;
132
130
  }
133
131
  _this.audioLikeInstance = new AudioLike();
134
- makeObservable(_assertThisInitialized(_this), {
132
+ makeObservable(_this, {
135
133
  paused: observable
136
134
  });
137
135
  var updatePaused = function updatePaused(paused) {
@@ -147,16 +145,16 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
147
145
  };
148
146
  _this.audioInstance.addEventListener('pause', onPause);
149
147
  _this.audioInstance.addEventListener('play', onPlay);
150
- (_this$options$videoIn = _this.options.videoInstance) === null || _this$options$videoIn === void 0 ? void 0 : _this$options$videoIn.addEventListener('pause', onPause);
151
- (_this$options$videoIn2 = _this.options.videoInstance) === null || _this$options$videoIn2 === void 0 ? void 0 : _this$options$videoIn2.addEventListener('play', onPlay);
148
+ (_this$options$videoIn = _this.options.videoInstance) === null || _this$options$videoIn === void 0 || _this$options$videoIn.addEventListener('pause', onPause);
149
+ (_this$options$videoIn2 = _this.options.videoInstance) === null || _this$options$videoIn2 === void 0 || _this$options$videoIn2.addEventListener('play', onPlay);
152
150
  _this.audioLikeInstance.addEventListener('pause', onPause);
153
151
  _this.audioLikeInstance.addEventListener('play', onPlay);
154
152
  _this.$removeEventListener = function () {
155
153
  var _this$options$videoIn3, _this$options$videoIn4;
156
154
  _this.audioInstance.removeEventListener('pause', onPause);
157
155
  _this.audioInstance.removeEventListener('play', onPlay);
158
- (_this$options$videoIn3 = _this.options.videoInstance) === null || _this$options$videoIn3 === void 0 ? void 0 : _this$options$videoIn3.removeEventListener('pause', onPause);
159
- (_this$options$videoIn4 = _this.options.videoInstance) === null || _this$options$videoIn4 === void 0 ? void 0 : _this$options$videoIn4.removeEventListener('play', onPlay);
156
+ (_this$options$videoIn3 = _this.options.videoInstance) === null || _this$options$videoIn3 === void 0 || _this$options$videoIn3.removeEventListener('pause', onPause);
157
+ (_this$options$videoIn4 = _this.options.videoInstance) === null || _this$options$videoIn4 === void 0 || _this$options$videoIn4.removeEventListener('play', onPlay);
160
158
  _this.audioLikeInstance.removeEventListener('pause', onPause);
161
159
  _this.audioLikeInstance.removeEventListener('play', onPlay);
162
160
  };
@@ -170,19 +168,17 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
170
168
  * @param videoUrl - 媒体文件URL
171
169
  * @private
172
170
  */
173
- _createClass(VideoAgentMesh, [{
171
+ _inherits(VideoAgentMesh, _THREE$Mesh);
172
+ return _createClass(VideoAgentMesh, [{
173
+ key: "operations",
174
+ value: function operations(run, element) {
175
+ var operations = run ? run.bind(element) : element;
176
+ this.outputs.set(element, operations);
177
+ return operations;
178
+ }
179
+ }, {
174
180
  key: "mediaInstance",
175
- get: /** 配置选项 */
176
-
177
- /** 当前视频URL */
178
-
179
- /** 是否冻结状态 */
180
-
181
- /** 是否暂停状态 */
182
-
183
- /** 音频实例 */
184
-
185
- /** AudioLike 实例 */
181
+ get: /** AudioLike 实例 */
186
182
 
187
183
  /** 移除事件监听器的函数 */
188
184
 
@@ -209,71 +205,69 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
209
205
  }
210
206
  }, {
211
207
  key: "update",
212
- value: function () {
213
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(videoUrl) {
208
+ value: (function () {
209
+ var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(videoUrl, valid, run) {
214
210
  var _this2 = this;
215
- var uniforms, onStart;
216
- return _regeneratorRuntime.wrap(function _callee$(_context) {
217
- while (1) {
218
- switch (_context.prev = _context.next) {
219
- case 0:
220
- if (!(this.videoUrl === videoUrl)) {
221
- _context.next = 2;
222
- break;
223
- }
224
- return _context.abrupt("return");
225
- case 2:
226
- this.videoUrl = videoUrl;
227
-
228
- // // 兼容非视频场景
229
- // if (this.mediaInstance instanceof HTMLAudioElement) {
230
- // this.mediaInstance.style.display = 'none'
231
- // } else if (this.mediaInstance instanceof HTMLVideoElement) {
232
- // this.mediaInstance.style.display = 'block'
233
- // }
234
-
235
- this.freeze = true;
236
- _context.next = 6;
237
- return this.mediaInstance.pause();
238
- case 6:
239
- uniforms = this.material.uniforms;
240
- this.mediaInstance.muted = true;
241
- if (!(this.options.preload || this.options.preload === undefined || getMediaType(this.videoUrl) === 'video')) {
242
- _context.next = 18;
243
- break;
244
- }
245
- _context.t1 = URL;
246
- _context.next = 12;
247
- return Preloader.blob(this.videoUrl);
248
- case 12:
249
- _context.t2 = _context.sent;
250
- _context.next = 15;
251
- return _context.t1.createObjectURL.call(_context.t1, _context.t2);
252
- case 15:
253
- _context.t0 = _context.sent;
254
- _context.next = 19;
211
+ var element, media, src, onStart, _t, _t2;
212
+ return _regenerator().w(function (_context) {
213
+ while (1) switch (_context.n) {
214
+ case 0:
215
+ if (!(this.videoUrl === videoUrl)) {
216
+ _context.n = 1;
217
+ break;
218
+ }
219
+ return _context.a(2);
220
+ case 1:
221
+ this.stop();
222
+ this.freeze = true;
223
+ element = getMediaType(videoUrl) === 'audio' ? this.audioInstance : this.options.videoInstance;
224
+ media = this.operations(run, element);
225
+ media.muted = true;
226
+ if (!(this.options.preload !== false || getMediaType(videoUrl) === 'video')) {
227
+ _context.n = 3;
228
+ break;
229
+ }
230
+ _t2 = URL;
231
+ _context.n = 2;
232
+ return Preloader.blob(videoUrl);
233
+ case 2:
234
+ _t = _t2.createObjectURL.call(_t2, _context.v);
235
+ _context.n = 4;
236
+ break;
237
+ case 3:
238
+ _t = videoUrl;
239
+ case 4:
240
+ src = _t;
241
+ if (valid()) {
242
+ _context.n = 5;
255
243
  break;
256
- case 18:
257
- _context.t0 = this.videoUrl;
258
- case 19:
259
- this.mediaInstance.src = _context.t0;
260
- this.mediaInstance.setAttribute('data-src', this.videoUrl);
261
- onStart = function onStart() {
262
- if (_this2.mediaInstance.currentTime === 0) return;
263
- _this2.freeze = false;
264
- _this2.mediaInstance.muted = false;
265
- uniforms.enable.value = getMediaType(_this2.videoUrl) ? 1 : 0;
266
- _this2.mediaInstance.removeEventListener('timeupdate', onStart, false);
267
- };
268
- this.mediaInstance.addEventListener('timeupdate', onStart, false);
269
- case 23:
270
- case "end":
271
- return _context.stop();
272
- }
244
+ }
245
+ if (src !== videoUrl) URL.revokeObjectURL(src);
246
+ return _context.a(2);
247
+ case 5:
248
+ this.videoUrl = videoUrl;
249
+ if (this.objectURL) URL.revokeObjectURL(this.objectURL);
250
+ this.objectURL = src !== videoUrl ? src : undefined;
251
+ media.src = src;
252
+ element.setAttribute('data-src', videoUrl);
253
+ onStart = function onStart() {
254
+ var _this2$removeStart;
255
+ if (!valid() || media.currentTime === 0) return;
256
+ _this2.freeze = false;
257
+ media.muted = false;
258
+ _this2.material.uniforms.enable.value = getMediaType(videoUrl) ? 1 : 0;
259
+ (_this2$removeStart = _this2.removeStart) === null || _this2$removeStart === void 0 || _this2$removeStart.call(_this2);
260
+ };
261
+ this.removeStart = function () {
262
+ return element.removeEventListener('timeupdate', onStart);
263
+ };
264
+ element.addEventListener('timeupdate', onStart);
265
+ case 6:
266
+ return _context.a(2);
273
267
  }
274
268
  }, _callee, this);
275
269
  }));
276
- function update(_x) {
270
+ function update(_x, _x2, _x3) {
277
271
  return _update.apply(this, arguments);
278
272
  }
279
273
  return update;
@@ -303,101 +297,114 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
303
297
  * await mesh.play()
304
298
  * ```
305
299
  */
300
+ )
306
301
  }, {
307
302
  key: "play",
308
- value: function () {
309
- var _play = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
310
- var _this3 = this;
303
+ value: (function () {
304
+ var _play = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
305
+ var _this$options$getPlay,
306
+ _this$options,
307
+ _this3 = this;
311
308
  var videoUrl,
312
309
  currentTime,
313
310
  duration,
314
- _args3 = arguments;
315
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
316
- while (1) {
317
- switch (_context3.prev = _context3.next) {
318
- case 0:
319
- videoUrl = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : '';
320
- currentTime = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 0;
321
- duration = _args3.length > 2 ? _args3[2] : undefined;
322
- videoUrl = videoUrl || '';
323
- if (!(duration && !videoUrl)) {
324
- _context3.next = 10;
325
- break;
326
- }
327
- if (this.currentTime) {
328
- this.mediaInstance.currentTime = currentTime;
329
- }
330
- this.mediaInstance.duration = duration;
311
+ run,
312
+ generation,
313
+ valid,
314
+ media,
315
+ _args2 = arguments;
316
+ return _regenerator().w(function (_context2) {
317
+ while (1) switch (_context2.n) {
318
+ case 0:
319
+ videoUrl = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
320
+ currentTime = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 0;
321
+ duration = _args2.length > 2 ? _args2[2] : undefined;
322
+ run = (_this$options$getPlay = (_this$options = this.options).getPlayback) === null || _this$options$getPlay === void 0 ? void 0 : _this$options$getPlay.call(_this$options);
323
+ if (!(this.options.getPlayback && !(run !== null && run !== void 0 && run.valid()))) {
324
+ _context2.n = 1;
325
+ break;
326
+ }
327
+ return _context2.a(2, false);
328
+ case 1:
329
+ // stop() invalidates all earlier loads before the new generation is captured.
330
+ if (videoUrl && videoUrl !== this.videoUrl) this.stop();
331
+ generation = this.generation;
332
+ valid = function valid() {
333
+ return generation === _this3.generation && (!_this3.options.getPlayback || !!(run !== null && run !== void 0 && run.valid()));
334
+ };
335
+ if (!(videoUrl && videoUrl !== this.videoUrl)) {
336
+ _context2.n = 2;
337
+ break;
338
+ }
339
+ // update's synchronous stop is accounted for before awaiting its load.
340
+ generation++;
341
+ _context2.n = 2;
342
+ return this.update(videoUrl, valid, run);
343
+ case 2:
344
+ if (valid()) {
345
+ _context2.n = 3;
346
+ break;
347
+ }
348
+ return _context2.a(2, false);
349
+ case 3:
350
+ if (duration && !videoUrl) {
331
351
  this.videoUrl = '';
332
- this.mediaInstance.play();
333
- return _context3.abrupt("return", true);
334
- case 10:
335
- if (videoUrl) {
336
- _context3.next = 18;
337
- break;
338
- }
339
- if (!this.videoUrl) {
340
- _context3.next = 16;
341
- break;
342
- }
343
- _context3.next = 14;
344
- return this.mediaInstance.play();
345
- case 14:
346
- _context3.next = 17;
352
+ this.audioLikeInstance.duration = duration;
353
+ }
354
+ media = this.videoUrl ? this.operations(run, this.mediaInstance) : this.audioLikeInstance;
355
+ if (videoUrl || duration) media.currentTime = currentTime;
356
+ media.muted = true;
357
+ _context2.n = 4;
358
+ return media.play();
359
+ case 4:
360
+ if (valid()) {
361
+ _context2.n = 5;
347
362
  break;
348
- case 16:
349
- console.warn('警告:视频资源未初始化。');
350
- case 17:
351
- return _context3.abrupt("return", true);
352
- case 18:
353
- if (!(videoUrl === this.videoUrl)) {
354
- _context3.next = 23;
355
- break;
356
- }
357
- this.mediaInstance.currentTime = currentTime;
358
- _context3.next = 22;
359
- return this.mediaInstance.play();
360
- case 22:
361
- return _context3.abrupt("return", true);
362
- case 23:
363
- _context3.next = 25;
364
- return this.update(videoUrl);
365
- case 25:
366
- this.mediaInstance.pause();
367
- _context3.next = 28;
368
- return new Promise(function (resolve) {
369
- return setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
370
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
371
- while (1) {
372
- switch (_context2.prev = _context2.next) {
373
- case 0:
374
- _this3.mediaInstance.currentTime = currentTime;
375
- _context2.next = 3;
376
- return _this3.mediaInstance.play();
377
- case 3:
378
- resolve(true);
379
- case 4:
380
- case "end":
381
- return _context2.stop();
382
- }
383
- }
384
- }, _callee2);
385
- })), 20);
386
- });
387
- case 28:
388
- return _context3.abrupt("return", _context3.sent);
389
- case 29:
390
- case "end":
391
- return _context3.stop();
392
- }
363
+ }
364
+ return _context2.a(2, false);
365
+ case 5:
366
+ media.muted = false;
367
+ return _context2.a(2, true);
393
368
  }
394
- }, _callee3, this);
369
+ }, _callee2, this);
395
370
  }));
396
371
  function play() {
397
372
  return _play.apply(this, arguments);
398
373
  }
399
374
  return play;
400
- }()
375
+ }())
376
+ }, {
377
+ key: "mediaOperations",
378
+ get: function get() {
379
+ var _this$options$getPlay2, _this$options2;
380
+ var run = (_this$options$getPlay2 = (_this$options2 = this.options).getPlayback) === null || _this$options$getPlay2 === void 0 ? void 0 : _this$options$getPlay2.call(_this$options2);
381
+ if (this.options.getPlayback && !(run !== null && run !== void 0 && run.valid())) return undefined;
382
+ return this.videoUrl ? this.operations(run, this.mediaInstance) : this.audioLikeInstance;
383
+ }
384
+ }, {
385
+ key: "stop",
386
+ value: function stop() {
387
+ var _this$removeStart;
388
+ ++this.generation;
389
+ (_this$removeStart = this.removeStart) === null || _this$removeStart === void 0 || _this$removeStart.call(this);
390
+ this.removeStart = undefined;
391
+ var _iterator = _createForOfIteratorHelper(this.outputs.values()),
392
+ _step;
393
+ try {
394
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
395
+ var output = _step.value;
396
+ output.muted = true;
397
+ output.pause();
398
+ }
399
+ } catch (err) {
400
+ _iterator.e(err);
401
+ } finally {
402
+ _iterator.f();
403
+ }
404
+ this.outputs.clear();
405
+ this.audioLikeInstance.pause();
406
+ }
407
+
401
408
  /**
402
409
  * 获取当前播放时间(毫秒)
403
410
  *
@@ -424,17 +431,15 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
424
431
  }, {
425
432
  key: "dispose",
426
433
  value: function dispose() {
427
- // 销毁事件监听
434
+ var _this$options$videoIn5;
435
+ this.stop();
428
436
  this.$removeEventListener();
429
- if (cacheInstance.audioInstance) {
430
- document.body.removeChild(cacheInstance.audioInstance);
431
- cacheInstance.audioInstance = undefined;
432
- }
433
- if (cacheInstance.videoInstance) {
434
- document.body.removeChild(cacheInstance.videoInstance);
435
- cacheInstance.videoInstance = undefined;
436
- }
437
+ if (this.ownsVideo) (_this$options$videoIn5 = this.options.videoInstance) === null || _this$options$videoIn5 === void 0 || _this$options$videoIn5.remove();
438
+ if (this.ownsAudio) this.audioInstance.remove();
439
+ if (this.objectURL) URL.revokeObjectURL(this.objectURL);
440
+ this.geometry.dispose();
441
+ this.material.uniforms.map.value.dispose();
442
+ this.material.dispose();
437
443
  }
438
444
  }]);
439
- return VideoAgentMesh;
440
445
  }(THREE.Mesh);
@@ -5,6 +5,7 @@ export declare class VideoAgentScene {
5
5
  scene: THREE.Scene;
6
6
  camera: THREE.OrthographicCamera;
7
7
  renderer: THREE.WebGLRenderer;
8
+ private frame;
8
9
  disposers: (() => void)[];
9
10
  constructor(container?: HTMLElement, options?: VideoAgentMeshOptions);
10
11
  run: () => void;
@@ -12,17 +12,21 @@ export var VideoAgentScene = /*#__PURE__*/_createClass(function VideoAgentScene(
12
12
  _defineProperty(this, "renderer", new THREE.WebGLRenderer({
13
13
  alpha: true
14
14
  }));
15
+ _defineProperty(this, "frame", 0);
15
16
  _defineProperty(this, "disposers", []);
16
17
  _defineProperty(this, "run", function () {
17
18
  // 视频开始 1s 不渲染:规避某些设备黑屏闪烁问题。视频前 2s 是最好是静默的。
18
19
  if (!(_this.videoAgentMesh.paused || _this.videoAgentMesh.freeze) && _this.videoAgentMesh.currentTime > 1000) {
19
20
  _this.renderer.render(_this.scene, _this.camera);
20
21
  }
21
- requestAnimationFrame(_this.run);
22
+ _this.frame = requestAnimationFrame(_this.run);
22
23
  });
23
24
  _defineProperty(this, "dispose", function () {
24
25
  var _this$videoAgentMesh;
25
- (_this$videoAgentMesh = _this.videoAgentMesh) === null || _this$videoAgentMesh === void 0 ? void 0 : _this$videoAgentMesh.dispose();
26
+ cancelAnimationFrame(_this.frame);
27
+ _this.renderer.dispose();
28
+ _this.renderer.domElement.remove();
29
+ (_this$videoAgentMesh = _this.videoAgentMesh) === null || _this$videoAgentMesh === void 0 || _this$videoAgentMesh.dispose();
26
30
  _this.disposers.forEach(function (disposer) {
27
31
  return disposer === null || disposer === void 0 ? void 0 : disposer();
28
32
  });
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import * as React from 'react';
2
5
  import { useController } from "../../hooks.js";
3
6
  import { VideoAgentScene } from "./VideoAgentScene.js";
@@ -21,12 +24,17 @@ export function VideoAgent(props) {
21
24
  console.warn('VideoAgentScene" 重复初始化,已被过滤');
22
25
  return;
23
26
  }
24
- var videoAgentScene = new VideoAgentScene(ref.current, props.options);
27
+ var videoAgentScene = new VideoAgentScene(ref.current, _objectSpread(_objectSpread({}, props.options), {}, {
28
+ getPlayback: function getPlayback() {
29
+ return controller.playback.capture();
30
+ }
31
+ }));
25
32
  controller.videoAgentScene = videoAgentScene;
26
33
  return function () {
27
34
  var _controller$videoAgen2;
28
35
  controller.dispose();
29
- (_controller$videoAgen2 = controller.videoAgentScene) === null || _controller$videoAgen2 === void 0 ? void 0 : _controller$videoAgen2.dispose();
36
+ (_controller$videoAgen2 = controller.videoAgentScene) === null || _controller$videoAgen2 === void 0 || _controller$videoAgen2.dispose();
37
+ controller.videoAgentScene = undefined;
30
38
  };
31
39
  }, []);
32
40
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {