open-webrtc-toolkit / owt-client-native

Open WebRTC Toolkit client SDK for native Windows/Linux/iOS applications.
https://01.org/open-webrtc-toolkit
Apache License 2.0
385 stars 180 forks source link

Add kType for RTCStats to fix GetStatsOfType build error. #642

Open JinChengShi opened 1 year ago

jianjunz commented 1 year ago

RTCStats has a field type, why we need another type in its derived classes.

JinChengShi commented 1 year ago

RTCStats has a field type, why we need another type in its derived classes.

Because it will cause follow code build error:

  const T* GetAs(const std::string& id) const {
    const RTCStats* stats = Get(id);
    if (!stats || stats->type != T::kType) {
      return nullptr;
    }
    return &stats->cast_to<const T>();
  }
  std::vector<const T*> GetStatsOfType() const {
    std::vector<const T*> stats_of_type;
    for (const RTCStats& stats : *this) {
      if (stats.type == T::kType)
        stats_of_type.push_back(&stats.cast_to<const T>());
    }
    return stats_of_type;
  }

when called GetStatsOfType in app: std::vector<const RTCOutboundRTPStreamStats*> outboundRTPStreamStats = status->GetStatsOfType<RTCOutboundRTPStreamStats>();