DetailPlayLivePage.ets
11.2 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import { ContentDetailDTO, LiveRoomDataBean, LiveRoomItemBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import { TabComponent } from '../widgets/details/TabComponent';
import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
import { DisplayDirection } from 'wdConstant/Index';
import mediaquery from '@ohos.mediaquery';
import { CustomToast, Logger, WindowModel } from 'wdKit/Index';
import { display, router, window } from '@kit.ArkUI';
import { WDAliPlayerController } from 'wdPlayer/Index';
import { LiveOperRowListView } from 'wdComponent';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';
import { TrackConstants, TrackingContent, TrackParamConvert } from 'wdTracking/Index';
import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg';
import { LiveDetailChatRoomController } from '../im/LiveDetailChatRoomController';
import { LiveMessageOptType, LiveMessageRoomType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic';
let TAG: string = 'DetailPlayLivePage';
/**
* 非沉浸式房间直播组件
*/
@Component
export struct DetailPlayLivePage {
//横竖屏,默认竖屏
@Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL
playerController: WDAliPlayerController = new WDAliPlayerController();
liveViewModel: LiveViewModel = new LiveViewModel()
@State relId: string = ''
@State contentId: string = ''
@State relType: string = ''
@Provide liveRoomDataBean: LiveRoomDataBean = {} as LiveRoomDataBean
@State tabs: string[] = []
@State changeToTab: number = -1
//监听屏幕横竖屏变化
listener = mediaquery.matchMediaSync('(orientation: landscape)');
@Consume @Watch('onPageShowCus') pageShow: number
@Consume @Watch('onPageHideCus') pageHide: number
@Consume @Watch('onBackPressCus') pageBackPress: number
@Consume contentDetailData: ContentDetailDTO
@Consume publishCommentModel: publishCommentModel
// 尽量不要动属性。用来作为输入了评论之后,值传递
@State lastInputedLiveComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的直播间消息
@State lastInputedChatComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的大家聊消息
@State lastLiveControl: LiveRoomItemBean = {} as LiveRoomItemBean // IM 控制消息
// 顶部状态栏高度
@Consume topSafeHeight: number
chatRoomController: LiveDetailChatRoomController = new LiveDetailChatRoomController()
@Provide banComment: boolean = true
@State isEnd: boolean = false
@Consume liveDetailPageLogic: LiveDetailPageLogic
@State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗"
@State topPlayHeight:number = this.getTopPlayHeight()
@StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm';
dialogToast: CustomDialogController = new CustomDialogController({
builder: CustomToast({
bgColor: 0xB3000000,
opacityValue: 1,
fontSizeValue: "25lpx",
lineHeightValue: "36lpx",
msg: this.toastText,
marginTop:211/2+px2vp(this.topSafeHeight)-px2vp(84/2)
}),
autoCancel: false,
alignment: DialogAlignment.Top,
customStyle: true,
maskColor: "#00000000"
})
showToastTip(msg: ResourceStr) {
this.toastText = msg
this.dialogToast.open()
}
async aboutToAppear(): Promise<void> {
Logger.info(TAG, `wyj-aboutToAppear`)
this.listener?.on("change", (mediaQueryResult) => {
Logger.info(TAG, `change;${mediaQueryResult.matches}`)
if (mediaQueryResult?.matches) {
this.displayDirection = DisplayDirection.VIDEO_HORIZONTAL
} else {
this.displayDirection = DisplayDirection.VERTICAL
}
// WindowModel.shared.setMainWindowFullScreen(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL)
})
this.getLiveDetails()
this.getLiveRoomData()
if (this.liveDetailPageLogic.dealOrShowToast()) {
if(!await onlyWifiLoadVideo()){
this.showToastTip(this.toastText)
}
}
this.configChatRoom()
}
async aboutToDisappear() {
Logger.info(TAG, `wyj-aboutToDisappear`)
await this.playerController?.stop()
await this.playerController?.release()
this.chatRoomController.disconnectLiveRoom()
}
configChatRoom() {
this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
const preDisplay = this.contentDetailData.liveInfo.preCommentFlag == 1
if (this.liveViewModel.filterMySelfCommentNoPreDisplay(liveRoomItemBean, preDisplay)) {
return
}
if (liveRoomItemBean.messageRoom == LiveMessageRoomType.living) {
this.lastInputedLiveComment = liveRoomItemBean
} else if (liveRoomItemBean.messageRoom == LiveMessageRoomType.chat) {
this.lastInputedChatComment = liveRoomItemBean
}
}
this.chatRoomController.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
switch (liveRoomItemBean.optionType) {
case LiveMessageOptType.ZH_ROOM_NUMBER_MSG: {
this.liveRoomDataBean.pv = Number(liveRoomItemBean.pv)
} break
case LiveMessageOptType.ZH_BARRAGE_SWITCH_MSG: {
const openComment = liveRoomItemBean.data == "1"
this.contentDetailData.liveInfo.openComment = openComment ? 1 : 0
} break
case LiveMessageOptType.ZH_PRE_DISPLAY_CHANGE: {
const preCommentFlag = liveRoomItemBean.data == "1"
this.contentDetailData.liveInfo.preCommentFlag = preCommentFlag ? 1 : 0
} break
case LiveMessageOptType.ZH_BARRAGE_BAN_MESSAGE:
case LiveMessageOptType.ZH_BARRAGE_UNBAN_MESSAGE: {
const banComment = liveRoomItemBean.data == "1"
this.banComment = banComment
} break
case LiveMessageOptType.ZH_STOP_LIVE:
case LiveMessageOptType.ZH_START_LIVE:
case LiveMessageOptType.ZH_CHANGE_PAD: { // 直播垫片控制
this.lastLiveControl = liveRoomItemBean
} break
case LiveMessageOptType.ZH_REPLY_MSG: {
this.lastInputedChatComment = liveRoomItemBean
} break
case LiveMessageOptType.ZH_UPDATE_MSG: {
this.lastInputedLiveComment = liveRoomItemBean
} break
case LiveMessageOptType.ZH_DELETE_MSG: {
this.lastInputedLiveComment = liveRoomItemBean
} break
case LiveMessageOptType.ZH_TOP_MSG: {
this.lastInputedLiveComment = liveRoomItemBean
} break
case LiveMessageOptType.ZH_UN_TOP_MSG: {
this.lastInputedLiveComment = liveRoomItemBean
} break
case LiveMessageOptType.ZH_WALL_MSG: {
this.lastInputedLiveComment = liveRoomItemBean
} break
default: {
Logger.warn(TAG, "暂未处理类型:" + liveRoomItemBean.optionType)
} break
}
}
this.chatRoomController.configDetail(this.contentDetailData)
}
build() {
Column() {
TopPlayComponent({ playerController: this.playerController, isEnd: this.isEnd, lastLiveControl: this.lastLiveControl })
.height(this.displayDirection == DisplayDirection.VERTICAL ? this.topPlayHeight : '100%')
.margin({
top: this.displayDirection == DisplayDirection.VERTICAL ? px2vp(this.topSafeHeight) : 0
})
TabComponent({
tabs: this.tabs,
changeToTab: this.changeToTab,
lastInputedLiveComment: this.lastInputedLiveComment,
lastInputedChatComment: this.lastInputedChatComment
})
.layoutWeight(1)
.visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
LiveOperRowListView({
operationButtonList: ['comment', 'collect', 'share', 'like'],
styleType: 1,
isLlive:this.displayDirection == DisplayDirection.VERTICAL,
contentDetailData: this.contentDetailData,
onCommentInputFocus: () => {
// 切换到大家聊
this.changeToTab = Math.random()
},
onCommentInputed: (content) => {
if (content.comment) {
this.liveViewModel.sendComment(content.comment, this.contentDetailData).then(result => {
if (!result) {
return
}
if (result.isWall == 1) {
this.lastInputedLiveComment = result
} else {
this.lastInputedChatComment = result
}
// 发布评论埋点
TrackingContent.commentClick(TrackConstants.PageName.Live_Detail,
TrackConstants.PageName.Live_Detail,
TrackParamConvert.contentDetail(this.contentDetailData));
})
}
}
}).visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
// LiveCommentComponent({ heartNum: this.liveRoomDataBean.likeNum })
// .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
}
.height('100%')
.width('100%')
}
onPageShowCus(): void {
Logger.info(TAG, `wyj-onPageShowCus`)
// WindowModel.shared.setPreferredOrientation(window.Orientation.LOCKED);
}
onPageHideCus(): void {
Logger.info(TAG, `wyj-onPageHideCus`)
this.listener.off('change');
// devicePLSensorManager.devicePLSensorOff();
}
onBackPressCus(): boolean | void {
if (this.displayDirection == DisplayDirection.VERTICAL) {
router.back()
} else {
this.displayDirection = DisplayDirection.VERTICAL
}
WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
window.Orientation.PORTRAIT :
window.Orientation.LANDSCAPE)
// devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
// window.Orientation.PORTRAIT :
// window.Orientation.LANDSCAPE);
return true
}
getLiveDetails() {
const data = this.contentDetailData
// console.error("XXXXZZZZ", 'contentDetailData ----liveState==>' + data.liveInfo?.liveState)
// console.error("XXXXZZZZ", 'contentDetailData ----liveStyle==>' + data.liveInfo?.liveStyle)
if (data.liveInfo?.liveState == 'wait') {
//直播样式 0-正常模式 , 1-隐藏直播间,2-隐藏大家聊 【人民号发布是竖屏的,为空】
if (data.liveInfo?.liveStyle == 1) {
this.tabs = ['简介', '大家聊']
} else if (data.liveInfo?.liveStyle == 2) {
this.tabs = ['简介', '直播间',]
} else {
this.tabs = ['简介', '直播间', '大家聊']
}
} else {
if (data.liveInfo?.liveStyle == 1) {
this.tabs = ['大家聊']
} else if (data.liveInfo?.liveStyle == 2) {
this.tabs = ['直播间',]
} else {
this.tabs = ['直播间', '大家聊']
}
}
}
getLiveRoomData() {
this.liveViewModel.getLiveRoomData(this.contentId)
.then(
(data) => {
this.liveRoomDataBean = data
},
() => {
})
}
getTopPlayHeight() {
let screenWidth = display.getDefaultDisplaySync().width
return px2vp(screenWidth) * 9/16.0
}
currentChanged() {
this.topPlayHeight = this.getTopPlayHeight()
}
}