@realsee/vreo 1.0.0-alpha.17 → 1.0.0-alpha.19

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 (73) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/docs/demo/assets/{AppReact.a3fc45d3.js → AppReact.20163f9a.js} +1 -1
  3. package/docs/demo/assets/default.5069891b.js +3988 -0
  4. package/docs/demo/assets/{dynamic.714b9eb8.js → dynamic.c8118cc9.js} +1 -1
  5. package/docs/demo/assets/{examples.1a6f5a2c.js → examples.5391fc1f.js} +1 -1
  6. package/docs/demo/assets/{index.0ca9e9d3.js → index.2272a9ef.js} +1 -1
  7. package/docs/demo/assets/main.b335b989.js +1 -0
  8. package/docs/demo/assets/{react.fca6a967.js → react.efea3f3f.js} +1 -1
  9. package/docs/demo/examples.html +2 -2
  10. package/docs/demo/index-react-dynamic.html +4 -4
  11. package/docs/demo/index-react.html +4 -4
  12. package/docs/demo/index.html +3 -3
  13. package/lib/PlayController/createHTMLAudioElement.js +11 -6
  14. package/lib/PlayController/index.js +81 -16
  15. package/lib/Player/App.js +24 -0
  16. package/lib/Player/Controller.d.ts +2 -2
  17. package/lib/Player/Controller.js +95 -19
  18. package/lib/Player/custom/SpatialScenePanel/index.js +68 -42
  19. package/lib/Player/hooks.js +10 -0
  20. package/lib/Player/index.js +85 -25
  21. package/lib/Player/modules/Drawer/index.js +17 -0
  22. package/lib/Player/modules/PopUp/index.js +10 -0
  23. package/lib/Player/modules/ResizeObserver/index.js +8 -0
  24. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +2 -2
  25. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +114 -20
  26. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +24 -2
  27. package/lib/Player/modules/VideoAgent/index.js +17 -0
  28. package/lib/Player/modules/Wave/index.js +32 -7
  29. package/lib/Player/modules/keyframes/BgMusic/index.js +44 -14
  30. package/lib/Player/modules/keyframes/CameraMovement/index.js +27 -3
  31. package/lib/Player/modules/keyframes/InfoPanel/index.js +25 -8
  32. package/lib/Player/modules/keyframes/ModelVideo/index.js +29 -3
  33. package/lib/Player/modules/keyframes/PanoEffect/index.js +43 -15
  34. package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +7 -0
  35. package/lib/Player/modules/keyframes/PanoTag/index.js +21 -4
  36. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +47 -22
  37. package/lib/Player/modules/keyframes/Prompter/index.js +32 -10
  38. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +25 -18
  39. package/lib/Player/modules/keyframes/VideoEffect/index.js +47 -12
  40. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +2 -0
  41. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +1 -0
  42. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +1 -0
  43. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +60 -19
  44. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +5 -2
  45. package/lib/fivePlugins/CameraMovementPlugin/index.js +75 -28
  46. package/lib/fivePlugins/CameraMovementPlugin/typings.js +4 -0
  47. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +60 -11
  48. package/lib/index.js +1 -0
  49. package/lib/react/index.js +34 -7
  50. package/lib/shared-utils/{AduioLike.d.ts → AudioLike.d.ts} +0 -0
  51. package/lib/shared-utils/{AduioLike.js → AudioLike.js} +43 -11
  52. package/lib/shared-utils/Preloader.js +7 -0
  53. package/lib/shared-utils/addResizeListener.js +5 -0
  54. package/lib/shared-utils/animationFrame/BetterTween.js +38 -2
  55. package/lib/shared-utils/animationFrame/index.js +10 -2
  56. package/lib/shared-utils/animationFrame/tween.js +15 -2
  57. package/lib/shared-utils/createTransMatrix.js +17 -2
  58. package/lib/shared-utils/getFileExpandedName.js +1 -0
  59. package/lib/shared-utils/getMediaInfo.js +9 -0
  60. package/lib/shared-utils/setElementDataset.js +2 -0
  61. package/lib/typings/VreoUnit.d.ts +5 -5
  62. package/lib/typings/VreoUnit.js +15 -0
  63. package/package.json +1 -1
  64. package/resources/PlayController/index.ts +1 -1
  65. package/resources/Player/Controller.ts +3 -3
  66. package/resources/Player/index.tsx +1 -1
  67. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +2 -2
  68. package/resources/Player/modules/keyframes/BgMusic/index.tsx +23 -14
  69. package/resources/Player/modules/keyframes/PanoTag/index.tsx +1 -0
  70. package/resources/shared-utils/{AduioLike.ts → AudioLike.ts} +4 -6
  71. package/resources/typings/VreoUnit.ts +5 -5
  72. package/docs/demo/assets/default.9985006b.js +0 -3988
  73. package/docs/demo/assets/main.7963f418.js +0 -1
@@ -8,17 +8,22 @@ exports.getFileName = getFileName;
8
8
  exports.getMediaType = getMediaType;
9
9
  exports.getMediaTypeByExpandedName = getMediaTypeByExpandedName;
10
10
  exports.getMediaTypeByUrl = getMediaTypeByUrl;
11
+
11
12
  var _getFileExpandedName = _interopRequireDefault(require("./getFileExpandedName"));
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
13
16
  function getMediaInfo(fileUrl) {
14
17
  var type = getMediaType(fileUrl);
15
18
  if (!type) return Promise.resolve({
16
19
  error: '未知的文件类型: ' + fileUrl
17
20
  });
21
+
18
22
  var mediaElement = function () {
19
23
  if (type === 'video') return document.createElement('video');
20
24
  if (type === 'audio') return document.createElement('audio');
21
25
  }();
26
+
22
27
  if (!mediaElement) return Promise.resolve({
23
28
  error: 'Unknown media element'
24
29
  });
@@ -29,6 +34,7 @@ function getMediaInfo(fileUrl) {
29
34
  error: 'onerror'
30
35
  });
31
36
  };
37
+
32
38
  mediaElement.onloadedmetadata = function () {
33
39
  resolve({
34
40
  duration: mediaElement.duration * 1000,
@@ -43,6 +49,7 @@ function getMediaType(url) {
43
49
  var type = getMediaTypeByExpandedName(fileExpandedName);
44
50
  return type;
45
51
  }
52
+
46
53
  function getMediaTypeByExpandedName(fileExpandedName) {
47
54
  if (!fileExpandedName) return 'unknown';
48
55
  if (/jpg|jpeg|png$/.test(fileExpandedName)) return 'image';
@@ -50,11 +57,13 @@ function getMediaTypeByExpandedName(fileExpandedName) {
50
57
  if (/avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob$/.test(fileExpandedName)) return 'video';
51
58
  return 'unknown';
52
59
  }
60
+
53
61
  function getMediaTypeByUrl(fileUrl) {
54
62
  if (!fileUrl) return;
55
63
  var fileExpandedName = (0, _getFileExpandedName["default"])(fileUrl);
56
64
  return getMediaTypeByExpandedName(fileExpandedName);
57
65
  }
66
+
58
67
  function getFileName(fileUrl) {
59
68
  if (!fileUrl) return '';
60
69
  var index1 = fileUrl.lastIndexOf('/');
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = setElementDataset;
7
+
7
8
  function setElementDataset(element, dataset) {
8
9
  if (element) {
9
10
  Object.keys(dataset).forEach(function (key) {
10
11
  var value = dataset[key].toString();
12
+
11
13
  if (element instanceof Element) {
12
14
  element.setAttribute("data-".concat(key), value);
13
15
  } else if (element instanceof Document) {
@@ -85,10 +85,10 @@ export interface VreoVideo {
85
85
  * 剧本结构
86
86
  */
87
87
  export interface VreoUnit {
88
- categoryId: string;
89
- categoryText: string;
90
- frontRequestId: string;
91
- index: string | number;
88
+ categoryId?: string;
89
+ categoryText?: string;
90
+ frontRequestId?: string;
91
+ index?: string | number;
92
92
  keyframes: VreoKeyframe[];
93
93
  video: VreoVideo;
94
94
  }
@@ -96,7 +96,7 @@ export interface VreoUnit {
96
96
  * 剧本事件
97
97
  */
98
98
  export declare type VreoKeyframeEvent = {
99
- [key in VreoKeyframeEnum]: (keyframe: VreoKeyframe) => void;
99
+ [key in VreoKeyframeEnum]: (keyframe: VreoKeyframe, currentTime: number) => void;
100
100
  } & {
101
101
  loaded: (vreoUnit: VreoUnit) => void;
102
102
  paused: (ended?: boolean) => void;
@@ -8,7 +8,9 @@ var VreoKeyframeEnum;
8
8
  /**
9
9
  * 支持自定义剧本关键帧配置项
10
10
  */
11
+
11
12
  exports.VreoKeyframeEnum = VreoKeyframeEnum;
13
+
12
14
  (function (VreoKeyframeEnum) {
13
15
  VreoKeyframeEnum["CameraMovement"] = "CameraMovement";
14
16
  VreoKeyframeEnum["PanoTag"] = "PanoTag";
@@ -23,6 +25,7 @@ exports.VreoKeyframeEnum = VreoKeyframeEnum;
23
25
  VreoKeyframeEnum["Exit"] = "Exit";
24
26
  VreoKeyframeEnum["Custom"] = "Custom";
25
27
  })(VreoKeyframeEnum || (exports.VreoKeyframeEnum = VreoKeyframeEnum = {}));
28
+
26
29
  /**
27
30
  * 全景标签枚举
28
31
  */
@@ -30,17 +33,22 @@ var PanoTagEnum;
30
33
  /**
31
34
  * 标签样式种类
32
35
  */
36
+
33
37
  exports.PanoTagEnum = PanoTagEnum;
38
+
34
39
  (function (PanoTagEnum) {
35
40
  PanoTagEnum["Text"] = "Text";
36
41
  PanoTagEnum["Image"] = "Image";
37
42
  })(PanoTagEnum || (exports.PanoTagEnum = PanoTagEnum = {}));
43
+
38
44
  var PanoTagStyleEnum;
39
45
  exports.PanoTagStyleEnum = PanoTagStyleEnum;
46
+
40
47
  (function (PanoTagStyleEnum) {
41
48
  PanoTagStyleEnum["Growth"] = "Growth";
42
49
  PanoTagStyleEnum["Expand"] = "Expand";
43
50
  })(PanoTagStyleEnum || (exports.PanoTagStyleEnum = PanoTagStyleEnum = {}));
51
+
44
52
  /**
45
53
  * 全景特效枚举
46
54
  */
@@ -48,24 +56,31 @@ var PanoEffectEnum;
48
56
  /**
49
57
  * 全景特效
50
58
  */
59
+
51
60
  exports.PanoEffectEnum = PanoEffectEnum;
61
+
52
62
  (function (PanoEffectEnum) {
53
63
  PanoEffectEnum["Distance"] = "Distance";
54
64
  })(PanoEffectEnum || (exports.PanoEffectEnum = PanoEffectEnum = {}));
65
+
55
66
  /**
56
67
  * 信息面板类型枚举
57
68
  */
58
69
  var InfoPanelTypeEnum;
59
70
  exports.InfoPanelTypeEnum = InfoPanelTypeEnum;
71
+
60
72
  (function (InfoPanelTypeEnum) {
61
73
  InfoPanelTypeEnum["Image"] = "Image";
62
74
  InfoPanelTypeEnum["Video"] = "Video";
63
75
  })(InfoPanelTypeEnum || (exports.InfoPanelTypeEnum = InfoPanelTypeEnum = {}));
76
+
64
77
  var InfoPanelStyleEnum;
65
78
  /**
66
79
  * 信息面板
67
80
  */
81
+
68
82
  exports.InfoPanelStyleEnum = InfoPanelStyleEnum;
83
+
69
84
  (function (InfoPanelStyleEnum) {
70
85
  InfoPanelStyleEnum["Drawer"] = "Drawer";
71
86
  InfoPanelStyleEnum["PopUp"] = "PopUp";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/vreo",
3
- "version": "1.0.0-alpha.17",
3
+ "version": "1.0.0-alpha.19",
4
4
  "description": "Vreo (VR Video 缩写) 是基于如视三维渲染引擎 Five 和 用户界面构建库 React 实现的如视 3D 空间剧本播放器。",
5
5
  "keywords": [
6
6
  "realsee",
@@ -85,7 +85,7 @@ export class PlayController extends Subscribe<VreoKeyframeEvent> {
85
85
  currentKeyframes.forEach((keyframe) => {
86
86
  if (keyframe.parsed) return
87
87
  keyframe.parsed = true
88
- this.emit(keyframe.type, keyframe)
88
+ this.emit(keyframe.type, keyframe, this.currentTime)
89
89
  })
90
90
  })
91
91
 
@@ -231,7 +231,7 @@ export class Controller extends Subscribe<VreoKeyframeEvent> {
231
231
  /**
232
232
  * 逐帧任务
233
233
  */
234
- requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
234
+ requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe, currentTime: number) => void) {
235
235
  if (this.mediaInstance?.ended) {
236
236
  this.setEnded(true)
237
237
  this.setPlaying(false)
@@ -255,9 +255,9 @@ export class Controller extends Subscribe<VreoKeyframeEvent> {
255
255
  currentKeyframes.forEach((keyframe) => {
256
256
  if (keyframe.parsed) return
257
257
  keyframe.parsed = true
258
- this.emit(keyframe.type, keyframe)
258
+ this.emit(keyframe.type, keyframe, this.currentTime)
259
259
  if (callback) {
260
- callback(keyframe.type, keyframe)
260
+ callback(keyframe.type, keyframe, this.currentTime)
261
261
  }
262
262
  })
263
263
  }
@@ -163,7 +163,7 @@ export class Player extends Subscribe<VreoKeyframeEvent> {
163
163
  this.controller.setEnded(false)
164
164
  this.play()
165
165
 
166
- this.controller.run((type, keyframe) => this.emit(type, keyframe))
166
+ this.controller.run((type, keyframe) => this.emit(type, keyframe, this.controller.currentTime))
167
167
  this.controller.setLoading(false)
168
168
  return true
169
169
  }
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three'
2
2
  import { Preloader } from '../../../shared-utils/Preloader'
3
3
  import { makeObservable, observable, runInAction } from 'mobx'
4
- import AudioLike from '../../../shared-utils/AduioLike'
4
+ import AudioLike from '../../../shared-utils/AudioLike'
5
5
  import { getMediaType } from '../../../shared-utils/getMediaInfo'
6
6
 
7
7
  const vertexShader = `
@@ -280,7 +280,7 @@ export class VideoAgentMesh extends THREE.Mesh {
280
280
  }
281
281
 
282
282
  /**
283
- * 转成毫秒,保障精准度
283
+ * 秒转成毫秒,保障精准度
284
284
  */
285
285
  get currentTime() {
286
286
  return this.mediaInstance.currentTime * 1000
@@ -2,6 +2,23 @@ import * as React from 'react'
2
2
  import { BgMusicData, VreoKeyframe, VreoKeyframeEnum } from '../../../../typings/VreoUnit'
3
3
  import { useController } from '../../../hooks'
4
4
 
5
+ const audioList: HTMLAudioElement[] = []
6
+ function getAudio(src: string = '', currentTime: number = 0) {
7
+ const audio = (() => {
8
+ const audio = audioList.find(audio => audio.src === src)
9
+ if (audio) return audio
10
+ else {
11
+ const newAudio = new Audio(src)
12
+ audioList.push(newAudio)
13
+ return newAudio
14
+ }
15
+ })()
16
+ audio.currentTime = currentTime
17
+ audio.setAttribute('playsinline', 'true')
18
+ audio.loop = true
19
+ return audio
20
+ }
21
+
5
22
  export function BgMusic() {
6
23
  const controller = useController()
7
24
  const timeoutIdRef = React.useRef<NodeJS.Timeout | null>(null)
@@ -13,18 +30,10 @@ export function BgMusic() {
13
30
  }, [])
14
31
 
15
32
  React.useEffect(() => {
16
- const audio = new Audio()
17
- audio.setAttribute('id', 'vreo-singleton-bgmusic')
18
- audio.style.display = 'none'
19
-
20
- audio.setAttribute('playsinline', 'true')
21
- audio.loop = true
22
- document.body.append(audio)
23
-
24
- const callback = (keyframe: VreoKeyframe) => {
33
+ const callback = (keyframe: VreoKeyframe, currentTime: number) => {
34
+ console.log({currentTime})
25
35
  const { start, end } = keyframe
26
- const { url } = keyframe.data as BgMusicData
27
- audio.src = url
36
+ const audio = getAudio(keyframe.data.url, Math.max(currentTime - start, 0))
28
37
  const playCallback = () => {
29
38
  audio.play()
30
39
  }
@@ -34,16 +43,17 @@ export function BgMusic() {
34
43
  cleanTimeout()
35
44
 
36
45
  const cleanAudio = () => {
46
+ console.log('cleanAudio', keyframe.start)
37
47
  audio.pause()
38
- audio.currentTime = 0
39
48
  audio.src = ''
40
49
  cleanTimeout()
41
50
  audio.removeEventListener('canplaythrough', playCallback)
42
51
  }
43
52
 
44
- const duration = (end - start) || 5000
53
+ const duration = end - start
45
54
 
46
55
  timeoutIdRef.current = setTimeout(() => {
56
+ console.log('timeout', duration)
47
57
  cleanAudio()
48
58
  }, duration)
49
59
 
@@ -57,7 +67,6 @@ export function BgMusic() {
57
67
 
58
68
  return () => {
59
69
  controller.off(VreoKeyframeEnum.BgMusic, callback)
60
- document.body.removeChild(audio)
61
70
  cleanTimeout()
62
71
  }
63
72
  })
@@ -53,6 +53,7 @@ export function PanoTag() {
53
53
  timeoutRef.current = setTimeout(() => {
54
54
  // clear
55
55
  const tag = panoTagPlugin.current.getTagById(id)
56
+ if (!tag) return
56
57
  if (tag.state) {
57
58
  tag.state.unfolded = false
58
59
  ;(panoTagPlugin.current as any).updateRenderAllTags()
@@ -43,7 +43,7 @@ export class AudioLike extends Subscribe<AudioLikeEvent> {
43
43
  this.$currentTime = 0
44
44
  }
45
45
  if (this.$timestamp === null) {
46
- this.$timestamp = performance.now() - this.$currentTime
46
+ this.$timestamp = performance.now()
47
47
  }
48
48
  this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop())
49
49
  this.emit('play')
@@ -61,7 +61,8 @@ export class AudioLike extends Subscribe<AudioLikeEvent> {
61
61
  requestAnimationFrameLoop() {
62
62
  if (this.$timestamp === null) return
63
63
  const now = performance.now()
64
- this.$currentTime = now - this.$timestamp
64
+ this.$currentTime += (now - this.$timestamp)
65
+ this.$timestamp = now
65
66
  this.emit('timeupdate')
66
67
  if (this.$currentTime >= this.$duration - 10) {
67
68
  this.$currentTime = this.$duration
@@ -75,7 +76,7 @@ export class AudioLike extends Subscribe<AudioLikeEvent> {
75
76
  }
76
77
 
77
78
  set currentTime(time: number) {
78
- this.$currentTime = time
79
+ this.$currentTime = time * 1000
79
80
  }
80
81
 
81
82
  get duration() {
@@ -83,10 +84,7 @@ export class AudioLike extends Subscribe<AudioLikeEvent> {
83
84
  }
84
85
 
85
86
  set duration(duration: number) {
86
- this.pause()
87
87
  this.$duration = duration
88
- this.$timestamp = null
89
- this.$currentTime = 0
90
88
  }
91
89
 
92
90
  get ended() {
@@ -91,10 +91,10 @@ export interface VreoVideo {
91
91
  * 剧本结构
92
92
  */
93
93
  export interface VreoUnit {
94
- categoryId: string
95
- categoryText: string
96
- frontRequestId: string
97
- index: string | number
94
+ categoryId?: string
95
+ categoryText?: string
96
+ frontRequestId?: string
97
+ index?: string | number
98
98
  keyframes: VreoKeyframe[]
99
99
  video: VreoVideo
100
100
  }
@@ -104,7 +104,7 @@ export interface VreoUnit {
104
104
  /**
105
105
  * 剧本事件
106
106
  */
107
- export type VreoKeyframeEvent = { [key in VreoKeyframeEnum]: (keyframe: VreoKeyframe) => void } & {
107
+ export type VreoKeyframeEvent = { [key in VreoKeyframeEnum]: (keyframe: VreoKeyframe, currentTime: number) => void } & {
108
108
  // 新数据载入完成
109
109
  loaded: (vreoUnit: VreoUnit) => void
110
110
  // 语音状态 播放 -> 暂停