|
@@ -1,5 +1,3 @@
|
|
|
-//index.js
|
|
|
-//获取应用实例
|
|
|
const app = require('../../utils/util.js');
|
|
|
const tools = require('../../utils/tools.js');
|
|
|
Page({
|
|
@@ -24,22 +22,6 @@ Page({
|
|
|
_timeout: 5000,
|
|
|
isCloseStatus: false
|
|
|
},
|
|
|
- // startBf: function () {
|
|
|
- // //pullUrl: `rtmp://hnb.spaceships.cn/education/live56?auth_key=1593654178-0-0-30f7fa190656ddb994151d23cf30d3b7`
|
|
|
- // var _this = this;
|
|
|
- // _this.setData({
|
|
|
- // pushUrl: _this.data.pushUrl,
|
|
|
- // // isPush: false
|
|
|
- // })
|
|
|
- // _this.data.videoContext.start();
|
|
|
- // },
|
|
|
- // stopBf: function () {
|
|
|
- // this.setData({
|
|
|
- // pushUrl: ``,
|
|
|
- // // isPush: true
|
|
|
- // })
|
|
|
- // this.data.videoContext.stop()
|
|
|
- // },
|
|
|
statechange: function (e) {
|
|
|
console.log(e)
|
|
|
},
|
|
@@ -59,18 +41,14 @@ Page({
|
|
|
this.sendSocketMessage("put up hands")
|
|
|
},
|
|
|
submit: function () {
|
|
|
- let _this = this;
|
|
|
- let input_val = _this.data.inputValue;
|
|
|
- _this.sendSocketMessage(input_val)
|
|
|
+ let input_val = this.data.inputValue;
|
|
|
+ this.sendSocketMessage(input_val)
|
|
|
this.setData({
|
|
|
inputValue: ''
|
|
|
})
|
|
|
},
|
|
|
- fullScreen: function () {
|
|
|
- var that = this;
|
|
|
- //全屏
|
|
|
- // var vidoHeight = wx.getSystemInfoSync().windowHeight;
|
|
|
- var fullScreenFlag = that.data.fullScreenFlag;
|
|
|
+ fullScreen: function() {
|
|
|
+ var fullScreenFlag = this.data.fullScreenFlag;
|
|
|
if (fullScreenFlag) {
|
|
|
fullScreenFlag = false;
|
|
|
} else {
|
|
@@ -78,52 +56,51 @@ Page({
|
|
|
}
|
|
|
if (fullScreenFlag) {
|
|
|
//全屏
|
|
|
- that.data.livectx.requestFullScreen({
|
|
|
- success: res => {
|
|
|
- that.setData({
|
|
|
+ this.data.livectx.requestFullScreen({
|
|
|
+ success: () => {
|
|
|
+ this.setData({
|
|
|
fullScreenFlag: fullScreenFlag,
|
|
|
spfx: "horizontal",
|
|
|
spfx1: "horizontal"
|
|
|
});
|
|
|
- if (that.data.isHands == true) {
|
|
|
- that.setData({
|
|
|
+ if (this.data.isHands == true) {
|
|
|
+ this.setData({
|
|
|
isHands: false
|
|
|
})
|
|
|
- that.setData({
|
|
|
+ this.setData({
|
|
|
isHands: true
|
|
|
})
|
|
|
}
|
|
|
console.log('我要全屏执行了');
|
|
|
},
|
|
|
- fail: res => {
|
|
|
+ fail: () => {
|
|
|
console.log('我要全屏执行失败了');
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
//缩小
|
|
|
- that.data.livectx.exitFullScreen({
|
|
|
- success: res => {
|
|
|
+ this.data.livectx.exitFullScreen({
|
|
|
+ success: () => {
|
|
|
console.log('fullscreen success');
|
|
|
- that.setData({
|
|
|
+ this.setData({
|
|
|
fullScreenFlag: fullScreenFlag,
|
|
|
spfx: "vertical",
|
|
|
spfx1: "vertical"
|
|
|
});
|
|
|
},
|
|
|
- fail: res => {
|
|
|
+ fail: () => {
|
|
|
console.log('exit fullscreen success');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
getZbArr(sessionKey) {
|
|
|
- var _this = this;
|
|
|
wx.request({
|
|
|
url: app.globalData.publicUrl + '/wx/course/selectLiveByCourseId',
|
|
|
method: "post",
|
|
|
data: {
|
|
|
sessionKey: sessionKey,
|
|
|
- courseId: _this.data.id
|
|
|
+ courseId: this.data.id
|
|
|
},
|
|
|
success: (e) => {
|
|
|
console.log(e, "11111111111111111")
|
|
@@ -137,23 +114,19 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
socketConnect(sessionKey) {
|
|
|
- var _this = this;
|
|
|
var newSessionkey = encodeURIComponent(sessionKey);
|
|
|
wx.connectSocket({
|
|
|
- url: app.globalData.publicSocketUrl + '/live/socket?sessionkey=' + newSessionkey + "&courseId=" + _this.data.id
|
|
|
+ url: app.globalData.publicSocketUrl + '/live/socket?sessionkey=' + newSessionkey + "&courseId=" + this.data.id
|
|
|
})
|
|
|
- wx.onSocketOpen(function () {
|
|
|
+ wx.onSocketOpen(() => {
|
|
|
console.log("我连上啦")
|
|
|
- _this.setData({
|
|
|
+ this.setData({
|
|
|
socketOpen: true
|
|
|
})
|
|
|
- // _this.data.timeoutObj = setInterval(() => {
|
|
|
- // _this.startHeart(sessionKey)
|
|
|
- // }, _this.data._timeout)
|
|
|
- _this.setData({
|
|
|
- timeoutObj: setInterval(function () {
|
|
|
- _this.startHeart(sessionKey)
|
|
|
- }, _this.data._timeout)
|
|
|
+ this.setData({
|
|
|
+ timeoutObj: setInterval( ()=> {
|
|
|
+ this.startHeart(sessionKey)
|
|
|
+ }, this.data._timeout)
|
|
|
})
|
|
|
})
|
|
|
wx.onSocketError(function () {
|
|
@@ -162,27 +135,26 @@ Page({
|
|
|
wx.onSocketClose(function () {
|
|
|
console.log("我关了")
|
|
|
})
|
|
|
- wx.onSocketMessage(function (data) {
|
|
|
+ wx.onSocketMessage((data) => {
|
|
|
console.log(data, "2222222222222")
|
|
|
let res = JSON.parse(data.data);
|
|
|
- console.log(res)
|
|
|
if (res.msg == "HeartBeat") {
|
|
|
return false;
|
|
|
}
|
|
|
if (res.messageType == "message" || res.messageType == "system") {
|
|
|
- _this.setData({
|
|
|
- chatContent: _this.data.chatContent.concat(res),
|
|
|
+ this.setData({
|
|
|
+ chatContent: this.data.chatContent.concat(res),
|
|
|
bottom: 'scrollBottom'
|
|
|
})
|
|
|
}
|
|
|
if (res.msg == "socketLiveEnd") {
|
|
|
- _this.setData({
|
|
|
+ this.setData({
|
|
|
url: "",
|
|
|
})
|
|
|
- if (_this.data.socketOpen) {
|
|
|
+ if (this.data.socketOpen) {
|
|
|
wx.closeSocket()
|
|
|
}
|
|
|
- _this.data.videoContext.stop()
|
|
|
+ this.data.videoContext.stop()
|
|
|
wx.showModal({
|
|
|
showCancel: false,
|
|
|
content: "直播结束了",
|
|
@@ -197,26 +169,24 @@ Page({
|
|
|
}
|
|
|
if (res.messageType == "studentPushStream") {
|
|
|
console.log(res, "我收到了举手的推流")
|
|
|
- _this.data.videoContext.start();
|
|
|
- _this.setData({
|
|
|
+ this.data.videoContext.start();
|
|
|
+ this.setData({
|
|
|
isHands: true,
|
|
|
pushUrl: res.pushUrl
|
|
|
})
|
|
|
}
|
|
|
if (res.messageType == "stopStudentPushStream") {
|
|
|
console.log(res.pushUrl, "不推了")
|
|
|
- _this.data.videoContext.stop()
|
|
|
- _this.setData({
|
|
|
+ this.data.videoContext.stop()
|
|
|
+ this.setData({
|
|
|
isHands: false,
|
|
|
pushUrl: ""
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// 发送消息
|
|
|
sendSocketMessage(msg) {
|
|
|
- // console.log(this.data.socketOpen)
|
|
|
if (this.data.socketOpen) {
|
|
|
wx.sendSocketMessage({
|
|
|
data: msg
|
|
@@ -225,81 +195,26 @@ Page({
|
|
|
},
|
|
|
// 心跳
|
|
|
startHeart(sessionKey) {
|
|
|
- let _this = this;
|
|
|
wx.sendSocketMessage({
|
|
|
data: "HeartBeat",
|
|
|
- success(res) {
|
|
|
+ success: (res) => {
|
|
|
console.log(res, "发送心跳成功")
|
|
|
},
|
|
|
- fail(err) {
|
|
|
+ fail: (err) => {
|
|
|
console.log(err, "发送心跳失败")
|
|
|
- if (_this.data.isCloseStatus == false) {
|
|
|
+ if (this.data.isCloseStatus == false) {
|
|
|
wx.closeSocket();
|
|
|
- clearInterval(_this.data.timeoutObj);
|
|
|
- _this.socketConnect(sessionKey);
|
|
|
+ clearInterval(this.data.timeoutObj);
|
|
|
+ this.socketConnect(sessionKey);
|
|
|
} else {
|
|
|
- clearInterval(_this.data.timeoutObj);
|
|
|
+ clearInterval(this.data.timeoutObj);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- // clearDs() {
|
|
|
- // clearInterval(this.data.timeoutObj);
|
|
|
- // },
|
|
|
async onShow() {
|
|
|
const sessionKey = await tools.checkSessionAndLogin();
|
|
|
this.socketConnect(sessionKey);
|
|
|
- // let _this = this;
|
|
|
- // wx.checkSession({
|
|
|
- // success: () => {
|
|
|
- // console.log("我有缓存")
|
|
|
- // var sessionKey = wx.getStorageSync('sessionKey');
|
|
|
- // console.log(sessionKey)
|
|
|
- // if (sessionKey == "") {
|
|
|
- // wx.login({
|
|
|
- // success(res) {
|
|
|
- // console.log(res);
|
|
|
- // var code = res.code
|
|
|
- // wx.request({
|
|
|
- // url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
- // method: "get",
|
|
|
- // data: {
|
|
|
- // code
|
|
|
- // },
|
|
|
- // success: function (res) {
|
|
|
- // sessionKey = res.data.sessionKey;
|
|
|
- // wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
- // } else {
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // },
|
|
|
- // fail() {
|
|
|
- // console.log("我没有缓存并去登录请求")
|
|
|
- // wx.login({
|
|
|
- // success(res) {
|
|
|
- // console.log(res);
|
|
|
- // var code = res.code
|
|
|
- // wx.request({
|
|
|
- // url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
- // method: "get",
|
|
|
- // data: {
|
|
|
- // code
|
|
|
- // },
|
|
|
- // success: function (res) {
|
|
|
- // wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
- // var sessionKey = res.data.sessionKey;
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
},
|
|
|
onHide() {
|
|
|
this.setData({
|
|
@@ -321,8 +236,7 @@ Page({
|
|
|
clearInterval(this.data.timeoutObj);
|
|
|
this.data.videoContext.stop()
|
|
|
},
|
|
|
- async onLoad (options) {
|
|
|
- // var _this = this;
|
|
|
+ async onLoad(options) {
|
|
|
this.setData({
|
|
|
id: options.id,
|
|
|
videoContext: wx.createLivePusherContext("video-livePusher"),
|
|
@@ -330,63 +244,6 @@ Page({
|
|
|
})
|
|
|
const sessionKey = await tools.checkSessionAndLogin();
|
|
|
this.getZbArr(sessionKey);
|
|
|
- // this.socketConnect(sessionKey);
|
|
|
- // wx.checkSession({
|
|
|
- // success: () => {
|
|
|
- // console.log("我有缓存")
|
|
|
- // var sessionKey = wx.getStorageSync('sessionKey');
|
|
|
- // console.log(sessionKey)
|
|
|
- // if (sessionKey == "") {
|
|
|
- // wx.login({
|
|
|
- // success(res) {
|
|
|
- // console.log(res);
|
|
|
- // var code = res.code
|
|
|
- // wx.request({
|
|
|
- // url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
- // method: "get",
|
|
|
- // data: {
|
|
|
- // code
|
|
|
- // },
|
|
|
- // success: function (res) {
|
|
|
- // sessionKey = res.data.sessionKey;
|
|
|
- // wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
- // _this.getZbArr(sessionKey);
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
- // } else {
|
|
|
- // _this.getZbArr(sessionKey);
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // },
|
|
|
- // fail() {
|
|
|
- // console.log("我没有缓存并去登录请求")
|
|
|
- // wx.login({
|
|
|
- // success(res) {
|
|
|
- // console.log(res);
|
|
|
- // var code = res.code
|
|
|
- // wx.request({
|
|
|
- // url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
- // method: "get",
|
|
|
- // data: {
|
|
|
- // code
|
|
|
- // },
|
|
|
- // success: function (res) {
|
|
|
- // wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
- // var sessionKey = res.data.sessionKey;
|
|
|
- // _this.getZbArr(sessionKey);
|
|
|
- // _this.socketConnect(sessionKey);
|
|
|
- // // _this.socketConnect(sessionKey);
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
}
|
|
|
|
|
|
})
|