fromJson static method

UserSessionStats? fromJson(
  1. dynamic value
)

Returns a new UserSessionStats instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static UserSessionStats? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "UserSessionStats[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "UserSessionStats[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return UserSessionStats(
      browser: mapValueOfType<String>(json, r'browser'),
      browserVersion: mapValueOfType<String>(json, r'browser_version'),
      currentIp: mapValueOfType<String>(json, r'current_ip'),
      currentSfu: mapValueOfType<String>(json, r'current_sfu'),
      deviceModel: mapValueOfType<String>(json, r'device_model'),
      deviceVersion: mapValueOfType<String>(json, r'device_version'),
      distanceToSfuKilometers: mapValueOfType<double>(json, r'distance_to_sfu_kilometers'),
      freezeDurationSeconds: mapValueOfType<int>(json, r'freeze_duration_seconds')!,
      geolocation: GeolocationResult.fromJson(json[r'geolocation']),
      jitter: TimeStats.fromJson(json[r'jitter']),
      latency: TimeStats.fromJson(json[r'latency']),
      maxFirPerSecond: mapValueOfType<double>(json, r'max_fir_per_second'),
      maxFreezeFraction: mapValueOfType<double>(json, r'max_freeze_fraction')!,
      maxFreezesDurationSeconds: mapValueOfType<int>(json, r'max_freezes_duration_seconds')!,
      maxFreezesPerSecond: mapValueOfType<double>(json, r'max_freezes_per_second'),
      maxNackPerSecond: mapValueOfType<double>(json, r'max_nack_per_second'),
      maxPliPerSecond: mapValueOfType<double>(json, r'max_pli_per_second'),
      maxPublishingVideoQuality: VideoQuality.fromJson(json[r'max_publishing_video_quality']),
      maxReceivingVideoQuality: VideoQuality.fromJson(json[r'max_receiving_video_quality']),
      os: mapValueOfType<String>(json, r'os'),
      osVersion: mapValueOfType<String>(json, r'os_version'),
      packetLossFraction: mapValueOfType<double>(json, r'packet_loss_fraction')!,
      pubSubHints: MediaPubSubHint.fromJson(json[r'pub_sub_hints']),
      publishedTracks: PublishedTrackInfo.listFromJson(json[r'published_tracks']),
      publisherAudioMos: MOSStats.fromJson(json[r'publisher_audio_mos']),
      publisherJitter: TimeStats.fromJson(json[r'publisher_jitter']),
      publisherLatency: TimeStats.fromJson(json[r'publisher_latency']),
      publisherNoiseCancellationSeconds: mapValueOfType<double>(json, r'publisher_noise_cancellation_seconds'),
      publisherPacketLossFraction: mapValueOfType<double>(json, r'publisher_packet_loss_fraction')!,
      publisherQualityLimitationFraction: mapValueOfType<double>(json, r'publisher_quality_limitation_fraction'),
      publisherVideoQualityLimitationDurationSeconds: mapCastOfType<String, double>(json, r'publisher_video_quality_limitation_duration_seconds') ?? const {},
      publishingAudioCodec: mapValueOfType<String>(json, r'publishing_audio_codec'),
      publishingDurationSeconds: mapValueOfType<int>(json, r'publishing_duration_seconds')!,
      publishingVideoCodec: mapValueOfType<String>(json, r'publishing_video_codec'),
      qualityScore: mapValueOfType<double>(json, r'quality_score')!,
      receivingAudioCodec: mapValueOfType<String>(json, r'receiving_audio_codec'),
      receivingDurationSeconds: mapValueOfType<int>(json, r'receiving_duration_seconds')!,
      receivingVideoCodec: mapValueOfType<String>(json, r'receiving_video_codec'),
      sdk: mapValueOfType<String>(json, r'sdk'),
      sdkVersion: mapValueOfType<String>(json, r'sdk_version'),
      sessionId: mapValueOfType<String>(json, r'session_id')!,
      subscriberAudioMos: MOSStats.fromJson(json[r'subscriber_audio_mos']),
      subscriberJitter: TimeStats.fromJson(json[r'subscriber_jitter']),
      subscriberLatency: TimeStats.fromJson(json[r'subscriber_latency']),
      subscriberVideoQualityThrottledDurationSeconds: mapValueOfType<double>(json, r'subscriber_video_quality_throttled_duration_seconds'),
      subsessions: Subsession.listFromJson(json[r'subsessions']),
      timeline: CallTimeline.fromJson(json[r'timeline']),
      totalPixelsIn: mapValueOfType<int>(json, r'total_pixels_in')!,
      totalPixelsOut: mapValueOfType<int>(json, r'total_pixels_out')!,
      truncated: mapValueOfType<bool>(json, r'truncated'),
      webrtcVersion: mapValueOfType<String>(json, r'webrtc_version'),
    );
  }
  return null;
}