@x-edu/live-player 0.0.11 → 0.0.13
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/.gem-mine +11 -11
- package/dist/XEduLivePlayer.common.js +987 -480
- package/dist/XEduLivePlayerPre.common.js +1042 -535
- package/package.json +1 -1
- package/public/JsBridge.js +1602 -1602
- package/src/component/AliPlayer/index.jsx +7 -4
- package/src/detail/LiveStatus/index.jsx +186 -186
- package/src/detail/LiveVideo/index.jsx +0 -2
- package/src/detail/RecordVideo/index.jsx +148 -150
- package/src/detail/index.jsx +501 -475
|
@@ -1,150 +1,148 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react'
|
|
2
|
-
import { Video } from 'fish'
|
|
3
|
-
import dayjs from 'dayjs'
|
|
4
|
-
import { PUBLIC_LIVE_STATUS } from '@/config/publicLive'
|
|
5
|
-
import { getUrlType, getType } from '@/util/video'
|
|
6
|
-
import { getRecordLiveStatus } from '@/util/live'
|
|
7
|
-
import LiveStatus from '../LiveStatus'
|
|
8
|
-
import style from './index.module.less'
|
|
9
|
-
|
|
10
|
-
export default function RecordVideo({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const [
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
player.current.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
player.current.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
}
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react'
|
|
2
|
+
import { Video } from 'fish'
|
|
3
|
+
import dayjs from 'dayjs'
|
|
4
|
+
import { PUBLIC_LIVE_STATUS } from '@/config/publicLive'
|
|
5
|
+
import { getUrlType, getType } from '@/util/video'
|
|
6
|
+
import { getRecordLiveStatus } from '@/util/live'
|
|
7
|
+
import LiveStatus from '../LiveStatus'
|
|
8
|
+
import style from './index.module.less'
|
|
9
|
+
|
|
10
|
+
export default function RecordVideo({
|
|
11
|
+
userInfo,
|
|
12
|
+
liveInfo,
|
|
13
|
+
visitTime,
|
|
14
|
+
diffTime,
|
|
15
|
+
onStatusChange,
|
|
16
|
+
onPlayReplay,
|
|
17
|
+
onVideoPlay = () => undefined,
|
|
18
|
+
onRequestFullScreen = () => undefined
|
|
19
|
+
}) {
|
|
20
|
+
const isFullScreenRef = useRef(false)
|
|
21
|
+
const [isLiveLoading, setIsLiveLoading] = useState(false)
|
|
22
|
+
const [isLiveLoadError, setIsLiveLoadError] = useState(false)
|
|
23
|
+
const hasPlayed = useRef(false)
|
|
24
|
+
const player = useRef()
|
|
25
|
+
const endTimer = useRef()
|
|
26
|
+
const needLogin = !userInfo && liveInfo.login
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const isLiving = liveInfo.status === PUBLIC_LIVE_STATUS.LIVEING
|
|
30
|
+
if (isLiving && needLogin) {
|
|
31
|
+
const timeToEnd = dayjs(liveInfo.end_time).valueOf() - (Date.now() - diffTime)
|
|
32
|
+
if (timeToEnd > 0) {
|
|
33
|
+
endTimer.current = setTimeout(() => {
|
|
34
|
+
onStatusChange(PUBLIC_LIVE_STATUS.COMPLETEED)
|
|
35
|
+
}, timeToEnd)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (player.current) {
|
|
40
|
+
player.current.controls(isLiving && !needLogin)
|
|
41
|
+
|
|
42
|
+
// 显示成封面
|
|
43
|
+
if (liveInfo.status === PUBLIC_LIVE_STATUS.COMPLETEED || liveInfo.status === PUBLIC_LIVE_STATUS.OFFLINE) {
|
|
44
|
+
player.current.autoplay(false)
|
|
45
|
+
player.current.load()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
clearTimeout(endTimer.current)
|
|
51
|
+
}
|
|
52
|
+
}, [liveInfo.status, userInfo])
|
|
53
|
+
|
|
54
|
+
const handleVideoReady = (v, playerIns) => {
|
|
55
|
+
player.current = playerIns
|
|
56
|
+
|
|
57
|
+
playerIns.on('fullscreenchange', () => {
|
|
58
|
+
const isFullScreenNow = playerIns.isFullscreen()
|
|
59
|
+
if (isFullScreenNow) {
|
|
60
|
+
if (!isFullScreenRef.current) {
|
|
61
|
+
onRequestFullScreen()
|
|
62
|
+
}
|
|
63
|
+
isFullScreenRef.current = true
|
|
64
|
+
} else {
|
|
65
|
+
isFullScreenRef.current = false
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
playerIns.on('waiting', () => {
|
|
69
|
+
setIsLiveLoading(true)
|
|
70
|
+
})
|
|
71
|
+
playerIns.on('playing', () => {
|
|
72
|
+
setIsLiveLoading(false)
|
|
73
|
+
})
|
|
74
|
+
playerIns.on('ended', () => {
|
|
75
|
+
onStatusChange(PUBLIC_LIVE_STATUS.COMPLETEED)
|
|
76
|
+
})
|
|
77
|
+
playerIns.on('play', () => {
|
|
78
|
+
const currentTime = Date.now() - diffTime
|
|
79
|
+
const status = getRecordLiveStatus(liveInfo.status, currentTime, liveInfo.begin_time, liveInfo.end_time)
|
|
80
|
+
onStatusChange(status)
|
|
81
|
+
if (status === PUBLIC_LIVE_STATUS.LIVEING) {
|
|
82
|
+
player.current.currentTime(Math.max(0, (currentTime - dayjs(liveInfo.begin_time).valueOf()) / 1000))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!hasPlayed.current) {
|
|
86
|
+
onVideoPlay()
|
|
87
|
+
}
|
|
88
|
+
hasPlayed.current = true
|
|
89
|
+
|
|
90
|
+
player.current.autoplay(false)
|
|
91
|
+
setIsLiveLoadError(false)
|
|
92
|
+
})
|
|
93
|
+
playerIns.on('error', () => {
|
|
94
|
+
setIsLiveLoadError(true)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const isLiving = liveInfo.status === PUBLIC_LIVE_STATUS.LIVEING
|
|
98
|
+
player.current.controls(isLiving && !needLogin)
|
|
99
|
+
if (isLiving) {
|
|
100
|
+
const currentTime = Math.max(0, (visitTime - dayjs(liveInfo.begin_time).valueOf()) / 1000)
|
|
101
|
+
player.current.currentTime(currentTime)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const handleVideoReload = () => {
|
|
106
|
+
if (player.current) {
|
|
107
|
+
player.current.autoplay(true)
|
|
108
|
+
player.current.load()
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handleStatusChange = (status, params = {}) => {
|
|
113
|
+
onStatusChange(status)
|
|
114
|
+
if (status === PUBLIC_LIVE_STATUS.LIVEING && params.play) {
|
|
115
|
+
player.current.play()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const options = {
|
|
120
|
+
sources: [{
|
|
121
|
+
src: liveInfo.video_url,
|
|
122
|
+
type: getType(getUrlType(liveInfo.video_url))
|
|
123
|
+
}],
|
|
124
|
+
poster: liveInfo.cover_pic_web_url,
|
|
125
|
+
autoplay: false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div className={style['record-video']}>
|
|
130
|
+
<Video
|
|
131
|
+
className="vjs-big-play-centered"
|
|
132
|
+
options={options}
|
|
133
|
+
onReady={handleVideoReady}
|
|
134
|
+
/>
|
|
135
|
+
<LiveStatus
|
|
136
|
+
userInfo={userInfo}
|
|
137
|
+
visitTime={visitTime}
|
|
138
|
+
diffTime={diffTime}
|
|
139
|
+
liveInfo={liveInfo}
|
|
140
|
+
isLiveLoading={isLiveLoading}
|
|
141
|
+
isLiveLoadError={isLiveLoadError}
|
|
142
|
+
onStatusChange={handleStatusChange}
|
|
143
|
+
onPlayReplay={onPlayReplay}
|
|
144
|
+
onReloadLive={handleVideoReload}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
)
|
|
148
|
+
}
|