water_xcx/packageD/pages/live/live.js

120 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2025-04-15 15:44:51 +08:00
var myRequest = require("../../../utils/api.js");
Page({
/**
* 页面的初始数据
*/
data: {
deviceSerial: '',
accessToken: '',
channelNo: '',
videoHDSrc: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
deviceSerial: options.deviceSerial,
accessToken: options.accessToken,
channelNo: options.channelNo,
})
this.getLiveData();
},
getLiveData() {
var _this = this;
wx.request({
url: 'https://open.ys7.com/api/lapp/v2/live/address/get',
method: 'POST',
data: {
accessToken: this.data.accessToken,
deviceSerial: this.data.deviceSerial,
channelNo: this.data.channelNo,
expireTime: 86400,
quality: 1,
protocol: 3,
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success: (res) => {
console.log(res.data);
if(res.data.code ==200 && res.data.data && res.data.data.url){
var result = res.data;
if(result.code == 200){
_this.setData({
//videoSrc: result.rtmp,
videoHDSrc: result.data.url,
})
}
}else {
console.log("获取高清播放地址失败")
// _this.openPlayUrl();
}
}
})
},
toVideo(e) {
var that = this;
myRequest.myRequest('monitor/getTokenAndSerial', {
deviceCode: e.currentTarget.dataset.code,
},'get').then(function(res){
var data = res.data.data;
console.log(data)
wx.navigateTo({
url: '../video/video?deviceSerial='+data.deviceSerial+'&accessToken='+data.accessToken+'&channelNo=1',
})
}).catch(function(res){
console.log(res);
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})