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; + } +}