xugenyuan

ref |> 直播IM动态接收消息和显示。目前是横屏直播已处理

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -19,11 +19,11 @@ export interface LiveRoomItemBean {
//guest :嘉宾,host:主持人
role: string
//ZH_TEXT_AND_IMAGE_MSG :图文,ZH_TEXT_MSG:文本,ZH_VIDEO_MSG:视频,ZH_AUDIO_MSG:音频
dataType: string
dataType: LiveMessageOptType
//管理直播间的消息类型 ZH_BARRAGE_SWITCH_MSG:弹幕开关 ZH_TOP_MSG:置顶,ZH_UN_TOP_MSG:取消置顶 ZH_STOP_LIVE: 直播结束,ZH_CHANGE_PAD直播垫片等
optionType: string
optionType: LiveMessageOptType
///房间类型,标识这个消息属于大家聊还是直播间,ZH_VIDEO:直播间 ZH_CHAT:大家聊
messageRoom: string
messageRoom: LiveMessageRoomType
//视频封面图
transcodeImageUrl: string
//视频地址
... ... @@ -38,5 +38,37 @@ export interface LiveRoomItemBean {
fullColumnImgUrlDto: FullColumnImgUrlDTO
//观看人次
pv: string
// 自义定表情 - from im
customizeExpression: number
// 自定义字段
customFormIM?: boolean // 默认来自网络接口
}
export enum LiveMessageOptType {
ZH_BARRAGE_SWITCH_MSG = "ZH_BARRAGE_SWITCH_MSG",
ZH_UPDATE_MSG = "ZH_UPDATE_MSG",
ZH_DELETE_MSG = "ZH_DELETE_MSG",
ZH_TOP_MSG = "ZH_TOP_MSG",
ZH_UN_TOP_MSG = "ZH_UN_TOP_MSG",
ZH_STOP_LIVE = "ZH_STOP_LIVE",
ZH_CHANGE_PAD = "ZH_CHANGE_PAD",
ZH_PRE_DISPLAY_CHANGE = "ZH_PRE_DISPLAY_CHANGE",
ZH_TEXT_MSG = "ZH_TEXT_MSG",
ZH_IMAGE_MSG = "ZH_IMAGE_MSG",
ZH_TEXT_AND_IMAGE_MSG = "ZH_TEXT_AND_IMAGE_MSG",
ZH_WALL_MSG = "ZH_WALL_MSG",
ZH_AUDIO_MSG = "ZH_AUDIO_MSG",
ZH_VIDEO_MSG = "ZH_VIDEO_MSG",
ZH_REPLY_MSG = "ZH_REPLY_MSG",
ZH_ROOM_NUMBER_MSG = "ZH_ROOM_NUMBER_MSG",
ZH_BARRAGE_BAN_MESSAGE = "ZH_BARRAGE_BAN_MESSAGE",
ZH_BARRAGE_UNBAN_MESSAGE = "ZH_BARRAGE_UNBAN_MESSAGE",
ZH_VOTE_MESSAGE = "ZH_VOTE_MESSAGE",
ZH_START_LIVE = "ZH_START_LIVE",
}
export enum LiveMessageRoomType {
living = "ZH_VIDEO", // 直播间
chat = "ZH_CHAT", // 大家聊
}
\ No newline at end of file
... ...
import { DateTimeUtils, Logger } from 'wdKit/Index';
import { WDPlayerController } from 'wdPlayer/Index';
import { PlayerConstants, WDPlayerController } from 'wdPlayer/Index';
let TAG: string = 'AudioRowComponent'
... ... @@ -12,6 +12,16 @@ export struct AudioRowComponent {
@State isPlaying: boolean = false
aboutToAppear(): void {
this.playerController.onCanplay = () => {
this.playerController.play()
}
this.playerController.onStatusChange = (status: number) => {
if (status == PlayerConstants.STATUS_START) {
this.isPlaying = true
} else {
this.isPlaying = false
}
}
this.playerController.firstPlay(this.audioUrl)
// this.playerController.onTimeUpdate = (nowSeconds, totalSeconds) => {
// console.log('现在时间', nowSeconds)
... ... @@ -30,7 +40,7 @@ export struct AudioRowComponent {
left: 8,
right: 6
})
.visibility(this.isPlaying ? Visibility.Visible : Visibility.Hidden)
.visibility(this.isPlaying ? Visibility.Hidden : Visibility.Visible)
Text(`${DateTimeUtils.getFormattedDuration(this.duration)}`)
.fontColor('#666666')
.fontWeight(400)
... ...
... ... @@ -10,6 +10,8 @@ import { LiveRoomItemBean } from 'wdBean/Index';
import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
import { JSON } from '@kit.ArkTS';
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
const TAG = "LiveRoomManager"
export class LiveRoom extends ChatroomStatusListener {
... ... @@ -32,7 +34,7 @@ export class LiveRoom extends ChatroomStatusListener {
enterRoom() {
let roomId = this.connectRoomBaseInfo?.roomID
let msgCount = 10;
let msgCount = 0;
Logger.debug(TAG, `will enterRoom roomId: ${roomId}`);
IMEngine.getInstance().joinExistingChatroom(roomId, msgCount).then(result => {
... ... @@ -108,6 +110,7 @@ export class LiveRoom extends ChatroomStatusListener {
let optionType = liveRoomItemBean.optionType != undefined ? liveRoomItemBean.optionType : liveRoomItemBean.dataType
if (this.isHistoryMessage(optionType)) {
liveRoomItemBean.customFormIM = true
if (this.onHistoryMessage) {
this.onHistoryMessage(liveRoomItemBean)
}
... ... @@ -124,16 +127,16 @@ export class LiveRoom extends ChatroomStatusListener {
isHistoryMessage(optionType: string): boolean {
let isHistoryMessage = false
switch (optionType) {
case "ZH_TEXT_MSG":
case "ZH_IMAGE_MSG":
case "ZH_TEXT_AND_IMAGE_MSG":
case "ZH_AUDIO_MSG":
case "ZH_VIDEO_MSG": {
case LiveMessageOptType.ZH_TEXT_MSG:
case LiveMessageOptType.ZH_IMAGE_MSG:
case LiveMessageOptType.ZH_TEXT_AND_IMAGE_MSG:
case LiveMessageOptType.ZH_AUDIO_MSG:
case LiveMessageOptType.ZH_VIDEO_MSG: {
isHistoryMessage = true
} break;
default:
break;
}
return isHistoryMessage
return isHistoryMessage
}
}
\ No newline at end of file
... ...
... ... @@ -12,6 +12,7 @@ import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment
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';
let TAG: string = 'DetailPlayLivePage';
... ... @@ -83,27 +84,31 @@ export struct DetailPlayLivePage {
if(!await onlyWifiLoadVideo()){
this.showToastTip(this.toastText)
}
this.configChatRoom()
}
async aboutToDisappear() {
Logger.info(TAG, `wyj-aboutToDisappear`)
await this.playerController?.stop()
await this.playerController?.release()
}
configChatRoom() {
this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (liveRoomItemBean.messageRoom == "ZH_VIDEO") {
if (liveRoomItemBean.messageRoom == LiveMessageRoomType.living) {
this.lastInputedLiveComment = liveRoomItemBean
} else if (liveRoomItemBean.messageRoom == "ZH_CHAT") {
} else if (liveRoomItemBean.messageRoom == LiveMessageRoomType.chat) {
this.lastInputedChatComment = liveRoomItemBean
}
}
this.chatRoomController.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (liveRoomItemBean.optionType == "ZH_ROOM_NUMBER_MSG") {
if (liveRoomItemBean.optionType == LiveMessageOptType.ZH_ROOM_NUMBER_MSG) {
this.liveRoomDataBean.pv = Number(liveRoomItemBean.pv)
}
}
this.chatRoomController.configDetail(this.contentDetailData)
}
async aboutToDisappear() {
Logger.info(TAG, `wyj-aboutToDisappear`)
await this.playerController?.stop()
await this.playerController?.release()
}
build() {
Column() {
TopPlayComponent({ playerController: this.playerController })
... ...
import { HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork';
import { HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { Logger, ToastUtils, EmitterEventId, EmitterUtils, SPHelper } from 'wdKit';
import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
... ... @@ -6,6 +6,7 @@ import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
ReserveItemBean, ValueType } from 'wdBean/Index';
import { ContentDetailRequest } from 'wdDetailPlayApi/Index';
import { SpConstants } from 'wdConstant/Index';
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
const TAG = 'LiveModel'
... ... @@ -113,7 +114,7 @@ export class LiveModel {
params['liveId'] = liveId
params['pageSize'] = pageSize + ''
return new Promise<LiveRoomBean>((success, fail) => {
HttpRequest.post<ResponseDTO<LiveRoomBean>>(
HttpBizUtil.post<ResponseDTO<LiveRoomBean>>(
HttpUrlUtils.getLiveChatListUrl(),
params,
).then((data: ResponseDTO<LiveRoomBean>) => {
... ... @@ -321,7 +322,7 @@ export class LiveModel {
let commentItem: LiveRoomItemBean = {} as LiveRoomItemBean
commentItem.text = comment
commentItem.isWall = 0
commentItem.dataType = "ZH_TEXT_MSG"
commentItem.dataType = LiveMessageOptType.ZH_TEXT_MSG
let params: Record<string, string | number> = {};
params["liveId"] = liveId
... ...
... ... @@ -3,6 +3,7 @@ import { Logger, StringUtils } from 'wdKit/Index'
// import { Action, LiveRoomItemBean, Params, PhotoListBean } from 'wdBean/Index'
import { WDRouterRule } from 'wdRouter'
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'
const TAG = "TabChatItemComponent"
... ... @@ -22,61 +23,32 @@ export struct TabChatItemComponent {
.width(24)
.height(24)
Column() {
if (this.item.dataType == 'ZH_IMAGE_MSG') {
Row() {
Text() {
Span(this.item.senderUserName + ': ')
.fontColor('#666666')
}
.margin({ left: 8 })
.lineHeight(20)
.layoutWeight(1)
.fontSize('14fp')
.fontWeight(400)
Row() {
Text() {
Span((this.item.senderUserName ?? "游客") + ': ')
.fontColor('#666666')
Span(this.item.text)
.fontColor('#222222')
}
.alignItems(VerticalAlign.Top)
if (this.item.pictureUrls && this.item.pictureUrls.length > 0) {
Image(this.item.pictureUrls[0])
.width(`100%`)
.objectFit(ImageFit.Contain)
.borderRadius(4)
.margin({
top: 10
})
.onClick(() => {
this.gotoMultipleListImagePage(this.item.pictureUrls[0])
})
}
} else {
Row() {
Text() {
Span(this.item.senderUserName + ': ')
.fontColor('#666666')
Span(this.item.text)
.fontColor('#222222')
}
.margin({ left: 8 })
.lineHeight(20)
.layoutWeight(1)
.fontSize('14fp')
.fontWeight(400)
}
.alignItems(VerticalAlign.Top)
.margin({ left: 8 })
.lineHeight(20)
.layoutWeight(1)
.fontSize('14fp')
.fontWeight(400)
}
.alignItems(VerticalAlign.Top)
if (this.item.dataType == 'ZH_TEXT_AND_IMAGE_MSG' && this.item.pictureUrls &&
this.item.pictureUrls.length > 0) {
Image(this.item.pictureUrls[0])
.width(`100%`)
.objectFit(ImageFit.Contain)
.borderRadius(4)
.margin({
top: 10
})
.onClick(() => {
this.gotoMultipleListImagePage(this.item.pictureUrls[0])
})
}
if (this.item.pictureUrls && this.item.pictureUrls.length > 0) {
Image(this.item.pictureUrls[0])
.width(this.item.customizeExpression === 1 ? 72 : `100%`)
.objectFit(ImageFit.Contain)
.borderRadius(4)
.margin({
top: 10, bottom: 4
})
.onClick(() => {
this.gotoMultipleListImagePage(this.item.pictureUrls[0])
})
}
}
... ...
... ... @@ -10,6 +10,7 @@ import { LiveViewModel } from '../../viewModel/LiveViewModel'
import { Logger } from 'wdKit'
import LoadMoreLayout from 'wdComponent/src/main/ets/components/page/LoadMoreLayout'
import { PeopleShipNoMoreData } from 'wdComponent/src/main/ets/components/reusable/PeopleShipNoMoreData'
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'
const TAG: string = 'TabLiveComponent';
... ... @@ -34,7 +35,11 @@ export struct TabLiveComponent {
lastInputedCommentChanged(info: string) {
Logger.debug(TAG, "1显示评论》》》: " + JSON.stringify(this.lastInputedComment))
this.liveList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
if (this.liveList.totalCount() === 0) {
this.liveList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
} else {
this.liveList.addFirstItem(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
}
this.pageModel.viewType = ViewType.LOADED;
}
... ... @@ -190,7 +195,7 @@ export struct TabLiveComponent {
liveRoomItemBeanTemp.senderUserName = '人民日报主持人'
liveRoomItemBeanTemp.pictureUrls = []
liveRoomItemBeanTemp.pictureUrls.push(this.contentDetailData?.fullColumnImgUrls[0]?.url)
liveRoomItemBeanTemp.dataType = 'ZH_TEXT_AND_IMAGE_MSG'
liveRoomItemBeanTemp.dataType = LiveMessageOptType.ZH_TEXT_AND_IMAGE_MSG
let temp = this.contentDetailData?.fullColumnImgUrls[0]
if (temp) {
liveRoomItemBeanTemp.pictureResolutions = []
... ...
import { Action, LiveRoomItemBean, Params, PhotoListBean } from 'wdBean/Index'
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'
import { AudioRowComponent } from 'wdComponent/Index'
import { DateTimeUtils, StringUtils } from 'wdKit/Index'
import { WDRouterRule } from 'wdRouter/Index'
... ... @@ -83,7 +84,7 @@ export struct TabLiveItemComponent {
.textAlign(TextAlign.Start)
//ZH_TEXT_AND_IMAGE_MSG :图文,ZH_TEXT_MSG:文本,ZH_VIDEO_MSG:视频,ZH_AUDIO_MSG:音频
//图文
if (this.item.dataType === 'ZH_TEXT_AND_IMAGE_MSG') {
if (this.item.dataType === LiveMessageOptType.ZH_TEXT_AND_IMAGE_MSG) {
List({ space: this.item.pictureUrls.length == 1 ? 0 : 5 }) {
ForEach(this.item.pictureUrls, (itemSub: string, index: number) => {
ListItem() {
... ... @@ -112,14 +113,14 @@ export struct TabLiveItemComponent {
})
}
//音频
else if (this.item.dataType === 'ZH_AUDIO_MSG') {
else if (this.item.dataType === LiveMessageOptType.ZH_AUDIO_MSG) {
AudioRowComponent({
audioUrl: this.item.audioUrl,
duration: this.item.duration
})
}
//视频
else if (this.item.dataType === 'ZH_VIDEO_MSG') {
else if (this.item.dataType === LiveMessageOptType.ZH_VIDEO_MSG) {
RelativeContainer() {
Image(this.item.transcodeImageUrl)
.width('100%')
... ...
... ... @@ -60,10 +60,10 @@ export class WDPlayerController {
*/
private createAVPlayer(): Promise<void> {
return new Promise((resolve, reject) => {
Logger.error("开始创建")
Logger.debug(TAG, "开始创建")
media.createAVPlayer().then((avPlayer) => {
if (avPlayer) {
Logger.error(TAG, "创建完成1")
Logger.debug(TAG, "创建完成1")
this.avPlayer = avPlayer;
this.bindState();
resolve();
... ...