Browse Source
feat(rtc): 添加RTC频道详情和座位用户信息模型
feat(rtc): 添加RTC频道详情和座位用户信息模型
- 新增RtcChannelDetail类用于表示RTC频道详情 - 新增RtcSeatUserInfo类用于表示座位上的用户信息 - 实现fromJson和toJson方法支持序列化和反序列化 - 支持解析座位用户的各种属性如用户ID、昵称、头像等 - 添加_bool解析函数以处理不同类型的布尔值转换 - 为座位用户信息添加可选的UID字段 - 支持解析主播、男性、女性座位信息ios
1 changed files with 111 additions and 0 deletions
Split View
Diff Options
@ -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<String, dynamic> json) { |
|||
return RtcChannelDetail( |
|||
channelId: json['channelId']?.toString() ?? '', |
|||
anchorInfo: _parseSeatInfo(json['anchorInfo']), |
|||
maleInfo: _parseSeatInfo(json['maleInfo']), |
|||
femaleInfo: _parseSeatInfo(json['femaleInfo']), |
|||
); |
|||
} |
|||
|
|||
Map<String, dynamic> toJson() { |
|||
return { |
|||
'channelId': channelId, |
|||
'anchorInfo': anchorInfo?.toJson(), |
|||
'maleInfo': maleInfo?.toJson(), |
|||
'femaleInfo': femaleInfo?.toJson(), |
|||
}; |
|||
} |
|||
|
|||
static RtcSeatUserInfo? _parseSeatInfo(dynamic value) { |
|||
if (value is Map<String, dynamic>) { |
|||
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<String, dynamic> 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<String, dynamic> 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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save