|
@@ -18,7 +18,10 @@ Page({
|
|
|
livectx: "",
|
|
|
spfx: "vertical",
|
|
|
spfx1: "vertical",
|
|
|
- isHands: false
|
|
|
+ isHands: false,
|
|
|
+ timeoutObj: null,
|
|
|
+ _timeout: 5000,
|
|
|
+ isCloseStatus: false
|
|
|
},
|
|
|
// startBf: function () {
|
|
|
// //pullUrl: `rtmp://hnb.spaceships.cn/education/live56?auth_key=1593654178-0-0-30f7fa190656ddb994151d23cf30d3b7`
|
|
@@ -61,7 +64,6 @@ Page({
|
|
|
inputValue: ''
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
fullScreen: function () {
|
|
|
var that = this;
|
|
|
//全屏
|
|
@@ -81,6 +83,14 @@ Page({
|
|
|
spfx: "horizontal",
|
|
|
spfx1: "horizontal"
|
|
|
});
|
|
|
+ if (that.data.isHands == true) {
|
|
|
+ that.setData({
|
|
|
+ isHands: false
|
|
|
+ })
|
|
|
+ that.setData({
|
|
|
+ isHands: true
|
|
|
+ })
|
|
|
+ }
|
|
|
console.log('我要全屏执行了');
|
|
|
},
|
|
|
fail: res => {
|
|
@@ -129,17 +139,20 @@ Page({
|
|
|
var newSessionkey = encodeURIComponent(sessionKey);
|
|
|
wx.connectSocket({
|
|
|
url: app.globalData.publicSocketUrl + '/live/socket?sessionkey=' + newSessionkey + "&courseId=" + _this.data.id
|
|
|
- // header:{
|
|
|
- // 'content-type': 'application/json'
|
|
|
- // },
|
|
|
- // protocols: ['protocol1']
|
|
|
})
|
|
|
wx.onSocketOpen(function () {
|
|
|
console.log("我连上啦")
|
|
|
_this.setData({
|
|
|
socketOpen: true
|
|
|
})
|
|
|
- // _this.sendSocketMessage(hsdushh);
|
|
|
+ // _this.data.timeoutObj = setInterval(() => {
|
|
|
+ // _this.startHeart(sessionKey)
|
|
|
+ // }, _this.data._timeout)
|
|
|
+ _this.setData({
|
|
|
+ timeoutObj: setInterval(function () {
|
|
|
+ _this.startHeart(sessionKey)
|
|
|
+ }, _this.data._timeout)
|
|
|
+ })
|
|
|
})
|
|
|
wx.onSocketError(function () {
|
|
|
console.log("我连接出错了")
|
|
@@ -150,6 +163,10 @@ Page({
|
|
|
wx.onSocketMessage(function (data) {
|
|
|
let res = JSON.parse(data.data);
|
|
|
console.log(res)
|
|
|
+ if (res.msg == "HeartBeat") {
|
|
|
+ // clearInterval(_this.data.timeoutObj);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (res.messageType == "message" || res.messageType == "system") {
|
|
|
_this.setData({
|
|
|
chatContent: _this.data.chatContent.concat(res),
|
|
@@ -188,6 +205,7 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 发送消息
|
|
|
sendSocketMessage(msg) {
|
|
|
if (this.data.socketOpen) {
|
|
|
wx.sendSocketMessage({
|
|
@@ -195,6 +213,29 @@ Page({
|
|
|
})
|
|
|
} else {}
|
|
|
},
|
|
|
+ // 心跳
|
|
|
+ startHeart(sessionKey) {
|
|
|
+ let _this = this;
|
|
|
+ wx.sendSocketMessage({
|
|
|
+ data: "HeartBeat",
|
|
|
+ success(res) {
|
|
|
+ console.log(res, "发送心跳成功")
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err, "发送心跳失败")
|
|
|
+ if (_this.data.isCloseStatus == false) {
|
|
|
+ wx.closeSocket();
|
|
|
+ clearInterval(_this.data.timeoutObj);
|
|
|
+ _this.socketConnect(sessionKey);
|
|
|
+ } else {
|
|
|
+ clearInterval(_this.data.timeoutObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // clearDs() {
|
|
|
+ // clearInterval(this.data.timeoutObj);
|
|
|
+ // },
|
|
|
onShow() {
|
|
|
let _this = this;
|
|
|
wx.checkSession({
|
|
@@ -208,7 +249,7 @@ Page({
|
|
|
console.log(res);
|
|
|
var code = res.code
|
|
|
wx.request({
|
|
|
- url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
+ url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
method: "get",
|
|
|
data: {
|
|
|
code
|
|
@@ -232,7 +273,7 @@ Page({
|
|
|
console.log(res);
|
|
|
var code = res.code
|
|
|
wx.request({
|
|
|
- url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
+ url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
method: "get",
|
|
|
data: {
|
|
|
code
|
|
@@ -249,18 +290,23 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
onHide() {
|
|
|
+ this.setData({
|
|
|
+ isCloseStatus: true
|
|
|
+ })
|
|
|
if (this.data.socketOpen) {
|
|
|
wx.closeSocket()
|
|
|
}
|
|
|
+ clearInterval(this.data.timeoutObj);
|
|
|
},
|
|
|
onUnload() {
|
|
|
+ this.setData({
|
|
|
+ isCloseStatus: true
|
|
|
+ })
|
|
|
if (this.data.socketOpen) {
|
|
|
wx.closeSocket()
|
|
|
}
|
|
|
+ clearInterval(this.data.timeoutObj);
|
|
|
},
|
|
|
- // onReady() {
|
|
|
-
|
|
|
- // },
|
|
|
onLoad: function (options) {
|
|
|
var _this = this;
|
|
|
_this.setData({
|
|
@@ -279,7 +325,7 @@ Page({
|
|
|
console.log(res);
|
|
|
var code = res.code
|
|
|
wx.request({
|
|
|
- url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
+ url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
method: "get",
|
|
|
data: {
|
|
|
code
|
|
@@ -306,7 +352,7 @@ Page({
|
|
|
console.log(res);
|
|
|
var code = res.code
|
|
|
wx.request({
|
|
|
- url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
+ url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
method: "get",
|
|
|
data: {
|
|
|
code
|