@realsee/vreo 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (166) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +46 -36
  3. package/lib/PlayController/createHTMLAudioElement.js +6 -11
  4. package/lib/PlayController/index.js +16 -81
  5. package/lib/Player/App.js +0 -24
  6. package/lib/Player/Controller.d.ts +3 -3
  7. package/lib/Player/Controller.js +47 -105
  8. package/lib/Player/custom/SpatialScenePanel/index.js +42 -68
  9. package/lib/Player/hooks.js +0 -10
  10. package/lib/Player/index.js +40 -87
  11. package/lib/Player/modules/Drawer/index.js +0 -17
  12. package/lib/Player/modules/PopUp/index.js +0 -10
  13. package/lib/Player/modules/ResizeObserver/index.js +0 -8
  14. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +2 -2
  15. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +20 -114
  16. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +2 -24
  17. package/lib/Player/modules/VideoAgent/index.js +1 -18
  18. package/lib/Player/modules/Wave/index.js +160 -36
  19. package/lib/Player/modules/keyframes/BgMusic/index.js +50 -51
  20. package/lib/Player/modules/keyframes/CameraMovement/index.js +3 -27
  21. package/lib/Player/modules/keyframes/InfoPanel/index.js +8 -25
  22. package/lib/Player/modules/keyframes/ModelVideo/index.js +3 -29
  23. package/lib/Player/modules/keyframes/PanoEffect/index.js +15 -43
  24. package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +0 -7
  25. package/lib/Player/modules/keyframes/PanoTag/index.js +7 -23
  26. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +22 -47
  27. package/lib/Player/modules/keyframes/Prompter/index.js +10 -32
  28. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +18 -25
  29. package/lib/Player/modules/keyframes/VideoEffect/index.js +12 -47
  30. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +0 -2
  31. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +0 -1
  32. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +0 -1
  33. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +19 -60
  34. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +2 -5
  35. package/lib/fivePlugins/CameraMovementPlugin/index.js +28 -75
  36. package/lib/fivePlugins/CameraMovementPlugin/typings.js +0 -4
  37. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +11 -60
  38. package/lib/index.js +0 -1
  39. package/lib/react/index.js +7 -34
  40. package/lib/shared-utils/Audio.d.ts +14 -0
  41. package/lib/shared-utils/Audio.js +159 -0
  42. package/lib/shared-utils/{AduioLike.d.ts → AudioLike.d.ts} +0 -0
  43. package/lib/shared-utils/{AduioLike.js → AudioLike.js} +9 -45
  44. package/lib/shared-utils/Preloader.js +0 -7
  45. package/lib/shared-utils/addResizeListener.js +0 -5
  46. package/lib/shared-utils/animationFrame/BetterTween.js +2 -38
  47. package/lib/shared-utils/animationFrame/index.js +2 -10
  48. package/lib/shared-utils/animationFrame/tween.js +2 -15
  49. package/lib/shared-utils/createTransMatrix.js +2 -17
  50. package/lib/shared-utils/getFileExpandedName.js +0 -1
  51. package/lib/shared-utils/getMediaInfo.js +0 -9
  52. package/lib/shared-utils/setElementDataset.js +0 -2
  53. package/lib/typings/VreoUnit.d.ts +5 -5
  54. package/lib/typings/VreoUnit.js +0 -15
  55. package/package.json +2 -4
  56. package/stylesheets/default.css +11 -4
  57. package/docs/.nojekyll +0 -1
  58. package/docs/assets/custom.css +0 -78
  59. package/docs/assets/highlight.css +0 -127
  60. package/docs/assets/icons.css +0 -1043
  61. package/docs/assets/icons.png +0 -0
  62. package/docs/assets/icons@2x.png +0 -0
  63. package/docs/assets/main.js +0 -52
  64. package/docs/assets/search.js +0 -1
  65. package/docs/assets/style.css +0 -1414
  66. package/docs/assets/widgets.png +0 -0
  67. package/docs/assets/widgets@2x.png +0 -0
  68. package/docs/classes/Player.AudioLike.html +0 -52
  69. package/docs/classes/Player.Controller.html +0 -54
  70. package/docs/classes/Player.Player-1.html +0 -50
  71. package/docs/classes/Player.VideoAgentMesh.html +0 -142
  72. package/docs/classes/Player.VideoAgentScene.html +0 -1
  73. package/docs/demo/assets/AppReact.39bef668.js +0 -1
  74. package/docs/demo/assets/default.9bbb3329.js +0 -3984
  75. package/docs/demo/assets/default.f3f3ca8c.css +0 -1
  76. package/docs/demo/assets/dynamic.5e9275ce.js +0 -1
  77. package/docs/demo/assets/examples.2ac45f33.js +0 -25
  78. package/docs/demo/assets/examples.dac4a6fe.css +0 -1
  79. package/docs/demo/assets/index.6699bd11.js +0 -1
  80. package/docs/demo/assets/index.9331038f.css +0 -1
  81. package/docs/demo/assets/main.a0741cbc.js +0 -1
  82. package/docs/demo/assets/react.2ee8565f.css +0 -1
  83. package/docs/demo/assets/react.a3f20ea9.js +0 -25
  84. package/docs/demo/assets/znRoyv06SZQeqA7m.0057e8ae.js +0 -1
  85. package/docs/demo/examples.html +0 -17
  86. package/docs/demo/index-react-dynamic.html +0 -20
  87. package/docs/demo/index-react.html +0 -20
  88. package/docs/demo/index.html +0 -19
  89. package/docs/enums/Player.InfoPanelStyleEnum.html +0 -1
  90. package/docs/enums/Player.InfoPanelTypeEnum.html +0 -3
  91. package/docs/enums/Player.PanoEffectEnum.html +0 -5
  92. package/docs/enums/Player.PanoTagEnum.html +0 -3
  93. package/docs/enums/Player.PanoTagStyleEnum.html +0 -7
  94. package/docs/enums/Player.VreoKeyframeEnum.html +0 -25
  95. package/docs/enums/fivePlugins.CameraMovementEffect.html +0 -1
  96. package/docs/enums/fivePlugins.Rotation.html +0 -1
  97. package/docs/index.html +0 -245
  98. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +0 -1
  99. package/docs/interfaces/Player.PlayerConfigs.html +0 -7
  100. package/docs/interfaces/Player.Vertex.html +0 -3
  101. package/docs/interfaces/Player.VideoAgentMeshOptions.html +0 -8
  102. package/docs/interfaces/Player.VreoKeyframe.html +0 -3
  103. package/docs/interfaces/Player.VreoUnit.html +0 -3
  104. package/docs/interfaces/Player.VreoVideo.html +0 -3
  105. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +0 -4
  106. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +0 -1
  107. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +0 -7
  108. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +0 -1
  109. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +0 -1
  110. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +0 -1
  111. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +0 -1
  112. package/docs/interfaces/fivePlugins.Vector3Position.html +0 -3
  113. package/docs/interfaces/react.VreoActionCallbacks.html +0 -23
  114. package/docs/interfaces/react.VreoProviderProps.html +0 -1
  115. package/docs/modules/Player.html +0 -37
  116. package/docs/modules/custom.html +0 -3
  117. package/docs/modules/fivePlugins.html +0 -6
  118. package/docs/modules/react.html +0 -1
  119. package/docs/modules.html +0 -1
  120. package/resources/PlayController/createHTMLAudioElement.ts +0 -53
  121. package/resources/PlayController/index.ts +0 -154
  122. package/resources/Player/App.tsx +0 -66
  123. package/resources/Player/Controller.ts +0 -297
  124. package/resources/Player/custom/SpatialScenePanel/index.tsx +0 -264
  125. package/resources/Player/hooks.ts +0 -26
  126. package/resources/Player/index.tsx +0 -225
  127. package/resources/Player/modules/Drawer/index.tsx +0 -40
  128. package/resources/Player/modules/PopUp/index.tsx +0 -26
  129. package/resources/Player/modules/ResizeObserver/index.tsx +0 -23
  130. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +0 -302
  131. package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +0 -56
  132. package/resources/Player/modules/VideoAgent/index.tsx +0 -53
  133. package/resources/Player/modules/Wave/index.tsx +0 -18
  134. package/resources/Player/modules/keyframes/BgMusic/index.tsx +0 -66
  135. package/resources/Player/modules/keyframes/CameraMovement/index.tsx +0 -37
  136. package/resources/Player/modules/keyframes/InfoPanel/index.tsx +0 -165
  137. package/resources/Player/modules/keyframes/ModelVideo/index.tsx +0 -77
  138. package/resources/Player/modules/keyframes/PanoEffect/index.tsx +0 -99
  139. package/resources/Player/modules/keyframes/PanoEffect/lineAnime.ts +0 -31
  140. package/resources/Player/modules/keyframes/PanoTag/index.tsx +0 -83
  141. package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +0 -117
  142. package/resources/Player/modules/keyframes/Prompter/index.tsx +0 -56
  143. package/resources/Player/modules/keyframes/UpdateVRPanorama/index.tsx +0 -99
  144. package/resources/Player/modules/keyframes/VideoEffect/index.tsx +0 -115
  145. package/resources/Player/typings.ts +0 -49
  146. package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +0 -5
  147. package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +0 -17
  148. package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +0 -4
  149. package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +0 -254
  150. package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +0 -5
  151. package/resources/fivePlugins/CameraMovementPlugin/index.ts +0 -226
  152. package/resources/fivePlugins/CameraMovementPlugin/typings.ts +0 -59
  153. package/resources/fivePlugins/ModelTVVideoPlugin/index.ts +0 -278
  154. package/resources/index.ts +0 -1
  155. package/resources/react/index.tsx +0 -121
  156. package/resources/shared-utils/AduioLike.ts +0 -109
  157. package/resources/shared-utils/Preloader.ts +0 -35
  158. package/resources/shared-utils/addResizeListener.ts +0 -46
  159. package/resources/shared-utils/animationFrame/BetterTween.ts +0 -33
  160. package/resources/shared-utils/animationFrame/index.ts +0 -48
  161. package/resources/shared-utils/animationFrame/tween.ts +0 -51
  162. package/resources/shared-utils/createTransMatrix.ts +0 -12
  163. package/resources/shared-utils/getFileExpandedName.ts +0 -6
  164. package/resources/shared-utils/getMediaInfo.ts +0 -52
  165. package/resources/shared-utils/setElementDataset.ts +0 -18
  166. package/resources/typings/VreoUnit.ts +0 -314
@@ -1,154 +0,0 @@
1
- import { Subscribe } from '@realsee/five'
2
- import { requestAnimationFrameInterval } from '../shared-utils/animationFrame'
3
- import { VreoKeyframe, VreoKeyframeEvent, VreoUnit } from '../typings/VreoUnit'
4
- import { createHTMLAudioElement } from './createHTMLAudioElement'
5
-
6
- export interface PlayControllerConfig {
7
- audio?: HTMLAudioElement
8
- }
9
-
10
- const closures: Record<string, any> = {}
11
-
12
- export class PlayController extends Subscribe<VreoKeyframeEvent> {
13
-
14
- vreoUnit?: VreoUnit
15
-
16
- config: PlayControllerConfig = {}
17
- stopInterval: () => void
18
-
19
- get paused() {
20
- return this.audioInstance.paused
21
- }
22
-
23
- get audioInstance() {
24
- return this.config.audio!
25
- }
26
-
27
- get currentTime() {
28
- return this.audioInstance.currentTime * 1000
29
- }
30
-
31
- get currentKeyframes() {
32
- if (!this.vreoUnit) return []
33
- const keyframes = this.vreoUnit.keyframes
34
- // 没有被解析过且开始时间低于当前时间戳 100ms
35
- return keyframes.filter((keyframe: VreoKeyframe) => {
36
- if (keyframe.parsed) return false
37
- const dur = this.currentTime - keyframe.start
38
- return dur <= 100 && dur >= 0
39
- })
40
- }
41
-
42
- /**
43
- * 音频时长 不一定能获取得到,建议以 VreoUnit 配置的时长为准。
44
- */
45
- get duration() {
46
- return this.audioInstance.duration * 1000
47
- }
48
-
49
- constructor(config: PlayControllerConfig = {}) {
50
- super()
51
-
52
- if (!config.audio) {
53
- config.audio = createHTMLAudioElement()
54
- }
55
-
56
- this.config = Object.assign(this.config, config)
57
-
58
- closures.onPlaying = () => this.emit('playing')
59
- closures.onPaused = () => this.emit('paused')
60
- closures.onEnded = () => this.emit('paused', true)
61
-
62
- this.audioInstance.addEventListener('play', closures.onPlaying)
63
- this.audioInstance.addEventListener('pause', closures.onPaused)
64
- this.audioInstance.addEventListener('ended', closures.onEnded)
65
-
66
- this.stopInterval = requestAnimationFrameInterval(() => {
67
- if (this.audioInstance.paused) {
68
- return
69
- }
70
-
71
- if (!this.vreoUnit) {
72
- return
73
- }
74
-
75
- const keyframes = this.vreoUnit.keyframes
76
- const currentTime = this.currentTime
77
- // 没有被解析过且开始时间低于当前时间戳 100ms
78
- const currentKeyframes = keyframes.filter((keyframe: VreoKeyframe) => {
79
- if (keyframe.parsed) return false
80
-
81
- const dur = currentTime - keyframe.start
82
- return dur <= 60 && dur >= 0
83
- })
84
-
85
- currentKeyframes.forEach((keyframe) => {
86
- if (keyframe.parsed) return
87
- keyframe.parsed = true
88
- this.emit(keyframe.type, keyframe)
89
- })
90
- })
91
-
92
- }
93
-
94
-
95
-
96
- /**
97
- * 载入数据
98
- */
99
- async load(vreoUnit: VreoUnit): Promise<boolean> {
100
- this.vreoUnit = vreoUnit
101
-
102
- await this.pause()
103
- return await new Promise((resolve, reject) => {
104
- if (vreoUnit.video.url === this.audioInstance.src) {
105
- return resolve(true)
106
- }
107
-
108
- this.audioInstance.src = vreoUnit.video.url
109
- const canplaythrough = () => {
110
- resolve(true)
111
- this.audioInstance.removeEventListener('canplaythrough', canplaythrough)
112
- }
113
- const error = (err: any) => {
114
- reject(err)
115
- this.audioInstance.removeEventListener('error', error)
116
- }
117
- this.audioInstance.addEventListener('canplaythrough', canplaythrough)
118
- this.audioInstance.addEventListener('error', error)
119
- })
120
- }
121
-
122
- /**
123
- * 播放
124
- */
125
- async play() {
126
- closures.playPromise = this.audioInstance.play()
127
- }
128
-
129
- /**
130
- * 暂停
131
- */
132
- async pause() {
133
- if (closures.playPromise) {
134
- await closures.playPromise
135
- }
136
- this.audioInstance.pause()
137
- }
138
-
139
- /**
140
- * 销毁资源
141
- * @notice 一旦销毁,创建的实例将不可用:需重新创建实例。
142
- *
143
- * @deprecated **慎重执行**
144
- */
145
- dispose() {
146
- // 清理事件监听
147
- this.audioInstance.removeEventListener('play', closures.onPlaying)
148
- this.audioInstance.removeEventListener('pasue', closures.onPaused)
149
- this.audioInstance.removeEventListener('ended', closures.onEnded)
150
- if (this.stopInterval) {
151
- this.stopInterval()
152
- }
153
- }
154
- }
@@ -1,66 +0,0 @@
1
- import * as React from 'react'
2
- import classNames from 'classnames'
3
- import { observer } from 'mobx-react'
4
- import { Controller } from './Controller'
5
- import { useController } from './hooks'
6
- import { CameraMovement } from './modules/keyframes/CameraMovement'
7
- import { ResizeObserver } from './modules/ResizeObserver'
8
- import { InfoPanel } from './modules/keyframes/InfoPanel'
9
- import { ModelVideo } from './modules/keyframes/ModelVideo'
10
- import { PanoEffect } from './modules/keyframes/PanoEffect'
11
- import { PanoTag } from './modules/keyframes/PanoTag'
12
- import { PanoTextLabel } from './modules/keyframes/PanoTextLabel'
13
- import { Prompter } from './modules/keyframes/Prompter'
14
- import { UpdateVRPanorama } from './modules/keyframes/UpdateVRPanorama'
15
- import { VideoEffect } from './modules/keyframes/VideoEffect'
16
- import { VideoAgent } from './modules/VideoAgent'
17
- import { BgMusic } from './modules/keyframes/BgMusic'
18
- import { Wave } from './modules/Wave'
19
-
20
- const AppView = observer(({ controller }: { controller: Controller }) => {
21
-
22
- return (
23
- <div
24
- className={classNames('vreo-panel', {
25
- 'vreo-panel--hidden': !controller.visible,
26
- })}
27
- >
28
- <div className="vreo-panel-inner">
29
- {controller.waveAppearance && <Wave appearance={controller.waveAppearance}/>}
30
- <VideoAgent
31
- onClick={() => {
32
- if (controller.playing) {
33
- controller.setPlaying(false)
34
- } else {
35
- controller.setPlaying(true)
36
- }
37
- }}
38
- options={controller.configs?.videoAgentMeshOptions || {}}
39
- />
40
- <Prompter />
41
- {controller.configs?.customPanelChildren}
42
- </div>
43
- </div>
44
- )
45
- })
46
-
47
- export function App() {
48
- const controller = useController()
49
- return (
50
- <>
51
- <>
52
- <ResizeObserver />
53
- <CameraMovement />
54
- <ModelVideo />
55
- <UpdateVRPanorama />
56
- <VideoEffect />
57
- <PanoTag />
58
- <PanoTextLabel />
59
- <InfoPanel />
60
- <PanoEffect />
61
- <BgMusic />
62
- </>
63
- <AppView controller={controller} />
64
- </>
65
- )
66
- }
@@ -1,297 +0,0 @@
1
- import { Five, Subscribe } from '@realsee/five'
2
- import { action, computed, makeObservable, observable, reaction } from 'mobx'
3
- import * as React from 'react'
4
- import { requestAnimationFrameInterval } from '../shared-utils/animationFrame'
5
- import { VreoKeyframe, VreoKeyframeEnum, VreoKeyframeEvent, VreoUnit, VreoVideo } from '../typings/VreoUnit'
6
- import { VideoAgentScene } from './modules/VideoAgent/VideoAgentScene'
7
- import { Appearance, PlayerConfigs, WaveAppearance } from './typings'
8
- import setElementDataset from '../shared-utils/setElementDataset'
9
- import { getMediaType } from '../shared-utils/getMediaInfo'
10
-
11
- /**
12
- * 逻辑控制器:内部状态。
13
- */
14
- export class Controller extends Subscribe<VreoKeyframeEvent> {
15
-
16
- five: Five
17
- configs: PlayerConfigs
18
- videoAgentScene?: VideoAgentScene
19
- vreoUnit?: VreoUnit
20
- stopInterval?: () => void
21
- playing = false
22
- ended = false
23
- loading: boolean | null = false // null 表示加载失败
24
- containerSize?: {
25
- width: number
26
- height: number
27
- }
28
- appSize?: 'S' | 'M' | 'L' | 'XL'
29
- container: Element
30
- waveAppearance: WaveAppearance | null = null
31
- appearance: Appearance = {
32
- waveStyle: 'solid',
33
- }
34
- avatar: VreoVideo['avatar'] = {}
35
-
36
-
37
- visible = false
38
-
39
- get agentType() {
40
- const type = getMediaType(this.videoAgentScene?.videoAgentMesh.videoUrl)
41
- if (this.avatar?.force) return 'avatar'
42
- if (type === 'video') return 'video'
43
- return 'none'
44
- }
45
-
46
- popUp: string | JSX.Element | null = null
47
-
48
- openPopUp(popUp: string | JSX.Element | false) {
49
- if (!popUp) {
50
- this.popUp = null
51
- return
52
- }
53
- this.popUp = popUp
54
- }
55
-
56
- setLoading(loading: boolean | null) {
57
- this.loading = loading
58
- }
59
-
60
- drawerConfig: {
61
- content: string | JSX.Element
62
- height?: number | string
63
- } | null = null
64
-
65
- setAvatar(avatar: VreoVideo['avatar']) {
66
- this.avatar = avatar
67
- }
68
-
69
- setContainerSize(width: number, height: number) {
70
- this.containerSize = { width, height }
71
- }
72
-
73
- setVisible(v: boolean) {
74
- this.visible = v
75
- }
76
-
77
- setPlaying(playing: boolean) {
78
- this.playing = playing
79
- }
80
-
81
- setEnded(ended: boolean) {
82
- this.ended = ended
83
- }
84
-
85
- setAppearance(appearance: Appearance) {
86
- this.appearance = { ...this.appearance, ...appearance }
87
- }
88
-
89
- openDrawer(drawerConfig?: false | { content: string | JSX.Element; height?: number | string }) {
90
- if (!drawerConfig) {
91
- this.drawerConfig = {
92
- content: '',
93
- height: this.drawerConfig?.height
94
- }
95
- return
96
- }
97
-
98
- this.drawerConfig = drawerConfig
99
- }
100
-
101
- constructor({five, container, configs}: { five: Five, container: Element, configs: PlayerConfigs }) {
102
- super()
103
-
104
- this.configs = configs
105
- this.container = container
106
- this.five = five
107
- this.appSize = configs.appSize
108
- this.appearance = { ...this.appearance, ...configs.appearance }
109
-
110
- makeObservable(this, {
111
- visible: observable,
112
- setVisible: action,
113
- playing: observable,
114
- setPlaying: action,
115
- loading: observable,
116
- setLoading: action,
117
- popUp: observable.ref,
118
- openPopUp: action,
119
- drawerConfig: observable.ref,
120
- openDrawer: action,
121
- ended: observable,
122
- waveAppearance: observable,
123
- avatar: observable,
124
- containerSize: observable,
125
- setContainerSize: action,
126
- appearance: observable,
127
- setAppearance: action,
128
- configs: observable.ref,
129
- setEnded: action,
130
- setAvatar: action,
131
- })
132
-
133
- reaction<[typeof this.appearance.waveStyle, boolean | null], boolean>(
134
- () => [this.appearance.waveStyle, this.loading],
135
- ([waveStyle, loading]) => {
136
- if (loading === null) {
137
- this.waveAppearance = null
138
- return
139
- }
140
- if (waveStyle === 'wave') {
141
- switch (loading) {
142
- case true:
143
- this.waveAppearance = 'double'
144
- break
145
- case false:
146
- this.waveAppearance = 'solid'
147
- break
148
- }
149
- } else if (waveStyle === 'solid') {
150
- switch (loading) {
151
- case true:
152
- this.waveAppearance = 'swap'
153
- break
154
- case false:
155
- this.waveAppearance = 'expand'
156
- break
157
- }
158
- }
159
- },
160
- { fireImmediately: true }
161
- )
162
-
163
- if (!this.appSize) {
164
- reaction(
165
- () => this.containerSize,
166
- (containerSize) => {
167
- if (!containerSize) return
168
- const width = containerSize.width
169
- const height = containerSize.height
170
- const size = (() => {
171
- if (width <= 500) return 'S'
172
- if (width <= 1024) return 'M'
173
- if (width <= 2048) return 'L'
174
- return 'XL'
175
- })()
176
- const orientation = (() => {
177
- if (height > width) return 'portrait'
178
- return 'landscape'
179
- })()
180
- setElementDataset(this.container, { size })
181
- setElementDataset(this.container, { orientation })
182
- },
183
- { fireImmediately: true }
184
- )
185
- } else {
186
- setElementDataset(this.container, { size: this.appSize })
187
- }
188
-
189
- // 监听播放情况:抛出触发时机
190
- reaction(
191
- () => this.ended,
192
- (ended) => {
193
- if (ended) {
194
- this.emit('paused', true)
195
- }
196
- }
197
- )
198
-
199
- reaction(
200
- () => this.playing,
201
- (playing) => {
202
- if (!this.ended) {
203
- this.emit(playing ? 'playing' : 'paused')
204
- }
205
- }
206
- )
207
-
208
- }
209
-
210
- get ready() {
211
- return !!this.videoAgentScene
212
- }
213
-
214
- get currentTime() {
215
- return this.videoAgentScene?.videoAgentMesh.currentTime || 0
216
- }
217
-
218
- get currentKeyframes() {
219
- if (!this.vreoUnit) return []
220
- const keyframes = this.vreoUnit.keyframes
221
- // 没有被解析过且开始时间低于当前时间戳 100ms
222
- return keyframes.filter((keyframe: VreoKeyframe) => {
223
- if (keyframe.parsed) return false
224
- const dur = this.currentTime - keyframe.start
225
- return dur <= 100 && dur >= 0
226
- })
227
- }
228
-
229
- get mediaInstance() {
230
- return this.videoAgentScene?.videoAgentMesh.mediaInstance
231
- }
232
-
233
- /**
234
- * 逐帧任务
235
- */
236
- requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
237
- if (this.mediaInstance?.ended) {
238
- this.setEnded(true)
239
- this.setPlaying(false)
240
- this.mediaInstance.pause()
241
- return
242
- }
243
-
244
- if (!this.playing) {
245
- if (!this.mediaInstance?.paused) {
246
- this.mediaInstance?.pause()
247
- }
248
- return
249
- }
250
-
251
- if (this.mediaInstance?.paused && this.playing) {
252
- this.mediaInstance.play()
253
- }
254
-
255
- const currentKeyframes = this.currentKeyframes
256
-
257
- currentKeyframes.forEach((keyframe) => {
258
- if (keyframe.parsed) return
259
- keyframe.parsed = true
260
- this.emit(keyframe.type, keyframe)
261
- if (callback) {
262
- callback(keyframe.type, keyframe)
263
- }
264
- })
265
- }
266
-
267
- run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
268
- if (this.stopInterval) return
269
- this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
270
- }
271
-
272
- dispose() {
273
- this.setPlaying(false)
274
-
275
- if (this.currentKeyframes) {
276
- this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
277
- }
278
-
279
- /**
280
- * 清理掉数据
281
- */
282
- this.vreoUnit = undefined
283
- if (this.mediaInstance) {
284
- this.mediaInstance.currentTime = 0
285
- }
286
-
287
- if (this.stopInterval) {
288
- this.stopInterval()
289
- this.stopInterval = undefined
290
- }
291
- }
292
- }
293
-
294
- const ControllerContext = React.createContext<Controller | null>(null)
295
-
296
- export { ControllerContext }
297
-