@realsee/vreo 0.1.3 → 0.1.4
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.
- package/docs/assets/search.js +1 -1
- package/docs/classes/Player.Player-1.html +6 -6
- package/docs/enums/Player.InfoPanelTypeEnum.html +1 -1
- package/docs/enums/Player.PanoEffectEnum.html +1 -1
- package/docs/enums/Player.PanoTagEnum.html +1 -1
- package/docs/enums/Player.VreoKeyframeEnum.html +10 -10
- package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
- package/docs/enums/fivePlugins.Rotation.html +1 -1
- package/docs/interfaces/Player.PlayerConfigs.html +1 -1
- package/docs/interfaces/Player.Vertex.html +1 -1
- package/docs/interfaces/Player.VreoKeyframe.html +1 -1
- package/docs/interfaces/Player.VreoUnit.html +1 -1
- package/docs/interfaces/Player.VreoVideo.html +1 -1
- package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
- package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
- package/docs/interfaces/react.VreoActionCallbacks.html +6 -6
- package/docs/modules/Player.html +11 -11
- package/docs/modules/fivePlugins.html +2 -2
- package/docs/modules/react.html +1 -1
- package/lib/Player/index.d.ts +1 -0
- package/lib/Player/index.js +33 -28
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +2 -0
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +59 -21
- package/lib/Player/modules/VideoAgent/VideoAgentScene.d.ts +1 -0
- package/lib/Player/modules/VideoAgent/VideoAgentScene.js +6 -0
- package/lib/Player/modules/VideoAgent/index.js +6 -0
- package/lib/react/index.js +6 -2
- package/package.json +2 -2
- package/resources/Player/Controller.ts +0 -3
- package/resources/Player/index.tsx +31 -25
- package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +62 -19
- package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +4 -0
- package/resources/Player/modules/VideoAgent/index.tsx +5 -0
- package/resources/react/index.tsx +5 -2
|
@@ -9,18 +9,19 @@ import { reaction } from 'mobx'
|
|
|
9
9
|
import { Drawer } from './modules/Drawer'
|
|
10
10
|
import { PlayerConfigs } from './typings'
|
|
11
11
|
|
|
12
|
-
const controller = new Controller()
|
|
13
|
-
|
|
14
12
|
export class Player extends Subscribe<VreoKeyframeEvent> {
|
|
15
13
|
$five: Five
|
|
14
|
+
private controller: Controller
|
|
16
15
|
configs: Readonly<PlayerConfigs>
|
|
17
16
|
|
|
18
17
|
constructor(five: Five, configs: Partial<PlayerConfigs> = {}) {
|
|
19
18
|
super()
|
|
20
|
-
this
|
|
19
|
+
this.controller = new Controller()
|
|
20
|
+
this.$five = this.controller.$five = five
|
|
21
21
|
|
|
22
22
|
if (!configs.containter) {
|
|
23
|
-
const containter = document.createElement('div')
|
|
23
|
+
const containter = document.querySelector('#vreo-app') || document.createElement('div')
|
|
24
|
+
ReactDOM.unmountComponentAtNode(containter)
|
|
24
25
|
containter.setAttribute('id', 'vreo-app')
|
|
25
26
|
configs.containter = containter
|
|
26
27
|
document.body.append(containter)
|
|
@@ -35,10 +36,10 @@ export class Player extends Subscribe<VreoKeyframeEvent> {
|
|
|
35
36
|
)
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
controller.configs = this.configs
|
|
39
|
+
this.controller.configs = this.configs
|
|
39
40
|
|
|
40
41
|
ReactDOM.render(
|
|
41
|
-
<ControllerContext.Provider value={controller}>
|
|
42
|
+
<ControllerContext.Provider value={this.controller}>
|
|
42
43
|
<App></App>
|
|
43
44
|
<Drawer />
|
|
44
45
|
</ControllerContext.Provider>,
|
|
@@ -47,7 +48,7 @@ export class Player extends Subscribe<VreoKeyframeEvent> {
|
|
|
47
48
|
|
|
48
49
|
// 监听播放情况:抛出触发时机
|
|
49
50
|
reaction(
|
|
50
|
-
() => controller.playing,
|
|
51
|
+
() => this.controller.playing,
|
|
51
52
|
(playing) => {
|
|
52
53
|
this.emit(playing ? 'playing' : 'paused')
|
|
53
54
|
}
|
|
@@ -55,56 +56,61 @@ export class Player extends Subscribe<VreoKeyframeEvent> {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
async load(vreoUnit: VreoUnit, currentTime = 0) {
|
|
58
|
-
if (!controller.visible) {
|
|
59
|
-
controller.setVisible(true)
|
|
59
|
+
if (!this.controller.visible) {
|
|
60
|
+
this.controller.setVisible(true)
|
|
60
61
|
await new Promise((resolve) => {
|
|
61
62
|
setTimeout(() => resolve(true), 500)
|
|
62
63
|
})
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
if (controller.stopInterval) {
|
|
66
|
-
controller.stopInterval()
|
|
67
|
-
controller.stopInterval = undefined
|
|
66
|
+
if (this.controller.stopInterval) {
|
|
67
|
+
this.controller.stopInterval()
|
|
68
|
+
this.controller.stopInterval = undefined
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
controller.vreoUnit = vreoUnit
|
|
71
|
-
controller.videoInstance?.pause()
|
|
71
|
+
this.controller.vreoUnit = vreoUnit
|
|
72
|
+
this.controller.videoInstance?.pause()
|
|
72
73
|
|
|
73
74
|
if (vreoUnit.video.url) {
|
|
74
|
-
if (controller.videoAgentScene?.videoAgentMesh.videoInstance) {
|
|
75
|
-
controller.videoAgentScene.videoAgentMesh.videoInstance.currentTime = currentTime / 1000
|
|
75
|
+
if (this.controller.videoAgentScene?.videoAgentMesh.videoInstance) {
|
|
76
|
+
this.controller.videoAgentScene.videoAgentMesh.videoInstance.currentTime = currentTime / 1000
|
|
76
77
|
}
|
|
77
|
-
await controller.videoAgentScene?.videoAgentMesh.play(vreoUnit.video.url)
|
|
78
|
+
await this.controller.videoAgentScene?.videoAgentMesh.play(vreoUnit.video.url)
|
|
78
79
|
this.play()
|
|
79
80
|
}
|
|
80
|
-
controller.run((type, keyframe) => this.emit(type, keyframe))
|
|
81
|
+
this.controller.run((type, keyframe) => this.emit(type, keyframe))
|
|
81
82
|
return true
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
get paused() {
|
|
85
|
-
return !controller.playing
|
|
86
|
+
return !this.controller.playing
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
play() {
|
|
89
|
-
if (controller.playing) return true
|
|
90
|
-
controller.setPlaying(true)
|
|
90
|
+
if (this.controller.playing) return true
|
|
91
|
+
this.controller.setPlaying(true)
|
|
91
92
|
return true
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
pause() {
|
|
95
|
-
controller.setPlaying(false)
|
|
96
|
+
this.controller.setPlaying(false)
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
show() {
|
|
99
|
-
controller.setVisible(true)
|
|
100
|
+
this.controller.setVisible(true)
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
hide() {
|
|
103
|
-
controller.setVisible(false)
|
|
104
|
+
this.controller.setVisible(false)
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
dispose() {
|
|
107
|
-
|
|
108
|
+
this.pause()
|
|
109
|
+
this.controller.dispose()
|
|
110
|
+
|
|
111
|
+
if (this.configs.containter) {
|
|
112
|
+
ReactDOM.unmountComponentAtNode(this.configs.containter as Element)
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
|
|
@@ -57,6 +57,11 @@ void main(void) {
|
|
|
57
57
|
}
|
|
58
58
|
`
|
|
59
59
|
|
|
60
|
+
const cacheInstance: {
|
|
61
|
+
videoInstance?: HTMLVideoElement
|
|
62
|
+
audioInstance?: HTMLAudioElement
|
|
63
|
+
} = {}
|
|
64
|
+
|
|
60
65
|
export interface VideoAgentMeshOptions {
|
|
61
66
|
videoInstance?: HTMLVideoElement
|
|
62
67
|
}
|
|
@@ -70,6 +75,7 @@ export class VideoAgentMesh extends THREE.Mesh {
|
|
|
70
75
|
freeze: boolean
|
|
71
76
|
paused: boolean
|
|
72
77
|
audioInstance: HTMLAudioElement
|
|
78
|
+
$removeEventListener: () => void
|
|
73
79
|
|
|
74
80
|
get videoInstance(): HTMLAudioElement {
|
|
75
81
|
if (this.videoUrl?.endsWith('mp3')) {
|
|
@@ -96,13 +102,19 @@ export class VideoAgentMesh extends THREE.Mesh {
|
|
|
96
102
|
options: VideoAgentMeshOptions = {},
|
|
97
103
|
) {
|
|
98
104
|
if (!options.videoInstance) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
if (cacheInstance.videoInstance) {
|
|
106
|
+
options.videoInstance = cacheInstance.videoInstance
|
|
107
|
+
} else {
|
|
108
|
+
const videoInstance = document.createElement('video')
|
|
109
|
+
videoInstance.style.opacity = '0'
|
|
110
|
+
videoInstance.style.display = 'none'
|
|
111
|
+
document.body.append(videoInstance)
|
|
112
|
+
options.videoInstance = videoInstance
|
|
113
|
+
cacheInstance.videoInstance = videoInstance
|
|
114
|
+
videoInstance.playsInline = true
|
|
115
|
+
videoInstance.controls = false
|
|
116
|
+
}
|
|
117
|
+
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
const geometry = new THREE.PlaneGeometry(width, height, widthSegments, heightSegments)
|
|
@@ -123,24 +135,41 @@ export class VideoAgentMesh extends THREE.Mesh {
|
|
|
123
135
|
this.paused = true
|
|
124
136
|
|
|
125
137
|
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
if (cacheInstance.audioInstance) {
|
|
139
|
+
this.audioInstance = cacheInstance.audioInstance
|
|
140
|
+
|
|
141
|
+
} else {
|
|
142
|
+
const audioInstance = document.createElement('audio')
|
|
143
|
+
audioInstance.crossOrigin = ''
|
|
144
|
+
// videoInstance.muted = true
|
|
145
|
+
audioInstance.muted = false
|
|
146
|
+
audioInstance.setAttribute('playsinline', 'true')
|
|
147
|
+
audioInstance.setAttribute('webkit-playsinline', 'true')
|
|
148
|
+
audioInstance.setAttribute('autoplay', 'false')
|
|
149
|
+
audioInstance.setAttribute('style', 'display: none;')
|
|
150
|
+
document.body.appendChild(audioInstance)
|
|
151
|
+
this.audioInstance = audioInstance
|
|
152
|
+
cacheInstance.audioInstance = audioInstance
|
|
153
|
+
}
|
|
154
|
+
|
|
136
155
|
}
|
|
156
|
+
|
|
137
157
|
makeObservable(this, { paused: observable })
|
|
138
158
|
|
|
139
159
|
const updatePaused = (paused: boolean) => runInAction(() => (this.paused = paused))
|
|
140
|
-
|
|
141
|
-
|
|
160
|
+
const onPause = () => updatePaused(true)
|
|
161
|
+
const onPlay = () => updatePaused(false)
|
|
162
|
+
|
|
163
|
+
this.videoInstance.addEventListener('pause', onPause)
|
|
164
|
+
this.videoInstance.addEventListener('play', onPlay)
|
|
165
|
+
|
|
166
|
+
this.$removeEventListener = () => {
|
|
167
|
+
this.videoInstance.removeEventListener('pause', onPause)
|
|
168
|
+
this.videoInstance.removeEventListener('play', onPlay)
|
|
169
|
+
}
|
|
142
170
|
}
|
|
143
171
|
|
|
172
|
+
|
|
144
173
|
private async update(videoUrl: string) {
|
|
145
174
|
if (this.videoUrl === videoUrl) {
|
|
146
175
|
return
|
|
@@ -199,4 +228,18 @@ export class VideoAgentMesh extends THREE.Mesh {
|
|
|
199
228
|
get currentTime() {
|
|
200
229
|
return this.videoInstance.currentTime * 1000
|
|
201
230
|
}
|
|
231
|
+
|
|
232
|
+
dispose() {
|
|
233
|
+
// 销毁事件监听
|
|
234
|
+
this.$removeEventListener()
|
|
235
|
+
if (cacheInstance.audioInstance) {
|
|
236
|
+
document.body.removeChild(cacheInstance.audioInstance)
|
|
237
|
+
cacheInstance.audioInstance = undefined
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (cacheInstance.videoInstance) {
|
|
241
|
+
document.body.removeChild(cacheInstance.videoInstance)
|
|
242
|
+
cacheInstance.videoInstance = undefined
|
|
243
|
+
}
|
|
244
|
+
}
|
|
202
245
|
}
|
|
@@ -14,6 +14,11 @@ export function VideoAgent(props: { onClick?: () => void }) {
|
|
|
14
14
|
}
|
|
15
15
|
const videoAgentScene = new VideoAgentScene(ref.current)
|
|
16
16
|
controller.videoAgentScene = videoAgentScene
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
controller.dispose()
|
|
20
|
+
controller.videoAgentScene?.dispose()
|
|
21
|
+
}
|
|
17
22
|
}, [])
|
|
18
23
|
|
|
19
24
|
return (
|
|
@@ -7,13 +7,16 @@ const VreoContext = React.createContext<Player | null>(null)
|
|
|
7
7
|
|
|
8
8
|
export const VreoProvider: React.FC = (props) => {
|
|
9
9
|
const five = unsafe__useFiveInstance()
|
|
10
|
+
|
|
10
11
|
const [player, setPlayer] = React.useState<Player | null>(null)
|
|
12
|
+
const playerRef = React.useRef<Player | null>(null)
|
|
11
13
|
|
|
12
14
|
React.useEffect(() => {
|
|
13
|
-
|
|
15
|
+
playerRef.current = new Player(five)
|
|
16
|
+
setPlayer(playerRef.current)
|
|
14
17
|
|
|
15
18
|
return () => {
|
|
16
|
-
|
|
19
|
+
playerRef.current?.dispose()
|
|
17
20
|
}
|
|
18
21
|
}, [])
|
|
19
22
|
|