From 772d8d732df96021f224ff0d9c3f75f4d0a18cb5 Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Sun, 23 Nov 2025 08:34:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(rtc):=20=E6=B7=BB=E5=8A=A0RTC=E9=A2=91?= =?UTF-8?q?=E9=81=93=E8=AF=A6=E6=83=85=E5=92=8C=E5=BA=A7=E4=BD=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增RtcChannelDetail类用于表示RTC频道详情 - 新增RtcSeatUserInfo类用于表示座位上的用户信息 - 实现fromJson和toJson方法支持序列化和反序列化 - 支持解析座位用户的各种属性如用户ID、昵称、头像等 - 添加_bool解析函数以处理不同类型的布尔值转换 - 为座位用户信息添加可选的UID字段 - 支持解析主播、男性、女性座位信息 --- lib/model/rtc/rtc_channel_detail.dart | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 lib/model/rtc/rtc_channel_detail.dart diff --git a/lib/model/rtc/rtc_channel_detail.dart b/lib/model/rtc/rtc_channel_detail.dart new file mode 100644 index 0000000..f3c4800 --- /dev/null +++ b/lib/model/rtc/rtc_channel_detail.dart @@ -0,0 +1,111 @@ +class RtcChannelDetail { + final String channelId; + final RtcSeatUserInfo? anchorInfo; + final RtcSeatUserInfo? maleInfo; + final RtcSeatUserInfo? femaleInfo; + + const RtcChannelDetail({ + required this.channelId, + this.anchorInfo, + this.maleInfo, + this.femaleInfo, + }); + + factory RtcChannelDetail.fromJson(Map json) { + return RtcChannelDetail( + channelId: json['channelId']?.toString() ?? '', + anchorInfo: _parseSeatInfo(json['anchorInfo']), + maleInfo: _parseSeatInfo(json['maleInfo']), + femaleInfo: _parseSeatInfo(json['femaleInfo']), + ); + } + + Map toJson() { + return { + 'channelId': channelId, + 'anchorInfo': anchorInfo?.toJson(), + 'maleInfo': maleInfo?.toJson(), + 'femaleInfo': femaleInfo?.toJson(), + }; + } + + static RtcSeatUserInfo? _parseSeatInfo(dynamic value) { + if (value is Map) { + return RtcSeatUserInfo.fromJson(value); + } + return null; + } +} + +class RtcSeatUserInfo { + final String miId; + final String userId; + final String nickName; + final String profilePhoto; + final int genderCode; + final int seatNumber; + final bool isFriend; + final bool isMicrophoneOn; + final bool isVideoOn; + final int? uid; + + const RtcSeatUserInfo({ + required this.miId, + required this.userId, + required this.nickName, + required this.profilePhoto, + required this.genderCode, + required this.seatNumber, + required this.isFriend, + required this.isMicrophoneOn, + required this.isVideoOn, + this.uid, + }); + + factory RtcSeatUserInfo.fromJson(Map json) { + return RtcSeatUserInfo( + miId: json['miId']?.toString() ?? '', + userId: json['userId']?.toString() ?? '', + nickName: json['nickName']?.toString() ?? '', + profilePhoto: json['profilePhoto']?.toString() ?? '', + genderCode: json['genderCode'] is int + ? json['genderCode'] as int + : int.tryParse(json['genderCode']?.toString() ?? '0') ?? 0, + seatNumber: json['seatNumber'] is int + ? json['seatNumber'] as int + : int.tryParse(json['seatNumber']?.toString() ?? '0') ?? 0, + isFriend: _parseBool(json['isFriend']), + isMicrophoneOn: _parseBool(json['isMicrophoneOn']), + isVideoOn: _parseBool(json['isVideoOn']), + uid: json['uid'] is int + ? json['uid'] as int + : int.tryParse(json['uid']?.toString() ?? ''), + ); + } + + Map toJson() { + return { + 'miId': miId, + 'userId': userId, + 'nickName': nickName, + 'profilePhoto': profilePhoto, + 'genderCode': genderCode, + 'seatNumber': seatNumber, + 'isFriend': isFriend, + 'isMicrophoneOn': isMicrophoneOn, + 'isVideoOn': isVideoOn, + 'uid': uid, + }; + } + + static bool _parseBool(dynamic value) { + if (value is bool) return value; + if (value is num) return value != 0; + if (value is String) { + return value == '1' || + value.toLowerCase() == 'true' || + value.toLowerCase() == 'yes'; + } + return false; + } +}