LiveBox.js
4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// pages/crowdfunding/components/LiveBox/LiveBox.js
const IMAGES = Object.freeze({
COVER_LIVE: 'https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_LIVE.gif',
COVER_REPLAY: 'https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_REPLAY.gif',
REPLAY_ICON: 'https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/replayIcon.png',
FULL_SCREEN: 'https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/fullscreen.png',
GROUP: "https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/gift.gif"
})
import environment from '~/utils/request/environment'
var that
Component({
/**
* 组件的属性列表
*/
properties: {
navHeight: {
type: String,
value: 0
},
detail: {
type: Object,
value: () => {}
},
liveDetail: {
type: Object,
value: () => {
return {
// 直播状态 0:未开始;1:直播中;2:已结束;
status: 0,
// 直播播放地址(status=1生效)
playPath: '',
// 回放列表
liveBroadcastRecordingFileList: []
}
},
observer: function (n) {
that = this
if (n?.status) {
this.init()
}
}
},
mediaLiveObject: {
type: Object,
observer(n) {
if (n.liveBroadcastMediaUrl) {
this.setData({
mediaLive: true,
isAction: true,
['liveDetail.status']: n.liveBroadcastStateFlag
})
}
}
},
haveIM: {
type: Boolean,
value: true
}
},
/**
* 组件的初始数据
*/
data: {
x: 280,
y: 180,
// 小容器直播条
isSmallBox: false,
// 全屏
videoFullscreen: false,
showKf: false,
// 按钮
isAction: false,
videoContext: {},
playConf: {
autoplay: true, // 自动播放
muted: true, // 是否静音
mode: 'RTC'
},
playUrl: '',
IMAGES: IMAGES,
reloadLive: false,
LiveProps: Object.freeze({
0: {
isShowBox: false
},
1: {
status: '直播',
text: '正在直播',
isLive: true,
covergif: IMAGES.COVER_LIVE,
isShowBox: true,
gifAttr: 'liveBroadcastRoomCover'
},
2: {
status: '回放',
text: '直播回放',
isLive: false,
covergif: IMAGES.COVER_REPLAY,
isShowBox: true,
icon: IMAGES.REPLAY_ICON,
gifAttr: 'liveBroadcastRoomEndCover'
}
})
},
/**
* 组件的方法列表
*/
methods: {
createContext: function () {
const isLive = this.data.LiveProps[this.data.liveDetail.status].isLive
const ctx = isLive ? 'live-player' : ''
this.setData({
videoContext: wx.createLivePlayerContext(ctx)
})
},
init() {
const liveDetail = this.data.liveDetail
const fileList = liveDetail.liveBroadcastRecordingFileList ? liveDetail.liveBroadcastRecordingFileList.map(item => item.videoUrl) : []
this.setData({
playUrl: this.data.LiveProps[liveDetail.status].isLive ? liveDetail.pullRtmpUrl : (liveDetail.liveBroadcastRecordingFileList || [])[0]?.videoUrl,
liveBroadcastRecordingFileList: fileList,
isAction: this.data.detail.activityStatus != 3 && this.data.detail.buyFlag != 2
})
this.createContext()
},
handleSetData(e) {
const {
attr,
val
} = e.currentTarget.dataset
this.setData({
[attr]: val
})
},
handleKf() {
this.setData({
showKf: !this.data.showKf
})
},
// h5授权登陆
h5Login() {
wx.$router.getPageInstance().jumpAuthUserInfo('imFlag')
},
handleFullscreen(e) {
const {
val
} = e.currentTarget.dataset
this.setData({
videoFullscreen: val,
['playConf.muted']: !val
})
this.triggerEvent('handleLiveFull', {
isFull: val
})
},
changeView: wx.$util.debounce(e => {
let {
source,
x,
y
} = e.detail
if (source != 'touch') return
that.setData({
x: Math.abs(x),
y: Math.abs(y)
})
}, 100),
onHide() {
if (this.data.liveDetail.status == 1) {
this.selectComponent('#im')?.destroyIm()
}
},
onShow() {
if (this.data.liveDetail.status == 1) {
this.selectComponent('#im')?.imOnShow()
}
},
liveError(e) {
let {
detail: {
errCode
}
} = e
console.log(errCode)
// 10001:未开麦克风和相机
if (errCode == 10001) {
this.setData({
['playConf.mode']: 'live',
reloadLive: true
})
setTimeout(() => {
this.setData({
reloadLive: false
}, 100)
})
}
}
}
})