@realsee/vreo 2.6.2 → 2.6.4-alpha.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.
Files changed (134) 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/AudioFocus.d.ts +36 -0
  5. package/lib/Player/AudioFocus.js +139 -0
  6. package/lib/Player/Controller.d.ts +16 -0
  7. package/lib/Player/Controller.js +119 -61
  8. package/lib/Player/custom/SpatialScenePanel/index.js +34 -11
  9. package/lib/Player/index.d.ts +8 -2
  10. package/lib/Player/index.js +182 -123
  11. package/lib/Player/modules/Drawer/index.js +1 -2
  12. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +8 -1
  13. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +173 -203
  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 +46 -54
  18. package/lib/Player/modules/keyframes/CameraMovement/index.js +43 -45
  19. package/lib/Player/modules/keyframes/InfoPanel/index.js +37 -32
  20. package/lib/Player/modules/keyframes/ModelVideo/index.js +98 -57
  21. package/lib/Player/modules/keyframes/PanoTag/index.js +1 -1
  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 +87 -74
  25. package/lib/Player/typings.d.ts +10 -0
  26. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +6 -6
  27. package/lib/fivePlugins/CameraMovementPlugin/index.js +173 -180
  28. package/lib/fivePlugins/CameraMovementPlugin/typings.js +6 -6
  29. package/lib/fivePlugins/ModelTVVideoPlugin/index.d.ts +2 -0
  30. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +87 -43
  31. package/lib/index.d.ts +1 -0
  32. package/lib/react/index.js +1 -1
  33. package/lib/shared-utils/Audio.js +53 -56
  34. package/lib/shared-utils/AudioLike.js +12 -14
  35. package/lib/shared-utils/animationFrame/BetterTween.js +13 -15
  36. package/lib/shared-utils/animationFrame/tween.js +1 -3
  37. package/lib/shared-utils/getMediaInfo.js +0 -1
  38. package/lib/typings/VreoUnit.js +134 -27
  39. package/package.json +6 -4
  40. package/docs/.nojekyll +0 -1
  41. package/docs/assets/custom.css +0 -78
  42. package/docs/assets/hierarchy.js +0 -1
  43. package/docs/assets/highlight.css +0 -127
  44. package/docs/assets/icons.js +0 -18
  45. package/docs/assets/icons.svg +0 -1
  46. package/docs/assets/main.js +0 -60
  47. package/docs/assets/navigation.js +0 -1
  48. package/docs/assets/search.js +0 -1
  49. package/docs/assets/style.css +0 -1640
  50. package/docs/classes/Player.AudioLike.html +0 -15
  51. package/docs/classes/Player.Controller.html +0 -87
  52. package/docs/classes/Player.Player.html +0 -54
  53. package/docs/classes/Player.VideoAgentMesh.html +0 -72
  54. package/docs/classes/Player.VideoAgentScene.html +0 -9
  55. package/docs/demo/assets/AppReact-CkuqZtcS.js +0 -1
  56. package/docs/demo/assets/default-BQGCQRLt.css +0 -1
  57. package/docs/demo/assets/default-CVvVdmSW.js +0 -5540
  58. package/docs/demo/assets/dynamic-CO5wq52h.js +0 -1
  59. package/docs/demo/assets/examples-BCLzFApO.css +0 -1
  60. package/docs/demo/assets/examples-DfiAz2fR.js +0 -25
  61. package/docs/demo/assets/index-CBBSwaYT.js +0 -1
  62. package/docs/demo/assets/index-CmEXi2sK.css +0 -1
  63. package/docs/demo/assets/main-BF1tvUg-.js +0 -25
  64. package/docs/demo/assets/react-BnzBLum3.css +0 -1
  65. package/docs/demo/assets/react-C4h9qndP.js +0 -25
  66. package/docs/demo/examples.html +0 -16
  67. package/docs/demo/index-react-dynamic.html +0 -18
  68. package/docs/demo/index-react.html +0 -19
  69. package/docs/demo/index.html +0 -19
  70. package/docs/enums/Player.InfoPanelStyleEnum.html +0 -3
  71. package/docs/enums/Player.InfoPanelTypeEnum.html +0 -4
  72. package/docs/enums/Player.PanoEffectEnum.html +0 -4
  73. package/docs/enums/Player.PanoTagEnum.html +0 -4
  74. package/docs/enums/Player.PanoTagStyleEnum.html +0 -6
  75. package/docs/enums/Player.VreoKeyframeEnum.html +0 -25
  76. package/docs/enums/fivePlugins.CameraMovementEffect.html +0 -3
  77. package/docs/enums/fivePlugins.Rotation.html +0 -4
  78. package/docs/functions/custom.SpatialScenePanel.html +0 -2
  79. package/docs/functions/react.useVreoAction.html +0 -8
  80. package/docs/functions/react.useVreoEventCallback.html +0 -10
  81. package/docs/functions/react.useVreoPausedState.html +0 -8
  82. package/docs/hierarchy.html +0 -1
  83. package/docs/index.html +0 -160
  84. package/docs/interfaces/Player.Appearance.html +0 -2
  85. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +0 -3
  86. package/docs/interfaces/Player.PlayerConfigs.html +0 -20
  87. package/docs/interfaces/Player.Vertex.html +0 -5
  88. package/docs/interfaces/Player.VideoAgentMeshOptions.html +0 -9
  89. package/docs/interfaces/Player.VreoKeyframe.html +0 -8
  90. package/docs/interfaces/Player.VreoUnit.html +0 -9
  91. package/docs/interfaces/Player.VreoVideo.html +0 -7
  92. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +0 -8
  93. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +0 -3
  94. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +0 -5
  95. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +0 -1
  96. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +0 -5
  97. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +0 -4
  98. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +0 -2
  99. package/docs/interfaces/fivePlugins.Vector3Position.html +0 -5
  100. package/docs/interfaces/react.VreoActionCallbacks.html +0 -18
  101. package/docs/interfaces/react.VreoProviderProps.html +0 -6
  102. package/docs/modules/Player.html +0 -1
  103. package/docs/modules/custom.html +0 -1
  104. package/docs/modules/fivePlugins.html +0 -1
  105. package/docs/modules/react.html +0 -1
  106. package/docs/modules.html +0 -1
  107. package/docs/types/Player.AppSize.html +0 -1
  108. package/docs/types/Player.AudioLikeEvent.html +0 -6
  109. package/docs/types/Player.CameraMovementData.html +0 -2
  110. package/docs/types/Player.CustomData.html +0 -2
  111. package/docs/types/Player.InfoPanelData.html +0 -7
  112. package/docs/types/Player.ModelVideoData.html +0 -9
  113. package/docs/types/Player.PanoEffectData.html +0 -4
  114. package/docs/types/Player.PanoTagData.html +0 -6
  115. package/docs/types/Player.PanoTextLabelData.html +0 -7
  116. package/docs/types/Player.PrompterData.html +0 -3
  117. package/docs/types/Player.QuadrangleVertexs.html +0 -2
  118. package/docs/types/Player.Quaternion.html +0 -6
  119. package/docs/types/Player.UpdateVRPanoramaData.html +0 -7
  120. package/docs/types/Player.Vertexs.html +0 -2
  121. package/docs/types/Player.VideoEffectData.html +0 -7
  122. package/docs/types/Player.VreoKeyframeEvent.html +0 -2
  123. package/docs/types/Player.VreoKeyframeMap.html +0 -6
  124. package/docs/types/Player.VreoSubscribe.html +0 -1
  125. package/docs/types/Player.WaveAppearance.html +0 -1
  126. package/docs/types/fivePlugins.CSS3DRenderPluginParameterType.html +0 -1
  127. package/docs/types/fivePlugins.MoveArgs.html +0 -1
  128. package/docs/types/fivePlugins.MoveOpts.html +0 -1
  129. package/docs/types/fivePlugins.RotateArgs.html +0 -1
  130. package/docs/types/fivePlugins.RotateOpts.html +0 -1
  131. package/docs/variables/fivePlugins.CSS3DRenderPlugin.html +0 -3
  132. package/docs/variables/fivePlugins.CameraMovementPlugin.html +0 -2
  133. package/docs/variables/fivePlugins.ModelTVVideoPlugin.html +0 -1
  134. package/docs/variables/react.VreoProvider.html +0 -9
@@ -1,13 +1,14 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
3
  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
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
5
  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; } }
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ 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 }; })(); }
9
+ 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); }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
12
  import * as THREE from 'three';
12
13
  import { Preloader } from "../../../shared-utils/Preloader.js";
13
14
  import { makeObservable, observable, runInAction } from 'mobx';
@@ -17,7 +18,6 @@ var vertexShader = "\nvarying vec2 vUv;\nvarying vec2 vColorUv;\nvarying vec2 vM
17
18
  var fragmentShaderTpl = function fragmentShaderTpl() {
18
19
  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
20
  };
20
- var cacheInstance = {};
21
21
 
22
22
  /**
23
23
  * 视频经纪人贴片的配置选项
@@ -53,8 +53,6 @@ var cacheInstance = {};
53
53
  * ```
54
54
  */
55
55
  export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
56
- _inherits(VideoAgentMesh, _THREE$Mesh);
57
- var _super = _createSuper(VideoAgentMesh);
58
56
  /**
59
57
  * 创建视频经纪人贴片实例
60
58
  *
@@ -79,20 +77,14 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
79
77
  preload: true
80
78
  };
81
79
  _classCallCheck(this, VideoAgentMesh);
80
+ var ownsVideo = !options.videoInstance;
82
81
  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
- }
82
+ var videoInstance = document.createElement('video');
83
+ videoInstance.style.display = 'none';
84
+ videoInstance.playsInline = true;
85
+ videoInstance.muted = true;
86
+ document.body.append(videoInstance);
87
+ options.videoInstance = videoInstance;
96
88
  }
97
89
  var geometry = new THREE.PlaneGeometry(width, height, widthSegments, heightSegments);
98
90
  var videoTexture = new THREE.VideoTexture(options.videoInstance);
@@ -109,29 +101,30 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
109
101
  fragmentShader: fragmentShaderTpl(),
110
102
  transparent: true
111
103
  });
112
- _this = _super.call(this, geometry, material);
104
+ _this = _callSuper(this, VideoAgentMesh, [geometry, material]);
105
+ /** 配置选项 */
106
+ /** 当前视频URL */
107
+ /** 是否冻结状态 */
108
+ /** 是否暂停状态 */
109
+ /** 音频实例 */
110
+ _defineProperty(_this, "ownsVideo", false);
111
+ _defineProperty(_this, "ownsAudio", false);
112
+ _defineProperty(_this, "generation", 0);
113
+ _this.ownsVideo = ownsVideo;
114
+ _this.ownsAudio = !options.audioInstance;
113
115
  _this.options = options;
114
116
  _this.freeze = false;
115
117
  _this.paused = true;
116
118
  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
- }
119
+ _this.audioInstance = document.createElement('audio');
120
+ _this.audioInstance.crossOrigin = '';
121
+ _this.audioInstance.muted = true;
122
+ _this.audioInstance.autoplay = false;
130
123
  } else {
131
124
  _this.audioInstance = options.audioInstance;
132
125
  }
133
126
  _this.audioLikeInstance = new AudioLike();
134
- makeObservable(_assertThisInitialized(_this), {
127
+ makeObservable(_this, {
135
128
  paused: observable
136
129
  });
137
130
  var updatePaused = function updatePaused(paused) {
@@ -147,16 +140,16 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
147
140
  };
148
141
  _this.audioInstance.addEventListener('pause', onPause);
149
142
  _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);
143
+ (_this$options$videoIn = _this.options.videoInstance) === null || _this$options$videoIn === void 0 || _this$options$videoIn.addEventListener('pause', onPause);
144
+ (_this$options$videoIn2 = _this.options.videoInstance) === null || _this$options$videoIn2 === void 0 || _this$options$videoIn2.addEventListener('play', onPlay);
152
145
  _this.audioLikeInstance.addEventListener('pause', onPause);
153
146
  _this.audioLikeInstance.addEventListener('play', onPlay);
154
147
  _this.$removeEventListener = function () {
155
148
  var _this$options$videoIn3, _this$options$videoIn4;
156
149
  _this.audioInstance.removeEventListener('pause', onPause);
157
150
  _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);
151
+ (_this$options$videoIn3 = _this.options.videoInstance) === null || _this$options$videoIn3 === void 0 || _this$options$videoIn3.removeEventListener('pause', onPause);
152
+ (_this$options$videoIn4 = _this.options.videoInstance) === null || _this$options$videoIn4 === void 0 || _this$options$videoIn4.removeEventListener('play', onPlay);
160
153
  _this.audioLikeInstance.removeEventListener('pause', onPause);
161
154
  _this.audioLikeInstance.removeEventListener('play', onPlay);
162
155
  };
@@ -170,19 +163,10 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
170
163
  * @param videoUrl - 媒体文件URL
171
164
  * @private
172
165
  */
173
- _createClass(VideoAgentMesh, [{
166
+ _inherits(VideoAgentMesh, _THREE$Mesh);
167
+ return _createClass(VideoAgentMesh, [{
174
168
  key: "mediaInstance",
175
- get: /** 配置选项 */
176
-
177
- /** 当前视频URL */
178
-
179
- /** 是否冻结状态 */
180
-
181
- /** 是否暂停状态 */
182
-
183
- /** 音频实例 */
184
-
185
- /** AudioLike 实例 */
169
+ get: /** AudioLike 实例 */
186
170
 
187
171
  /** 移除事件监听器的函数 */
188
172
 
@@ -209,71 +193,68 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
209
193
  }
210
194
  }, {
211
195
  key: "update",
212
- value: function () {
213
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(videoUrl) {
196
+ value: (function () {
197
+ var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(videoUrl, valid) {
214
198
  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;
199
+ var media, src, onStart, _t, _t2;
200
+ return _regenerator().w(function (_context) {
201
+ while (1) switch (_context.n) {
202
+ case 0:
203
+ if (!(this.videoUrl === videoUrl)) {
204
+ _context.n = 1;
205
+ break;
206
+ }
207
+ return _context.a(2);
208
+ case 1:
209
+ this.stop();
210
+ this.freeze = true;
211
+ media = getMediaType(videoUrl) === 'audio' ? this.audioInstance : this.options.videoInstance;
212
+ media.muted = true;
213
+ if (!(this.options.preload !== false || getMediaType(videoUrl) === 'video')) {
214
+ _context.n = 3;
255
215
  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
- }
216
+ }
217
+ _t2 = URL;
218
+ _context.n = 2;
219
+ return Preloader.blob(videoUrl);
220
+ case 2:
221
+ _t = _t2.createObjectURL.call(_t2, _context.v);
222
+ _context.n = 4;
223
+ break;
224
+ case 3:
225
+ _t = videoUrl;
226
+ case 4:
227
+ src = _t;
228
+ if (valid()) {
229
+ _context.n = 5;
230
+ break;
231
+ }
232
+ if (src !== videoUrl) URL.revokeObjectURL(src);
233
+ return _context.a(2);
234
+ case 5:
235
+ this.videoUrl = videoUrl;
236
+ if (this.objectURL) URL.revokeObjectURL(this.objectURL);
237
+ this.objectURL = src !== videoUrl ? src : undefined;
238
+ media.src = src;
239
+ media.setAttribute('data-src', videoUrl);
240
+ onStart = function onStart() {
241
+ var _this2$removeStart;
242
+ if (!valid() || media.currentTime === 0) return;
243
+ _this2.freeze = false;
244
+ media.muted = false;
245
+ _this2.material.uniforms.enable.value = getMediaType(videoUrl) ? 1 : 0;
246
+ (_this2$removeStart = _this2.removeStart) === null || _this2$removeStart === void 0 || _this2$removeStart.call(_this2);
247
+ };
248
+ this.removeStart = function () {
249
+ return media.removeEventListener('timeupdate', onStart);
250
+ };
251
+ media.addEventListener('timeupdate', onStart);
252
+ case 6:
253
+ return _context.a(2);
273
254
  }
274
255
  }, _callee, this);
275
256
  }));
276
- function update(_x) {
257
+ function update(_x, _x2) {
277
258
  return _update.apply(this, arguments);
278
259
  }
279
260
  return update;
@@ -303,101 +284,92 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
303
284
  * await mesh.play()
304
285
  * ```
305
286
  */
287
+ )
306
288
  }, {
307
289
  key: "play",
308
- value: function () {
309
- var _play = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
290
+ value: (function () {
291
+ var _play = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
310
292
  var _this3 = this;
311
293
  var videoUrl,
312
294
  currentTime,
313
295
  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;
296
+ generation,
297
+ valid,
298
+ media,
299
+ _args2 = arguments;
300
+ return _regenerator().w(function (_context2) {
301
+ while (1) switch (_context2.n) {
302
+ case 0:
303
+ videoUrl = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
304
+ currentTime = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 0;
305
+ duration = _args2.length > 2 ? _args2[2] : undefined;
306
+ if (!(this.options.canPlay && !this.options.canPlay())) {
307
+ _context2.n = 1;
308
+ break;
309
+ }
310
+ return _context2.a(2, false);
311
+ case 1:
312
+ // stop() invalidates all earlier loads before the new generation is captured.
313
+ if (videoUrl && videoUrl !== this.videoUrl) this.stop();
314
+ generation = this.generation;
315
+ valid = function valid() {
316
+ return generation === _this3.generation && (!_this3.options.canPlay || _this3.options.canPlay());
317
+ };
318
+ if (!(videoUrl && videoUrl !== this.videoUrl)) {
319
+ _context2.n = 2;
320
+ break;
321
+ }
322
+ // update's synchronous stop is accounted for before awaiting its load.
323
+ generation++;
324
+ _context2.n = 2;
325
+ return this.update(videoUrl, valid);
326
+ case 2:
327
+ if (valid()) {
328
+ _context2.n = 3;
329
+ break;
330
+ }
331
+ return _context2.a(2, false);
332
+ case 3:
333
+ if (duration && !videoUrl) {
331
334
  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;
335
+ this.audioLikeInstance.duration = duration;
336
+ }
337
+ media = this.mediaInstance;
338
+ if (videoUrl || duration) media.currentTime = currentTime;
339
+ media.muted = true;
340
+ _context2.n = 4;
341
+ return media.play();
342
+ case 4:
343
+ if (valid()) {
344
+ _context2.n = 5;
347
345
  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
- }
346
+ }
347
+ return _context2.a(2, false);
348
+ case 5:
349
+ media.muted = false;
350
+ return _context2.a(2, true);
393
351
  }
394
- }, _callee3, this);
352
+ }, _callee2, this);
395
353
  }));
396
354
  function play() {
397
355
  return _play.apply(this, arguments);
398
356
  }
399
357
  return play;
400
- }()
358
+ }())
359
+ }, {
360
+ key: "stop",
361
+ value: function stop() {
362
+ var _this$removeStart;
363
+ ++this.generation;
364
+ (_this$removeStart = this.removeStart) === null || _this$removeStart === void 0 || _this$removeStart.call(this);
365
+ this.removeStart = undefined;
366
+ this.audioInstance.muted = true;
367
+ this.audioInstance.pause();
368
+ this.options.videoInstance.muted = true;
369
+ this.options.videoInstance.pause();
370
+ this.audioLikeInstance.pause();
371
+ }
372
+
401
373
  /**
402
374
  * 获取当前播放时间(毫秒)
403
375
  *
@@ -424,17 +396,15 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
424
396
  }, {
425
397
  key: "dispose",
426
398
  value: function dispose() {
427
- // 销毁事件监听
399
+ var _this$options$videoIn5;
400
+ this.stop();
428
401
  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
- }
402
+ if (this.ownsVideo) (_this$options$videoIn5 = this.options.videoInstance) === null || _this$options$videoIn5 === void 0 || _this$options$videoIn5.remove();
403
+ if (this.ownsAudio) this.audioInstance.remove();
404
+ if (this.objectURL) URL.revokeObjectURL(this.objectURL);
405
+ this.geometry.dispose();
406
+ this.material.uniforms.map.value.dispose();
407
+ this.material.dispose();
437
408
  }
438
409
  }]);
439
- return VideoAgentMesh;
440
410
  }(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
+ canPlay: function canPlay() {
29
+ return controller.audioFocus.active;
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", {