ref |> 进入直播链接容易IM,已可以接收消息
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
15 changed files
with
402 additions
and
113 deletions
| @@ -51,6 +51,9 @@ export class SpConstants{ | @@ -51,6 +51,9 @@ export class SpConstants{ | ||
| 51 | static FIRSTCOMMENTTIME = 'firstCommentTime' | 51 | static FIRSTCOMMENTTIME = 'firstCommentTime' |
| 52 | static TOURIST_NICK_NAME = 'touristNickName' | 52 | static TOURIST_NICK_NAME = 'touristNickName' |
| 53 | 53 | ||
| 54 | + // 融云IM App存储key | ||
| 55 | + static ROMGYUN_IM_APPKEY = 'rongyunIMAppKey' | ||
| 56 | + | ||
| 54 | // 个推推送 | 57 | // 个推推送 |
| 55 | static GETUI_PUSH_CID = "cid" | 58 | static GETUI_PUSH_CID = "cid" |
| 56 | static GETUI_PUSH_DEVICE_TOKEN = "deviceToken" | 59 | static GETUI_PUSH_DEVICE_TOKEN = "deviceToken" |
| @@ -210,6 +210,11 @@ export class HttpUrlUtils { | @@ -210,6 +210,11 @@ export class HttpUrlUtils { | ||
| 210 | static readonly LIVE_CHAT_LIST_PATH: string = "/api/live-center-message/zh/a/live/message/chat/list"; | 210 | static readonly LIVE_CHAT_LIST_PATH: string = "/api/live-center-message/zh/a/live/message/chat/list"; |
| 211 | 211 | ||
| 212 | /** | 212 | /** |
| 213 | + * 直播获取IM Token | ||
| 214 | + */ | ||
| 215 | + static readonly LIVE_GET_IM_TOKEN: string = "/api/live-center-message/zh/a/live/getToken"; | ||
| 216 | + | ||
| 217 | + /** | ||
| 213 | * C端评论列表 竖屏直播间 | 218 | * C端评论列表 竖屏直播间 |
| 214 | */ | 219 | */ |
| 215 | static readonly LIVE_COMMENTS_LIST_PATH: string = "/api/live-center-message/zh/a/live/message/comments/list"; | 220 | static readonly LIVE_COMMENTS_LIST_PATH: string = "/api/live-center-message/zh/a/live/message/comments/list"; |
| @@ -656,6 +661,11 @@ export class HttpUrlUtils { | @@ -656,6 +661,11 @@ export class HttpUrlUtils { | ||
| 656 | return url | 661 | return url |
| 657 | } | 662 | } |
| 658 | 663 | ||
| 664 | + static getLiveIMToken() { | ||
| 665 | + let url = HttpUrlUtils.getHost() + HttpUrlUtils.LIVE_GET_IM_TOKEN | ||
| 666 | + return url | ||
| 667 | + } | ||
| 668 | + | ||
| 659 | static getLiveListUrl() { | 669 | static getLiveListUrl() { |
| 660 | let url = HttpUrlUtils.getHost() + HttpUrlUtils.LIVE_LIST_PATH | 670 | let url = HttpUrlUtils.getHost() + HttpUrlUtils.LIVE_LIST_PATH |
| 661 | return url | 671 | return url |
| 1 | export { DetailPlayLivePage } from './src/main/ets/pages/DetailPlayLivePage' | 1 | export { DetailPlayLivePage } from './src/main/ets/pages/DetailPlayLivePage' |
| 2 | 2 | ||
| 3 | export { DetailPlayVLivePage } from './src/main/ets/pages/DetailPlayVLivePage' | 3 | export { DetailPlayVLivePage } from './src/main/ets/pages/DetailPlayVLivePage' |
| 4 | + | ||
| 5 | +export { LiveRoomManager } from "./src/main/ets/im/LiveRoomManager" |
| 1 | -import { JsonUtil, MessageContent, MessageFlag, MessageTag } from '@rongcloud/imlib'; | ||
| 2 | - | ||
| 3 | - | ||
| 4 | -const CustomMessageContentObjectName = "App:CustomMsg"; | ||
| 5 | -const CustomMessageContentFlag = MessageFlag.Count; | ||
| 6 | - | ||
| 7 | -@MessageTag(CustomMessageContentObjectName,CustomMessageContentFlag) | ||
| 8 | -export class CustomMessageContent extends MessageContent { | ||
| 9 | - type: string = "" //消息类型 | ||
| 10 | - data: string = "" //消息体 json字符串 | ||
| 11 | - constructor() { | ||
| 12 | - super() | ||
| 13 | - } | ||
| 14 | - | ||
| 15 | - encode(): string { | ||
| 16 | - let map = super.encodeBaseData(); | ||
| 17 | - map.set("type", this.type as Object) | ||
| 18 | - map.set("data", this.data as Object) | ||
| 19 | - return JsonUtil.stringifyFromMap(map); | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - decode(contentJson: string): void { | ||
| 23 | - // 5.1 将字符串转为 map | ||
| 24 | - let map = JsonUtil.parseToMap(contentJson); | ||
| 25 | - // 5.2 将基类的数据解析出来 | ||
| 26 | - super.decodeBaseData(map); | ||
| 27 | - | ||
| 28 | - // 5.3 将本类的独有属性解析 | ||
| 29 | - // 说明:需要将 Object 转为对应的数据类型 | ||
| 30 | - this.type = map.get("type") as string; | ||
| 31 | - this.data = map.get("data") as string; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - getClassName(): string { | ||
| 35 | - return CustomMessageContent.name; | ||
| 36 | - } | ||
| 37 | -} |
| 1 | -import { | ||
| 2 | - ConversationIdentifier, | ||
| 3 | - ConversationType, | ||
| 4 | - IAsyncResult, | ||
| 5 | - IMEngine, | ||
| 6 | - InitOption, | ||
| 7 | - ISendMsgOption, | ||
| 8 | - Message, | ||
| 9 | - ReceivedInfo | ||
| 10 | -} from '@rongcloud/imlib'; | ||
| 11 | -import { Context } from '@kit.AbilityKit'; | ||
| 12 | -import { hilog } from '@kit.PerformanceAnalysisKit'; | ||
| 13 | -import { CustomMessageContent } from './CustomMessageContent'; | ||
| 14 | - | ||
| 15 | -export class IMHelper { | ||
| 16 | - private static appKey: string = "c9kqb3rdcfolj" | ||
| 17 | - | ||
| 18 | - /**初始化*/ | ||
| 19 | - static initSdk(context: Context) { | ||
| 20 | - let initOption = new InitOption(); | ||
| 21 | - let appKey = IMHelper.appKey; | ||
| 22 | - IMEngine.getInstance().init(context, appKey, initOption); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - /**注册消息监听*/ | ||
| 26 | - static registerMsgListener() { | ||
| 27 | - IMEngine.getInstance().setMessageReceivedListener((message: Message, info: ReceivedInfo) => { | ||
| 28 | - // 针对接收离线消息时,服务端会将 200 条消息打成一个包发到客户端,客户端对这包数据进行解析。该参数表示每个数据包数据逐条上抛后,还剩余的条数 | ||
| 29 | - let left = info.left; | ||
| 30 | - // 消息是否离线消息 | ||
| 31 | - let isOffline = info.isOffline; | ||
| 32 | - // 是否在服务端还存在未下发的消息包 | ||
| 33 | - let hasPackage = info.hasPackage; | ||
| 34 | - hilog.info(0x0000, 'IM-App', 'message: ' + message + "//" + info.hasPackage); | ||
| 35 | - }); | ||
| 36 | - | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - /**建立 IM 连接*/ | ||
| 40 | - static creatSocket(iMToken: string) { | ||
| 41 | - // let token = "m8KmlHGuI4wjGBr2sHaUAASYiD7nx6VZJ5vkHoVrMhU=@b20a.cn.rongnav.com;b20a.cn.rongcfg.com"; | ||
| 42 | - // iMToken = "m8KmlHGuI4zGTdp+DIN9qwSYiD7nx6VZmZKqed9uqUk=@b20a.cn.rongnav.com;b20a.cn.rongcfg.com"; | ||
| 43 | - let timeout = 5; | ||
| 44 | - | ||
| 45 | - hilog.info(0x0000, 'IM-App', 'connect token:%{public}s', iMToken); | ||
| 46 | - IMEngine.getInstance().connect(iMToken, timeout) | ||
| 47 | - .then(result => { | ||
| 48 | - hilog.info(0x0000, 'IM-App', 'connect result :%{public}s', JSON.stringify(result)); | ||
| 49 | - }); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - /**发送消息*/ | ||
| 53 | - static sendMsg(type: ConversationType, targetId: string, data: CustomMessageContent): Promise<IAsyncResult<Message>> { | ||
| 54 | - let conId = new ConversationIdentifier(); | ||
| 55 | - conId.conversationType = type; | ||
| 56 | - conId.targetId = targetId; // 按需填写实际的会话 id | ||
| 57 | - | ||
| 58 | - let option: ISendMsgOption = {}; | ||
| 59 | - | ||
| 60 | - // 创建消息体 | ||
| 61 | - let msg = new Message(conId, data); | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - // IMEngine.getInstance().sendMessage(msg,option,(msg: Message) => { | ||
| 65 | - // // 消息入库回调 | ||
| 66 | - // hilog.info(0x0000, 'IM-App', 'SendTextMessage onSave msg:%{public}s', JSON.stringify(msg)); | ||
| 67 | - // }).then(result => { | ||
| 68 | - // // 消息发送结果 | ||
| 69 | - // hilog.info(0x0000, 'IM-App', 'SendTextMessage onResult :%{public}s', JSON.stringify(result)); | ||
| 70 | - // }) | ||
| 71 | - return IMEngine.getInstance().sendMessage(msg, option, () => { | ||
| 72 | - }); | ||
| 73 | - } | ||
| 74 | -} |
| 1 | +import { ContentDetailDTO } from 'wdBean/Index' | ||
| 2 | +import { LiveRoom } from './LiveRoom' | ||
| 3 | +import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' | ||
| 4 | +import { LiveRoomManager } from './LiveRoomManager' | ||
| 5 | + | ||
| 6 | +export class LiveDetailChatRoomController { | ||
| 7 | + | ||
| 8 | + detail?: ContentDetailDTO | ||
| 9 | + | ||
| 10 | + public configDetail(detail: ContentDetailDTO) { | ||
| 11 | + this.detail = detail | ||
| 12 | + | ||
| 13 | + let roomInfo = new LiveRoomBaseInfo() | ||
| 14 | + roomInfo.roomID = detail.liveInfo.mlive.roomId | ||
| 15 | + roomInfo.mliveID = detail.liveInfo.mlive.mliveId | ||
| 16 | + roomInfo.liveID = detail.newsId + "" | ||
| 17 | + | ||
| 18 | + this.listenConnect() | ||
| 19 | + | ||
| 20 | + LiveRoomManager.sharedManager().connectLiveRoomWith(roomInfo) | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + listenConnect() { | ||
| 24 | + LiveRoomManager.sharedManager().onConnectedRoom = (room: LiveRoom) => { | ||
| 25 | + | ||
| 26 | + room.onJoined = (room: LiveRoom) => { | ||
| 27 | + | ||
| 28 | + } | ||
| 29 | + room.onJoinFailed = (room: LiveRoom, code: number) => { | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + room.onExited = (room: LiveRoom) => { | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + room.enterRoom() | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | +} |
| 1 | +import { ChatroomDestroyType, | ||
| 2 | + ChatroomJoinedInfo, | ||
| 3 | + ChatroomStatusListener, | ||
| 4 | + EngineError, | ||
| 5 | + IMEngine, Message, ReceivedInfo, | ||
| 6 | + TextMessage} from '@rongcloud/imlib'; | ||
| 7 | +import { Logger } from 'wdKit/Index'; | ||
| 8 | +import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' | ||
| 9 | +import { JSON } from '@kit.ArkTS'; | ||
| 10 | + | ||
| 11 | +const TAG = "LiveRoomManager" | ||
| 12 | + | ||
| 13 | +export class LiveRoom extends ChatroomStatusListener { | ||
| 14 | + | ||
| 15 | + connectRoomBaseInfo?: LiveRoomBaseInfo | ||
| 16 | + | ||
| 17 | + /// 回调 | ||
| 18 | + onJoined?: (room: LiveRoom) => void | ||
| 19 | + onJoinFailed?: (room: LiveRoom, code: number) => void | ||
| 20 | + onExited?: (room: LiveRoom) => void | ||
| 21 | + | ||
| 22 | + constructor(baseInfo?: LiveRoomBaseInfo) { | ||
| 23 | + super() | ||
| 24 | + this.connectRoomBaseInfo = baseInfo | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + enterRoom() { | ||
| 28 | + let roomId = this.connectRoomBaseInfo?.roomID | ||
| 29 | + let msgCount = 10; | ||
| 30 | + | ||
| 31 | + Logger.debug(TAG, `will enterRoom roomId: ${roomId}`); | ||
| 32 | + IMEngine.getInstance().joinExistingChatroom(roomId, msgCount).then(result => { | ||
| 33 | + if (EngineError.Success !== result.code) { | ||
| 34 | + // 加入聊天室失败 | ||
| 35 | + Logger.error(TAG, 'onChatroomJoinFailed roomId: ' + roomId + " code: " + result.code); | ||
| 36 | + return; | ||
| 37 | + } | ||
| 38 | + if (!result.data) { | ||
| 39 | + // 聊天室加入信息失败 | ||
| 40 | + return; | ||
| 41 | + } | ||
| 42 | + let joinedInfo = result.data as ChatroomJoinedInfo; | ||
| 43 | + }); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + exitRoom() { | ||
| 47 | + let roomId = this.connectRoomBaseInfo?.roomID | ||
| 48 | + | ||
| 49 | + IMEngine.getInstance().quitChatroom(roomId).then(result => { | ||
| 50 | + if (EngineError.Success !== result.code) { | ||
| 51 | + // 退出聊天室失败 | ||
| 52 | + return; | ||
| 53 | + } | ||
| 54 | + }); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + // ---- ChatroomStatusListener | ||
| 58 | + onChatroomJoining(roomId: string): void { | ||
| 59 | + Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + onChatroomJoined(roomId: string, info: ChatroomJoinedInfo): void { | ||
| 63 | + Logger.debug(TAG, `onChatroomJoined roomId` + roomId + " " + JSON.stringify(info)); | ||
| 64 | + if (this.onJoined) { | ||
| 65 | + this.onJoined(this) | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + onChatroomJoinFailed(roomId: string, code: EngineError): void { | ||
| 70 | + Logger.error(TAG, 'onChatroomJoinFailed roomId: ' + roomId + " code: " + code); | ||
| 71 | + if (this.onJoinFailed) { | ||
| 72 | + this.onJoinFailed(this, code) | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + onChatroomQuited(roomId: string): void { | ||
| 77 | + Logger.warn(TAG, 'onChatroomQuited roomId: ' + roomId); | ||
| 78 | + if (this.onExited) { | ||
| 79 | + this.onExited(this) | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + onChatroomDestroyed(roomId: string, type: ChatroomDestroyType): void { | ||
| 84 | + Logger.debug(TAG, 'onChatroomDestroyed roomId: ' + roomId + " type: " + type); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // --- on message | ||
| 88 | + onMessage(message: Message, info: ReceivedInfo) { | ||
| 89 | + | ||
| 90 | + Logger.debug(TAG, 'onMessage message: ' + JSON.stringify(message)); | ||
| 91 | + | ||
| 92 | + if (message.objectName != "RC:TxtMsg") { | ||
| 93 | + return | ||
| 94 | + } | ||
| 95 | + let textMsg = message.content as TextMessage | ||
| 96 | + textMsg.content | ||
| 97 | + | ||
| 98 | + | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | +} |
| 1 | +import { | ||
| 2 | + ChatroomDestroyType, | ||
| 3 | + ChatroomJoinedInfo, | ||
| 4 | + ChatroomStatusListener, ConnectionStatus, EngineError, IMEngine, InitOption, | ||
| 5 | + Message, | ||
| 6 | + ReceivedInfo} from '@rongcloud/imlib' | ||
| 7 | +import { SpConstants } from 'wdConstant/Index' | ||
| 8 | +import { CrptoUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index' | ||
| 9 | +import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index' | ||
| 10 | +import { Context } from '@kit.AbilityKit'; | ||
| 11 | +import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' | ||
| 12 | +import { LiveRoom } from './LiveRoom' | ||
| 13 | + | ||
| 14 | +const TAG = "LiveRoomManager" | ||
| 15 | + | ||
| 16 | +export class LiveRoomManager { | ||
| 17 | + | ||
| 18 | + private static roomManager: LiveRoomManager | ||
| 19 | + | ||
| 20 | + private static RONGYUN_IM_APPKEY = "k51hidwqk50jb" | ||
| 21 | + private static RONGYUN_IM_APPKEY_TEST = "m7ua80gbm7yim" | ||
| 22 | + | ||
| 23 | + private hasInited: boolean = false | ||
| 24 | + public gotContextFunc?: () => Context = undefined | ||
| 25 | + | ||
| 26 | + private imTokenInfo?: string = undefined | ||
| 27 | + private connectRoomBaseInfo?: LiveRoomBaseInfo | ||
| 28 | + private connectedRoom?: LiveRoom | ||
| 29 | + | ||
| 30 | + /// 连接成功回调 | ||
| 31 | + onConnectedRoom?:(room: LiveRoom) => void | ||
| 32 | + | ||
| 33 | + private constructor() { | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public static sharedManager() { | ||
| 37 | + if (!LiveRoomManager.roomManager) { | ||
| 38 | + LiveRoomManager.roomManager = new LiveRoomManager() | ||
| 39 | + } | ||
| 40 | + LiveRoomManager.roomManager.checkToInitManager() | ||
| 41 | + return LiveRoomManager.roomManager | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public connectLiveRoomWith(baseInfo: LiveRoomBaseInfo) { | ||
| 45 | + this.connectRoomBaseInfo = baseInfo | ||
| 46 | + if (this.imTokenInfo) { | ||
| 47 | + this.connectWithIMToken(this.imTokenInfo) | ||
| 48 | + return | ||
| 49 | + } | ||
| 50 | + this.fetchIMToken().then((token: string) => { | ||
| 51 | + this.imTokenInfo = token; | ||
| 52 | + this.connectWithIMToken(token) | ||
| 53 | + }) | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public disconnect() { | ||
| 57 | + this.connectedRoom?.exitRoom() | ||
| 58 | + this.connectedRoom = undefined | ||
| 59 | + IMEngine.getInstance().disconnect(true) | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + private checkToInitManager() { | ||
| 67 | + if (this.hasInited) { | ||
| 68 | + return | ||
| 69 | + } | ||
| 70 | + if (this.gotContextFunc) { | ||
| 71 | + let initOption = new InitOption(); | ||
| 72 | + IMEngine.getInstance().init(this.gotContextFunc(), this.getAppKey(), initOption); | ||
| 73 | + this.listenStatus() | ||
| 74 | + this.hasInited = true | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + private listenStatus() { | ||
| 79 | + EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => { | ||
| 80 | + this.imTokenInfo = undefined | ||
| 81 | + IMEngine.getInstance().disconnect(true) | ||
| 82 | + }) | ||
| 83 | + | ||
| 84 | + IMEngine.getInstance().setConnectionStatusListener((status: ConnectionStatus) => { | ||
| 85 | + switch (status) { | ||
| 86 | + case ConnectionStatus.Connecting: { | ||
| 87 | + Logger.debug(TAG, "ConnectionStatus => 开始连接, 连接中....") | ||
| 88 | + } break | ||
| 89 | + case ConnectionStatus.Connected: { | ||
| 90 | + Logger.debug(TAG, "ConnectionStatus => 链接成功") | ||
| 91 | + this.processConnected() | ||
| 92 | + } break | ||
| 93 | + case ConnectionStatus.DisconnectNetworkUnavailable: { | ||
| 94 | + Logger.debug(TAG, "ConnectionStatus => 连接异常,SDK 会做好自动重连,开发者无须处理") | ||
| 95 | + } break | ||
| 96 | + case ConnectionStatus.DisconnectUserKicked: { | ||
| 97 | + Logger.debug(TAG, "ConnectionStatus => 当前用户在其他设备上登录,此设备被踢下线") | ||
| 98 | + } break | ||
| 99 | + case ConnectionStatus.DisconnectConnectionTimeout: { | ||
| 100 | + Logger.debug(TAG, "ConnectionStatus => 链接超时") | ||
| 101 | + } break | ||
| 102 | + case ConnectionStatus.DisconnectUserLogout: { | ||
| 103 | + Logger.debug(TAG, "ConnectionStatus => 退出连接") | ||
| 104 | + } break | ||
| 105 | + case ConnectionStatus.DisconnectTokenIncorrect: { | ||
| 106 | + Logger.debug(TAG, "ConnectionStatus => token无效,请检查AppKey配置,或者token过期,需要重新获取token") | ||
| 107 | + } break | ||
| 108 | + case ConnectionStatus.DisconnectTokenExpired: { | ||
| 109 | + Logger.debug(TAG, "ConnectionStatus => token过期,需要重新获取token") | ||
| 110 | + } break | ||
| 111 | + default : { | ||
| 112 | + Logger.debug(TAG, "ConnectionStatus => 其他状态:" + status) | ||
| 113 | + } break | ||
| 114 | + } | ||
| 115 | + }) | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + private connectWithIMToken(token: string) { | ||
| 119 | + const timeout = 5 | ||
| 120 | + IMEngine.getInstance().connect(token, timeout).then(result => { | ||
| 121 | + if (EngineError.Success === result.code) { | ||
| 122 | + // 连接成功 | ||
| 123 | + let userId = result.userId; | ||
| 124 | + Logger.debug(TAG, "连接成功:" + userId) | ||
| 125 | + return | ||
| 126 | + } | ||
| 127 | + if (EngineError.ConnectionExists === result.code) { | ||
| 128 | + Logger.debug(TAG, "连接已存在") | ||
| 129 | + this.processConnected() | ||
| 130 | + return | ||
| 131 | + } | ||
| 132 | + Logger.debug(TAG, "连接结果:" + result.code) | ||
| 133 | + }); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + private processConnected() { | ||
| 137 | + this.connectedRoom = new LiveRoom(this.connectRoomBaseInfo) | ||
| 138 | + | ||
| 139 | + // let listener: ChatroomStatusListener = { | ||
| 140 | + // onChatroomJoining(roomId: string): void { | ||
| 141 | + // Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 142 | + // LiveRoomManager.sharedManager().connectedRoom?.onChatroomJoining(roomId) | ||
| 143 | + // }, | ||
| 144 | + // | ||
| 145 | + // onChatroomJoined(roomId: string, info: ChatroomJoinedInfo): void { | ||
| 146 | + // Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 147 | + // LiveRoomManager.sharedManager().connectedRoom?.onChatroomJoined(roomId, info) | ||
| 148 | + // }, | ||
| 149 | + // | ||
| 150 | + // onChatroomJoinFailed(roomId: string, code: EngineError): void { | ||
| 151 | + // Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 152 | + // LiveRoomManager.sharedManager().connectedRoom?.onChatroomJoinFailed(roomId, code) | ||
| 153 | + // }, | ||
| 154 | + // | ||
| 155 | + // onChatroomQuited(roomId: string): void { | ||
| 156 | + // Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 157 | + // LiveRoomManager.sharedManager().connectedRoom?.onChatroomQuited(roomId) | ||
| 158 | + // }, | ||
| 159 | + // | ||
| 160 | + // onChatroomDestroyed(roomId: string, type: ChatroomDestroyType): void { | ||
| 161 | + // Logger.debug(TAG, `onChatroomJoining roomId: ${roomId}`); | ||
| 162 | + // LiveRoomManager.sharedManager().connectedRoom?.onChatroomDestroyed(roomId, type) | ||
| 163 | + // }, | ||
| 164 | + // } | ||
| 165 | + IMEngine.getInstance().setChatroomStatusListener(this.connectedRoom); | ||
| 166 | + IMEngine.getInstance().setMessageReceivedListener(this.connectedRoom.onMessage); | ||
| 167 | + if (this.onConnectedRoom) { | ||
| 168 | + this.onConnectedRoom(this.connectedRoom) | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + private fetchIMToken() { | ||
| 173 | + return new Promise<string>(async (success, fail) => { | ||
| 174 | + | ||
| 175 | + let userId = HttpUtils.getUserId() | ||
| 176 | + if (userId.length == 0) { | ||
| 177 | + const deviceId = DeviceUtil.clientId() | ||
| 178 | + userId = await CrptoUtils.md5(deviceId) | ||
| 179 | + } | ||
| 180 | + let url = HttpUrlUtils.getLiveIMToken() + `?userId=${userId}&userName=${userId}` | ||
| 181 | + | ||
| 182 | + HttpBizUtil.get<ResponseDTO<string>>(url).then((data: ResponseDTO<string>) => { | ||
| 183 | + if (data.data) { | ||
| 184 | + success(data.data) | ||
| 185 | + } else { | ||
| 186 | + fail(data.message) | ||
| 187 | + } | ||
| 188 | + }).catch((error: Error) => { | ||
| 189 | + fail(error.message) | ||
| 190 | + }) | ||
| 191 | + }) | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + private getAppKey() { | ||
| 195 | + const appKey = SPHelper.default.getSync(SpConstants.ROMGYUN_IM_APPKEY, "") as string | ||
| 196 | + if (appKey.length > 0) { | ||
| 197 | + return appKey | ||
| 198 | + } | ||
| 199 | + const isOnlineEnv = HostManager.getHost() === HostEnum.HOST_PRODUCT | ||
| 200 | + return isOnlineEnv ? LiveRoomManager.RONGYUN_IM_APPKEY : LiveRoomManager.RONGYUN_IM_APPKEY_TEST | ||
| 201 | + } | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +interface LiveIMToken { | ||
| 205 | + // 连接IM的token | ||
| 206 | + refreshToken: string | ||
| 207 | + | ||
| 208 | + //token过期时间 | ||
| 209 | + deadline: number | ||
| 210 | +} |
| @@ -11,6 +11,7 @@ import { LiveOperRowListView } from 'wdComponent'; | @@ -11,6 +11,7 @@ import { LiveOperRowListView } from 'wdComponent'; | ||
| 11 | import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'; | 11 | import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'; |
| 12 | import { TrackConstants, TrackingContent, TrackParamConvert } from 'wdTracking/Index'; | 12 | import { TrackConstants, TrackingContent, TrackParamConvert } from 'wdTracking/Index'; |
| 13 | import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg'; | 13 | import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg'; |
| 14 | +import { LiveDetailChatRoomController } from '../im/LiveDetailChatRoomController'; | ||
| 14 | 15 | ||
| 15 | let TAG: string = 'DetailPlayLivePage'; | 16 | let TAG: string = 'DetailPlayLivePage'; |
| 16 | 17 | ||
| @@ -41,6 +42,7 @@ export struct DetailPlayLivePage { | @@ -41,6 +42,7 @@ export struct DetailPlayLivePage { | ||
| 41 | @State lastInputedChatComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的大家聊消息 | 42 | @State lastInputedChatComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的大家聊消息 |
| 42 | // 顶部状态栏高度 | 43 | // 顶部状态栏高度 |
| 43 | @Consume topSafeHeight: number | 44 | @Consume topSafeHeight: number |
| 45 | + chatRoomController: LiveDetailChatRoomController = new LiveDetailChatRoomController() | ||
| 44 | 46 | ||
| 45 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" | 47 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" |
| 46 | dialogToast: CustomDialogController = new CustomDialogController({ | 48 | dialogToast: CustomDialogController = new CustomDialogController({ |
| @@ -81,6 +83,8 @@ export struct DetailPlayLivePage { | @@ -81,6 +83,8 @@ export struct DetailPlayLivePage { | ||
| 81 | if(!await onlyWifiLoadVideo()){ | 83 | if(!await onlyWifiLoadVideo()){ |
| 82 | this.showToastTip(this.toastText) | 84 | this.showToastTip(this.toastText) |
| 83 | } | 85 | } |
| 86 | + | ||
| 87 | + this.chatRoomController.configDetail(this.contentDetailData) | ||
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | async aboutToDisappear() { | 90 | async aboutToDisappear() { |
| @@ -11,6 +11,7 @@ import { TrackConstants, TrackingButton } from 'wdTracking/Index'; | @@ -11,6 +11,7 @@ import { TrackConstants, TrackingButton } from 'wdTracking/Index'; | ||
| 11 | import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic'; | 11 | import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic'; |
| 12 | import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg'; | 12 | import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg'; |
| 13 | import { StringUtils } from 'wdKit'; | 13 | import { StringUtils } from 'wdKit'; |
| 14 | +import { LiveDetailChatRoomController } from '../im/LiveDetailChatRoomController'; | ||
| 14 | 15 | ||
| 15 | const storage = LocalStorage.getShared(); | 16 | const storage = LocalStorage.getShared(); |
| 16 | const TAG = 'DetailPlayVLivePage' | 17 | const TAG = 'DetailPlayVLivePage' |
| @@ -43,6 +44,7 @@ export struct DetailPlayVLivePage { | @@ -43,6 +44,7 @@ export struct DetailPlayVLivePage { | ||
| 43 | @State isPlayerError: boolean = false | 44 | @State isPlayerError: boolean = false |
| 44 | @State isCanplay: boolean = false | 45 | @State isCanplay: boolean = false |
| 45 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" | 46 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" |
| 47 | + chatRoomController: LiveDetailChatRoomController = new LiveDetailChatRoomController() | ||
| 46 | 48 | ||
| 47 | dialogToast: CustomDialogController = new CustomDialogController({ | 49 | dialogToast: CustomDialogController = new CustomDialogController({ |
| 48 | builder: CustomToast({ | 50 | builder: CustomToast({ |
| @@ -69,6 +71,7 @@ export struct DetailPlayVLivePage { | @@ -69,6 +71,7 @@ export struct DetailPlayVLivePage { | ||
| 69 | if(!await onlyWifiLoadVideo()){ | 71 | if(!await onlyWifiLoadVideo()){ |
| 70 | this.showToastTip(this.toastText) | 72 | this.showToastTip(this.toastText) |
| 71 | } | 73 | } |
| 74 | + this.chatRoomController.configDetail(this.contentDetailData) | ||
| 72 | } | 75 | } |
| 73 | 76 | ||
| 74 | aboutToDisappear(): void { | 77 | aboutToDisappear(): void { |
| @@ -69,7 +69,7 @@ export class WDAliListPlayerController { | @@ -69,7 +69,7 @@ export class WDAliListPlayerController { | ||
| 69 | 69 | ||
| 70 | constructor() { | 70 | constructor() { |
| 71 | Logger.info(TAG, "初始化") | 71 | Logger.info(TAG, "初始化") |
| 72 | - initGlobalPlayerSettings() | 72 | + // initGlobalPlayerSettings() |
| 73 | this.initPromise = this.createAVPlayer(); | 73 | this.initPromise = this.createAVPlayer(); |
| 74 | } | 74 | } |
| 75 | 75 |
| @@ -70,7 +70,7 @@ export class WDAliPlayerController { | @@ -70,7 +70,7 @@ export class WDAliPlayerController { | ||
| 70 | 70 | ||
| 71 | constructor() { | 71 | constructor() { |
| 72 | Logger.info(TAG, "初始化") | 72 | Logger.info(TAG, "初始化") |
| 73 | - initGlobalPlayerSettings() | 73 | + // initGlobalPlayerSettings() |
| 74 | this.initPromise = this.createAVPlayer(); | 74 | this.initPromise = this.createAVPlayer(); |
| 75 | } | 75 | } |
| 76 | 76 |
| @@ -21,5 +21,6 @@ | @@ -21,5 +21,6 @@ | ||
| 21 | "wdTracking": "file:../../features/wdTracking", | 21 | "wdTracking": "file:../../features/wdTracking", |
| 22 | "wdPlayer": "file:../../features/wdPlayer", | 22 | "wdPlayer": "file:../../features/wdPlayer", |
| 23 | "wdShare": "file:../../features/wdShare", | 23 | "wdShare": "file:../../features/wdShare", |
| 24 | + "wdDetailPlayLive": "file:../../features/wdDetailPlayLive" | ||
| 24 | } | 25 | } |
| 25 | } | 26 | } |
| @@ -20,6 +20,8 @@ import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index' | @@ -20,6 +20,8 @@ import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index' | ||
| 20 | import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife' | 20 | import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife' |
| 21 | import { webview } from '@kit.ArkWeb' | 21 | import { webview } from '@kit.ArkWeb' |
| 22 | import { NewspaperWidgetCommon } from '../dailynewspaperwidget/common/NewspaperWidgetCommon' | 22 | import { NewspaperWidgetCommon } from '../dailynewspaperwidget/common/NewspaperWidgetCommon' |
| 23 | +import { LiveRoomManager } from 'wdDetailPlayLive/Index' | ||
| 24 | +import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSetting' | ||
| 23 | 25 | ||
| 24 | const TAG = "[StartupManager]" | 26 | const TAG = "[StartupManager]" |
| 25 | 27 | ||
| @@ -111,6 +113,8 @@ export class StartupManager { | @@ -111,6 +113,8 @@ export class StartupManager { | ||
| 111 | this.initLocation() | 113 | this.initLocation() |
| 112 | 114 | ||
| 113 | this.initAuthLogin() | 115 | this.initAuthLogin() |
| 116 | + | ||
| 117 | + this.initLiveChatRoom() | ||
| 114 | Logger.debug(TAG, "App 必要初始化完成") | 118 | Logger.debug(TAG, "App 必要初始化完成") |
| 115 | } | 119 | } |
| 116 | 120 | ||
| @@ -131,6 +135,8 @@ export class StartupManager { | @@ -131,6 +135,8 @@ export class StartupManager { | ||
| 131 | // 提前初始化webview | 135 | // 提前初始化webview |
| 132 | webview.WebviewController.initializeWebEngine() | 136 | webview.WebviewController.initializeWebEngine() |
| 133 | 137 | ||
| 138 | + initGlobalPlayerSettings(this.context!) | ||
| 139 | + | ||
| 134 | if (this.lastStartupWant && this.dealWithDeepLink(this.lastStartupWant)) { | 140 | if (this.lastStartupWant && this.dealWithDeepLink(this.lastStartupWant)) { |
| 135 | this.lastStartupWant = undefined | 141 | this.lastStartupWant = undefined |
| 136 | } | 142 | } |
| @@ -198,6 +204,12 @@ export class StartupManager { | @@ -198,6 +204,12 @@ export class StartupManager { | ||
| 198 | LoginModule.startup() | 204 | LoginModule.startup() |
| 199 | } | 205 | } |
| 200 | 206 | ||
| 207 | + private initLiveChatRoom() { | ||
| 208 | + LiveRoomManager.sharedManager().gotContextFunc = () => { | ||
| 209 | + return StartupManager.sharedInstance().context! | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 201 | private initThirdPlatformSDK() { | 213 | private initThirdPlatformSDK() { |
| 202 | 214 | ||
| 203 | } | 215 | } |
-
Please register or login to post a comment