@realsee/vreo 2.6.4-alpha.2 → 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.
@@ -1,10 +1,14 @@
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
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
6
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
7
  import _inherits from "@babel/runtime/helpers/esm/inherits";
7
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; }
8
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 }; })(); }
9
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); }
10
14
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -107,6 +111,7 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
107
111
  /** 是否冻结状态 */
108
112
  /** 是否暂停状态 */
109
113
  /** 音频实例 */
114
+ _defineProperty(_this, "outputs", new Map());
110
115
  _defineProperty(_this, "ownsVideo", false);
111
116
  _defineProperty(_this, "ownsAudio", false);
112
117
  _defineProperty(_this, "generation", 0);
@@ -165,6 +170,13 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
165
170
  */
166
171
  _inherits(VideoAgentMesh, _THREE$Mesh);
167
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
+ }, {
168
180
  key: "mediaInstance",
169
181
  get: /** AudioLike 实例 */
170
182
 
@@ -194,9 +206,9 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
194
206
  }, {
195
207
  key: "update",
196
208
  value: (function () {
197
- var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(videoUrl, valid) {
209
+ var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(videoUrl, valid, run) {
198
210
  var _this2 = this;
199
- var media, src, onStart, _t, _t2;
211
+ var element, media, src, onStart, _t, _t2;
200
212
  return _regenerator().w(function (_context) {
201
213
  while (1) switch (_context.n) {
202
214
  case 0:
@@ -208,7 +220,8 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
208
220
  case 1:
209
221
  this.stop();
210
222
  this.freeze = true;
211
- media = getMediaType(videoUrl) === 'audio' ? this.audioInstance : this.options.videoInstance;
223
+ element = getMediaType(videoUrl) === 'audio' ? this.audioInstance : this.options.videoInstance;
224
+ media = this.operations(run, element);
212
225
  media.muted = true;
213
226
  if (!(this.options.preload !== false || getMediaType(videoUrl) === 'video')) {
214
227
  _context.n = 3;
@@ -236,7 +249,7 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
236
249
  if (this.objectURL) URL.revokeObjectURL(this.objectURL);
237
250
  this.objectURL = src !== videoUrl ? src : undefined;
238
251
  media.src = src;
239
- media.setAttribute('data-src', videoUrl);
252
+ element.setAttribute('data-src', videoUrl);
240
253
  onStart = function onStart() {
241
254
  var _this2$removeStart;
242
255
  if (!valid() || media.currentTime === 0) return;
@@ -246,15 +259,15 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
246
259
  (_this2$removeStart = _this2.removeStart) === null || _this2$removeStart === void 0 || _this2$removeStart.call(_this2);
247
260
  };
248
261
  this.removeStart = function () {
249
- return media.removeEventListener('timeupdate', onStart);
262
+ return element.removeEventListener('timeupdate', onStart);
250
263
  };
251
- media.addEventListener('timeupdate', onStart);
264
+ element.addEventListener('timeupdate', onStart);
252
265
  case 6:
253
266
  return _context.a(2);
254
267
  }
255
268
  }, _callee, this);
256
269
  }));
257
- function update(_x, _x2) {
270
+ function update(_x, _x2, _x3) {
258
271
  return _update.apply(this, arguments);
259
272
  }
260
273
  return update;
@@ -289,10 +302,13 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
289
302
  key: "play",
290
303
  value: (function () {
291
304
  var _play = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
292
- var _this3 = this;
305
+ var _this$options$getPlay,
306
+ _this$options,
307
+ _this3 = this;
293
308
  var videoUrl,
294
309
  currentTime,
295
310
  duration,
311
+ run,
296
312
  generation,
297
313
  valid,
298
314
  media,
@@ -303,7 +319,8 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
303
319
  videoUrl = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
304
320
  currentTime = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 0;
305
321
  duration = _args2.length > 2 ? _args2[2] : undefined;
306
- if (!(this.options.canPlay && !this.options.canPlay())) {
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()))) {
307
324
  _context2.n = 1;
308
325
  break;
309
326
  }
@@ -313,7 +330,7 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
313
330
  if (videoUrl && videoUrl !== this.videoUrl) this.stop();
314
331
  generation = this.generation;
315
332
  valid = function valid() {
316
- return generation === _this3.generation && (!_this3.options.canPlay || _this3.options.canPlay());
333
+ return generation === _this3.generation && (!_this3.options.getPlayback || !!(run !== null && run !== void 0 && run.valid()));
317
334
  };
318
335
  if (!(videoUrl && videoUrl !== this.videoUrl)) {
319
336
  _context2.n = 2;
@@ -322,7 +339,7 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
322
339
  // update's synchronous stop is accounted for before awaiting its load.
323
340
  generation++;
324
341
  _context2.n = 2;
325
- return this.update(videoUrl, valid);
342
+ return this.update(videoUrl, valid, run);
326
343
  case 2:
327
344
  if (valid()) {
328
345
  _context2.n = 3;
@@ -334,7 +351,7 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
334
351
  this.videoUrl = '';
335
352
  this.audioLikeInstance.duration = duration;
336
353
  }
337
- media = this.mediaInstance;
354
+ media = this.videoUrl ? this.operations(run, this.mediaInstance) : this.audioLikeInstance;
338
355
  if (videoUrl || duration) media.currentTime = currentTime;
339
356
  media.muted = true;
340
357
  _context2.n = 4;
@@ -356,6 +373,14 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
356
373
  }
357
374
  return play;
358
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
+ }
359
384
  }, {
360
385
  key: "stop",
361
386
  value: function stop() {
@@ -363,10 +388,20 @@ export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
363
388
  ++this.generation;
364
389
  (_this$removeStart = this.removeStart) === null || _this$removeStart === void 0 || _this$removeStart.call(this);
365
390
  this.removeStart = undefined;
366
- this.audioInstance.muted = true;
367
- this.audioInstance.pause();
368
- this.options.videoInstance.muted = true;
369
- this.options.videoInstance.pause();
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();
370
405
  this.audioLikeInstance.pause();
371
406
  }
372
407
 
@@ -25,8 +25,8 @@ export function VideoAgent(props) {
25
25
  return;
26
26
  }
27
27
  var videoAgentScene = new VideoAgentScene(ref.current, _objectSpread(_objectSpread({}, props.options), {}, {
28
- canPlay: function canPlay() {
29
- return controller.audioFocus.active;
28
+ getPlayback: function getPlayback() {
29
+ return controller.playback.capture();
30
30
  }
31
31
  }));
32
32
  controller.videoAgentScene = videoAgentScene;
@@ -8,15 +8,19 @@ export function BgMusic() {
8
8
  React.useEffect(function () {
9
9
  var tracks = new Set();
10
10
  var callback = function callback(keyframe, currentTime) {
11
- var valid = controller.audioFocus.capture();
11
+ var run = controller.playback.capture();
12
+ var valid = function valid() {
13
+ return !!(run !== null && run !== void 0 && run.valid());
14
+ };
12
15
  if (!valid()) return;
13
- var audio = getAudio();
16
+ var element = getAudio();
17
+ var audio = run.bind(element);
14
18
  var cleaned = false;
15
19
  var _clean = function clean() {
16
20
  if (cleaned) return;
17
21
  cleaned = true;
18
- audio.removeEventListener('canplay', _play);
19
- audio.removeEventListener('ended', _clean);
22
+ element.removeEventListener('canplay', _play);
23
+ element.removeEventListener('ended', _clean);
20
24
  audio.muted = true;
21
25
  audio.pause();
22
26
  audio.src = '';
@@ -24,16 +28,16 @@ export function BgMusic() {
24
28
  tracks.delete(_clean);
25
29
  controller.setWaitingForBgMusic(false);
26
30
  };
27
- var remove = controller.audioFocus.add(_clean);
31
+ var remove = controller.playback.add(_clean);
28
32
  tracks.add(_clean);
29
33
  var _play = function play() {
30
- audio.removeEventListener('canplay', _play);
34
+ element.removeEventListener('canplay', _play);
31
35
  if (!valid() || cleaned) return;
32
36
  audio.muted = false;
33
37
  void audio.play().catch(function (error) {
34
38
  if (valid() && !cleaned) {
35
39
  _clean();
36
- controller.audioFocus.cancel('paused');
40
+ controller.playback.cancel();
37
41
  console.error(error);
38
42
  }
39
43
  });
@@ -42,10 +46,10 @@ export function BgMusic() {
42
46
  audio.muted = true;
43
47
  audio.src = keyframe.data.url;
44
48
  audio.currentTime = Math.max(0, (currentTime - keyframe.start) / 1000);
45
- audio.addEventListener('ended', _clean);
46
- if (controller.configs.waitForBgMusicLoaded && audio.readyState < 3) {
49
+ element.addEventListener('ended', _clean);
50
+ if (controller.configs.waitForBgMusicLoaded && element.readyState < 3) {
47
51
  controller.setWaitingForBgMusic(true);
48
- audio.addEventListener('canplay', _play);
52
+ element.addEventListener('canplay', _play);
49
53
  } else _play();
50
54
  };
51
55
  controller.on(VreoKeyframeEnum.BgMusic, callback);
@@ -21,37 +21,42 @@ function InfoPanelVideo(_ref2) {
21
21
  var _controller$configs;
22
22
  // if (!isIOSorWX) return
23
23
  var video = ((_controller$configs = controller.configs) === null || _controller$configs === void 0 || (_controller$configs = _controller$configs.videos) === null || _controller$configs === void 0 ? void 0 : _controller$configs.videoPanel) || document.createElement('video');
24
- var valid = controller.audioFocus.capture();
24
+ var run = controller.playback.capture();
25
+ var valid = function valid() {
26
+ return !!(run !== null && run !== void 0 && run.valid());
27
+ };
28
+ if (!(run !== null && run !== void 0 && run.valid())) return;
29
+ var output = run.bind(video);
25
30
  var disposed = false;
26
31
  video.playsInline = true;
27
- video.muted = true;
32
+ output.muted = true;
28
33
  var stop = function stop() {
29
34
  disposed = true;
30
- video.muted = true;
31
- video.pause();
35
+ output.muted = true;
36
+ output.pause();
32
37
  video.removeEventListener('canplaythrough', _canplaythrough);
33
38
  };
34
39
  if (!videoWrapperRef.current) return;
35
- var remove = controller.audioFocus.add(stop);
36
- video.src = url;
40
+ var remove = controller.playback.add(stop);
41
+ output.src = url;
37
42
  if (!videoWrapperRef.current.contains(video)) {
38
43
  videoWrapperRef.current.appendChild(video);
39
44
  }
40
45
  var _canplaythrough = function canplaythrough() {
41
46
  video.removeEventListener('canplaythrough', _canplaythrough);
42
47
  if (disposed || !valid()) return;
43
- video.muted = false;
44
- void video.play().catch(function (error) {
48
+ output.muted = false;
49
+ void output.play().catch(function (error) {
45
50
  if (valid() && !disposed) {
46
51
  stop();
47
- controller.audioFocus.cancel('paused');
52
+ controller.playback.cancel();
48
53
  console.error(error);
49
54
  }
50
55
  });
51
56
  };
52
57
  video.addEventListener('canplaythrough', _canplaythrough);
53
- video.load();
54
- // video.play()
58
+ output.load();
59
+ // output.play()
55
60
 
56
61
  return function () {
57
62
  var _videoWrapperRef$curr;
@@ -151,7 +156,7 @@ export function InfoPanel() {
151
156
  controller.openDrawer(false);
152
157
  controller.openPopUp(false);
153
158
  };
154
- var remove = controller.audioFocus.add(close);
159
+ var remove = controller.playback.add(close);
155
160
  return function () {
156
161
  remove();
157
162
  close();
@@ -18,31 +18,31 @@ export function ModelVideo() {
18
18
  var _ref$current;
19
19
  ++generation;
20
20
  if (timeoutRef.current) clearTimeout(timeoutRef.current);
21
- (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.disable();
21
+ (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.dispose();
22
+ ref.current = undefined;
22
23
  };
23
- var remove = controller.audioFocus.add(stop);
24
+ var remove = controller.playback.add(stop);
24
25
  var callback = /*#__PURE__*/function () {
25
26
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(keyframe) {
26
- var current, valid, start, end, _ref2, videoSrc, videoPosterSrc, vertexs, matrixWorld, position, points, _controller$configs, _t;
27
+ var current, run, valid, plugin, start, end, _ref2, videoSrc, videoPosterSrc, vertexs, matrixWorld, position, points, _controller$configs, _t;
27
28
  return _regenerator().w(function (_context) {
28
29
  while (1) switch (_context.p = _context.n) {
29
30
  case 0:
30
31
  stop();
31
32
  current = generation;
32
- valid = controller.audioFocus.capture();
33
+ run = controller.playback.capture();
34
+ valid = function valid() {
35
+ return !!(run !== null && run !== void 0 && run.valid());
36
+ };
33
37
  if (valid()) {
34
38
  _context.n = 1;
35
39
  break;
36
40
  }
37
41
  return _context.a(2);
38
42
  case 1:
39
- if (!ref.current) {
40
- ref.current = ModelTVVideoPlugin(five, {
41
- canPlay: function canPlay() {
42
- return controller.audioFocus.active;
43
- }
44
- });
45
- }
43
+ plugin = ref.current = ModelTVVideoPlugin(five, {
44
+ mediaManager: run === null || run === void 0 ? void 0 : run.mediaManager
45
+ });
46
46
  start = keyframe.start, end = keyframe.end;
47
47
  _ref2 = keyframe.data, videoSrc = _ref2.videoSrc, videoPosterSrc = _ref2.videoPosterSrc, vertexs = _ref2.vertexs, matrixWorld = _ref2.matrixWorld;
48
48
  position = function () {
@@ -72,10 +72,10 @@ export function ModelVideo() {
72
72
  }
73
73
  return [position];
74
74
  }();
75
- ref.current.disable();
75
+ plugin.disable();
76
76
  _context.p = 2;
77
77
  _context.n = 3;
78
- return ref.current.load({
78
+ return plugin.load({
79
79
  video_src: videoSrc,
80
80
  video_poster_src: videoPosterSrc,
81
81
  points: points
@@ -87,7 +87,7 @@ export function ModelVideo() {
87
87
  _context.p = 4;
88
88
  _t = _context.v;
89
89
  if (current === generation && valid()) {
90
- controller.audioFocus.cancel('paused');
90
+ controller.playback.cancel();
91
91
  console.error(_t);
92
92
  }
93
93
  return _context.a(2);
@@ -98,11 +98,8 @@ export function ModelVideo() {
98
98
  }
99
99
  return _context.a(2);
100
100
  case 6:
101
- ref.current.enable();
102
- timeoutRef.current = setTimeout(function () {
103
- var _ref$current2;
104
- return (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.disable();
105
- }, end - start);
101
+ plugin.enable();
102
+ timeoutRef.current = setTimeout(stop, end - start);
106
103
  case 7:
107
104
  return _context.a(2);
108
105
  }
@@ -114,10 +111,10 @@ export function ModelVideo() {
114
111
  }();
115
112
  controller.on(VreoKeyframeEnum.ModelVideo, callback);
116
113
  return function () {
117
- var _ref$current3;
114
+ var _ref$current2;
118
115
  stop();
119
116
  remove();
120
- (_ref$current3 = ref.current) === null || _ref$current3 === void 0 || _ref$current3.dispose();
117
+ (_ref$current2 = ref.current) === null || _ref$current2 === void 0 || _ref$current2.dispose();
121
118
  ref.current = undefined;
122
119
  controller.off(VreoKeyframeEnum.ModelVideo, callback);
123
120
  if (timeoutRef.current) {
@@ -27,7 +27,8 @@ export function PanoTag() {
27
27
  return;
28
28
  }
29
29
  var callback = function callback(keyframe) {
30
- if (!panoTagPlugin.current) return;
30
+ var run = controller.playback.capture();
31
+ if (!panoTagPlugin.current || !(run !== null && run !== void 0 && run.valid())) return;
31
32
  var start = keyframe.start,
32
33
  end = keyframe.end,
33
34
  data = keyframe.data;
@@ -74,6 +75,7 @@ export function PanoTag() {
74
75
  });
75
76
  var tagInstance = panoTagPlugin.current.getTagById(id);
76
77
  if (tagInstance) {
78
+ tagInstance.setMediaManager(run.mediaManager);
77
79
  tagInstance.state.unfolded = true;
78
80
  panoTagPlugin.current.updateRenderAllTags();
79
81
  }
@@ -19,21 +19,17 @@ export function VideoEffect() {
19
19
  visible = _React$useState2[0],
20
20
  setVisible = _React$useState2[1];
21
21
  var five = useFiveInstance();
22
- var setBlobSrc = function setBlobSrc(blob) {
23
- if (!videoRef.current) return;
24
- videoRef.current.src = blob;
25
- };
26
22
  React.useEffect(function () {
23
+ var output;
27
24
  var generation = 0;
28
25
  var removeCanPlay;
29
26
  var callback = /*#__PURE__*/function () {
30
27
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(keyframe) {
31
28
  var _removeCanPlay;
32
- var current, start, end, _ref2, videoSrc, fov, direction, panoIndex, vector, _ref3, _ref4, longitude, latitude, active, valid, video, play;
29
+ var start, end, _ref2, videoSrc, fov, direction, panoIndex, vector, _ref3, _ref4, longitude, latitude, currentGeneration, run, active, valid, video, media, play;
33
30
  return _regenerator().w(function (_context) {
34
31
  while (1) switch (_context.n) {
35
32
  case 0:
36
- current = ++generation;
37
33
  start = keyframe.start, end = keyframe.end;
38
34
  _ref2 = keyframe.data, videoSrc = _ref2.videoSrc, fov = _ref2.fov, direction = _ref2.direction, panoIndex = _ref2.panoIndex, vector = _ref2.vector;
39
35
  _ref3 = function () {
@@ -48,22 +44,21 @@ export function VideoEffect() {
48
44
  var latitude = -Math.asin(direction.y / 1);
49
45
  return [longitude, latitude];
50
46
  }(), _ref4 = _slicedToArray(_ref3, 2), longitude = _ref4[0], latitude = _ref4[1];
51
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
52
- if (videoRef.current) {
53
- videoRef.current.muted = true;
54
- videoRef.current.pause();
55
- }
47
+ destroy();
48
+ currentGeneration = generation;
56
49
  five.setState({
57
50
  fov: fov,
58
51
  panoIndex: panoIndex,
59
52
  longitude: longitude,
60
53
  latitude: latitude
61
54
  }, true);
62
- setBlobSrc(videoSrc);
63
55
  (_removeCanPlay = removeCanPlay) === null || _removeCanPlay === void 0 || _removeCanPlay();
64
- active = controller.audioFocus.capture();
56
+ run = controller.playback.capture();
57
+ active = function active() {
58
+ return !!(run !== null && run !== void 0 && run.valid());
59
+ };
65
60
  valid = function valid() {
66
- return current === generation && active();
61
+ return currentGeneration === generation && active();
67
62
  };
68
63
  video = videoRef.current;
69
64
  if (!(!video || !valid())) {
@@ -72,14 +67,17 @@ export function VideoEffect() {
72
67
  }
73
68
  return _context.a(2);
74
69
  case 1:
70
+ media = output = run.bind(video);
71
+ media.muted = true;
72
+ media.src = videoSrc;
75
73
  play = function play() {
76
74
  var _removeCanPlay2;
77
75
  (_removeCanPlay2 = removeCanPlay) === null || _removeCanPlay2 === void 0 || _removeCanPlay2();
78
76
  if (!valid()) return;
79
- video.muted = false;
80
- void video.play().catch(function (error) {
77
+ media.muted = false;
78
+ void media.play().catch(function (error) {
81
79
  if (valid()) {
82
- controller.audioFocus.cancel('paused');
80
+ controller.playback.cancel();
83
81
  console.error(error);
84
82
  }
85
83
  });
@@ -88,7 +86,7 @@ export function VideoEffect() {
88
86
  return video.removeEventListener('canplaythrough', play);
89
87
  };
90
88
  video.addEventListener('canplaythrough', play);
91
- video.load();
89
+ media.load();
92
90
  setVisible(true);
93
91
  timeoutRef.current = setTimeout(destroy, Math.max(0, end - start));
94
92
  case 2:
@@ -102,18 +100,21 @@ export function VideoEffect() {
102
100
  }();
103
101
  controller.on(VreoKeyframeEnum.VideoEffect, callback);
104
102
  var destroy = function destroy() {
105
- var _removeCanPlay3, _videoRef$current;
103
+ var _removeCanPlay3;
106
104
  ++generation;
107
105
  if (timeoutRef.current) {
108
106
  clearTimeout(timeoutRef.current);
109
107
  }
110
108
  (_removeCanPlay3 = removeCanPlay) === null || _removeCanPlay3 === void 0 || _removeCanPlay3();
111
- if (videoRef.current) videoRef.current.muted = true;
112
- (_videoRef$current = videoRef.current) === null || _videoRef$current === void 0 || _videoRef$current.pause();
109
+ if (output) {
110
+ output.muted = true;
111
+ output.pause();
112
+ output.src = '';
113
+ }
114
+ output = undefined;
113
115
  setVisible(false);
114
- setBlobSrc('');
115
116
  };
116
- var remove = controller.audioFocus.add(destroy);
117
+ var remove = controller.playback.add(destroy);
117
118
  return function () {
118
119
  destroy();
119
120
  remove();
@@ -0,0 +1,21 @@
1
+ export interface PlaybackManager {
2
+ createController(options: {
3
+ label: string;
4
+ onCancel(): void;
5
+ }): PlaybackController;
6
+ }
7
+ export interface PlaybackController {
8
+ begin(request: {
9
+ userAction: boolean;
10
+ audible: boolean;
11
+ }): PlaybackSession | null;
12
+ cancel(): void;
13
+ dispose(): void;
14
+ }
15
+ export interface PlaybackSession {
16
+ readonly signal: AbortSignal;
17
+ readonly mediaManager: PlaybackManager;
18
+ bind(element: HTMLMediaElement): MediaOperations;
19
+ finish(): void;
20
+ }
21
+ export type MediaOperations = Pick<HTMLMediaElement, 'play' | 'pause' | 'load' | 'src' | 'currentTime' | 'muted' | 'volume' | 'loop'>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,10 @@
1
- import type { AudioFocusHost } from './AudioFocus';
1
+ import type { PlaybackManager } from './playback-types';
2
2
  import React, { ReactNode } from 'react';
3
3
  import { Subscribe, Five } from '@realsee/five';
4
4
  import { VreoKeyframe, VreoKeyframeConfigMap, VreoKeyframeEvent } from '../typings/VreoUnit';
5
5
  import { VideoAgentMeshOptions } from './modules/VideoAgent/VideoAgentMesh';
6
6
  export interface PlayerConfigs {
7
- audioFocus?: AudioFocusHost;
7
+ mediaManager?: PlaybackManager;
8
8
  /**
9
9
  * @deprecated rename to container
10
10
  */
@@ -54,7 +54,7 @@ export interface Appearance {
54
54
  }
55
55
  export type VreoSubscribe = Pick<Subscribe<VreoKeyframeEvent>, 'on' | 'once' | 'off'>;
56
56
  export interface CustomVreoKeyframeProps {
57
- audioFocus: AudioFocusHost;
57
+ getMediaManager(): PlaybackManager | undefined;
58
58
  subscribe: Pick<Subscribe<{
59
59
  [key: string]: (data: VreoKeyframe, currentTime: number) => any;
60
60
  }>, 'on' | 'once' | 'off'>;
@@ -1,4 +1,5 @@
1
1
  import type { FivePlugin } from '@realsee/five';
2
+ import type { PlaybackManager } from '../../Player/playback-types';
2
3
  export interface ModelTVVideoPluginData {
3
4
  enable?: boolean;
4
5
  video_src: string;
@@ -11,7 +12,7 @@ export interface ModelTVVideoPluginData {
11
12
  }
12
13
  export interface ModelTVVideoPluginParameterType {
13
14
  videoElement?: HTMLVideoElement;
14
- canPlay?: () => boolean;
15
+ mediaManager?: PlaybackManager;
15
16
  }
16
17
  export interface ModelTVVideoPluginExportType {
17
18
  enable: () => void;