Commit ac6d0920 by zhanghaozhe

视频安全问题

parent 783627e3
...@@ -23052,6 +23052,11 @@ ...@@ -23052,6 +23052,11 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
}, },
"vconsole": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/vconsole/-/vconsole-3.3.4.tgz",
"integrity": "sha512-9yihsic96NPoMLQx/lCQwH9d89H0bbMW3LZPzo/t4yGQcS1X+vTCe9OHm1XSH7WNxzGDmcSwBiKLsFGwvJpQBg=="
},
"vendors": { "vendors": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/vendors/-/vendors-1.0.4.tgz", "resolved": "https://registry.npmjs.org/vendors/-/vendors-1.0.4.tgz",
......
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
"ts-pnp": "1.1.6", "ts-pnp": "1.1.6",
"typescript": "^3.7.5", "typescript": "^3.7.5",
"url-loader": "2.3.0", "url-loader": "2.3.0",
"vconsole": "^3.3.4",
"video.js": "^7.8.4", "video.js": "^7.8.4",
"web-launch-app": "^2.2.4", "web-launch-app": "^2.2.4",
"webpack": "4.42.0", "webpack": "4.42.0",
......
...@@ -16,6 +16,7 @@ import jsCookie from 'js-cookie' ...@@ -16,6 +16,7 @@ import jsCookie from 'js-cookie'
import Single from "src/components/detail/single"; import Single from "src/components/detail/single";
import SingleSuccess from "../detail/single/singleSuccess"; import SingleSuccess from "../detail/single/singleSuccess";
import './CustomPlayButton' import './CustomPlayButton'
import VConsole from 'vconsole'
let alert = Modal.alert let alert = Modal.alert
...@@ -111,6 +112,7 @@ class Video extends Component { ...@@ -111,6 +112,7 @@ class Video extends Component {
componentDidMount() { componentDidMount() {
new VConsole()
if (window.location.protocol === 'https:') { if (window.location.protocol === 'https:') {
window.location.replace('http' + window.location.href.slice(5)) window.location.replace('http' + window.location.href.slice(5))
return return
...@@ -358,11 +360,9 @@ class Video extends Component { ...@@ -358,11 +360,9 @@ class Video extends Component {
}) })
this.ws.addEventListener('message', e => { this.ws.addEventListener('message', e => {
const data = JSON.parse(e.data); const data = JSON.parse(e.data);
data.code == 4040 && (this.reconnect = false); data.code === 4040 && (this.reconnect = false);
if (data.code === 0) { if (data.code === 0 && data.data && data.data.position) {
if (data.data && data.data.position) { this.player.currentTime(data.data.position);
this.player.currentTime(data.data.position);
}
} }
}) })
} }
...@@ -486,10 +486,14 @@ class Video extends Component { ...@@ -486,10 +486,14 @@ class Video extends Component {
}) })
this.player.addChild('CustomPlayButtonCover') this.player.addChild('CustomPlayButtonCover')
this.player.on('play', () => { this.player.on('play', () => {
console.log('play')
let videoTime = window.sessionStorage.getItem('videoTimeBeforeReload') let videoTime = window.sessionStorage.getItem('videoTimeBeforeReload')
if (videoTime) { if (videoTime) {
this.player.currentTime(videoTime) setTimeout(() => {
window.sessionStorage.removeItem('videoTimeBeforeReload') // window.alert(videoTime)
this.player.currentTime(Number(videoTime))
}, 2000)
// window.sessionStorage.removeItem('videoTimeBeforeReload')
} }
const {videoList, activeIndex, vCourseId, course = {}} = this.state const {videoList, activeIndex, vCourseId, course = {}} = this.state
...@@ -513,6 +517,11 @@ class Video extends Component { ...@@ -513,6 +517,11 @@ class Video extends Component {
this.setupTimer(); this.setupTimer();
} }
}) })
this.player.on('ready', () => {
console.log('ready')
})
this.player.on('ratechange', () => { this.player.on('ratechange', () => {
this.currentPlaybackRate = this.player.playbackRate() this.currentPlaybackRate = this.player.playbackRate()
this.sendWatchTime(this.watchSec, this.previousPlaybackRate) this.sendWatchTime(this.watchSec, this.previousPlaybackRate)
...@@ -535,15 +544,11 @@ class Video extends Component { ...@@ -535,15 +544,11 @@ class Video extends Component {
}) })
} }
}) })
this.player.on('error', () => {
this.handleVideoAuthError(0)
})
this.player.on('waiting', () => { this.player.on('waiting', () => {
clearTimeout(this.currentVideoTimer) this.handleVideoAuthError(3000)
this.currentVideoTimer = setTimeout(() => {
if (this.currentVideoExpireTime < new Date().getTime()) {
window.sessionStorage.setItem('videoTimeBeforeReload', this.player.currentTime())
this.getVideoSrc()
}
}, 3000)
}) })
} }
...@@ -567,6 +572,17 @@ class Video extends Component { ...@@ -567,6 +572,17 @@ class Video extends Component {
this.recordSocket = null this.recordSocket = null
} }
//处理视频播放权限问题
handleVideoAuthError = (interval) => {
clearTimeout(this.currentVideoTimer)
this.currentVideoTimer = setTimeout(() => {
if (this.currentVideoExpireTime < new Date().getTime()) {
window.sessionStorage.setItem('videoTimeBeforeReload', this.player.currentTime())
this.getVideoSrc()
}
}, interval)
}
//请求签名视频地址 //请求签名视频地址
getVideoSrc = () => { getVideoSrc = () => {
const {videoList, activeIndex} = this.state const {videoList, activeIndex} = this.state
...@@ -702,10 +718,8 @@ class Video extends Component { ...@@ -702,10 +718,8 @@ class Video extends Component {
this.player.ready(() => { this.player.ready(() => {
this.player.play() this.player.play()
}) })
} }
getDatumCatalog() { getDatumCatalog() {
http.get(`${API.home}/m/course/data/${this.courseID}`) http.get(`${API.home}/m/course/data/${this.courseID}`)
.then(res => { .then(res => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment