TRTCScreenCaptureSourceInfo.fromJson constructor

TRTCScreenCaptureSourceInfo.fromJson(
  1. Map<String, dynamic> json
)

Parse the corresponding structure from Json

Implementation

factory TRTCScreenCaptureSourceInfo.fromJson(Map<String, dynamic> json) {
  Map<String, dynamic> thumbBGRAJson;
  thumbBGRAJson = (json['thumbBGRA'] as Map<Object?, Object?>).cast<String, dynamic>();

  Map<String, dynamic> iconBGRAJson;
  iconBGRAJson = (json['iconBGRA'] as Map<Object?, Object?>).cast<String, dynamic>();

  // 统一解析 sourceId 为 String 类型
  // Windows 可能传入 int/int64,macOS 传入 String
  String? sourceId;
  if (json['sourceId'] is String) {
    sourceId = json['sourceId'] as String;
  } else if (json['sourceId'] is int) {
    sourceId = (json['sourceId'] as int).toString();
  }

  return TRTCScreenCaptureSourceInfo(
    type: _fromInt(json['type']),
    sourceId: sourceId,
    sourceName: json['sourceName'],
    thumbBGRA: TRTCImageBuffer.fromJson(thumbBGRAJson),
    iconBGRA: TRTCImageBuffer.fromJson(iconBGRAJson),
    isMinimizeWindow: json['isMinimizeWindow'],
    isMainScreen: json['isMainScreen'],
    x: json['x'],
    y: json['y'],
    width: json['width'],
    height: json['height'],
  );
}