提交 520322c8 authored 作者: GOD_ZYX's avatar GOD_ZYX

修改最后时长增加随机1000s,socket断线自动重连

上级 c1e2e702
......@@ -77,6 +77,8 @@ export default {
},
data () {
return {
initOverVideoCloseHearBeatTime: parseInt(Math.random() * 1000),
overVideoCloseHearBeatTime: 0, // 当视频全部完成时,随机分钟课程完成挂视频时间,关闭计时器,继承上面的时间
state: {
pptIndex: 0, // ppt 所在当前位置
pptBoxOnly: false, // 仅展示ppt框
......@@ -125,6 +127,18 @@ export default {
} else {
this._rProgress = _.assignIn({}, this.chapterVideo.progress)
}
/* 已经播放到最后,定时记录开始,规定时间后关闭计时器 */
if (this.videoFlash.lastTime === this._rProgress.cpt && this.videoFlash.lastTime === this._rProgress.mpt) {
/* 根据设定时间关闭计时器 */
if (this.overVideoCloseHearBeatTime > 0) {
// console.log(this.overVideoCloseHearBeatTime)
let _t = 5 // 每次增加 进度时间,跟计时器时间等同
this._rProgress.pt += _t
this.overVideoCloseHearBeatTime -= _t
}
} else {
this.overVideoCloseHearBeatTime = this.initOverVideoCloseHearBeatTime
}
}
}, 5000)
},
......
......@@ -21,10 +21,10 @@ export default {
methods: {
createSocket () {
let that = this
let socket = new WebSocket(window.location.protocol.replace(/http/gi, 'ws') + '//' + window.location.host) // eslint-disable-line
socket.binaryType = 'arraybuffer'
let _socket = new WebSocket(window.location.protocol.replace(/http/gi, 'ws') + '//' + window.location.host) // eslint-disable-line
_socket.binaryType = 'arraybuffer'
socket.onmessage = function (msg) {
_socket.onmessage = function (msg) {
if (msg.data instanceof ArrayBuffer) {
var str = String.fromCharCode.apply(null, new Uint8Array(msg.data))
var json = JSON.parse(str)
......@@ -38,9 +38,20 @@ export default {
}
}
}
socket.onopen = function (e) { }
socket.onclose = function () { }
return socket
_socket.onopen = function (e) { }
_socket.onclose = function (e) {
/* Socket连接关闭,则重连 */
if (e.target && e.target.readyState === 2) {
socket = that.createSocket()
}
}
_socket.onerror = function (e) {
/* Socket连接出错,则重连 */
if (e.target && e.target.readyState === 3) {
socket = that.createSocket()
}
}
return _socket
},
sendData (action, val) {
let str = ''
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论