void DefaultSignalingClient::HandleSubAckFrame()

in chime-sdk-signaling-cpp/src/signaling/default_signaling_client.cc [523:556]


void DefaultSignalingClient::HandleSubAckFrame(const signal_sdk::SdkSubscribeAckFrame& subscribe_ack_frame) {
  if (!subscribe_ack_frame.has_sdp_answer()) {
    CHIME_LOG(LogLevel::kError, "Empty sdp offer received.")
    return;
  }

  const std::string& sdp_answer = subscribe_ack_frame.sdp_answer();
  CHIME_LOG(LogLevel::kDebug, "Received sdp offer: " + subscribeAckFrameDebugString(subscribe_ack_frame))

  std::vector<MediaSection> media_sections = SDPUtils::ParseSDP(subscribe_ack_frame.sdp_answer());

  int allocationInd = 0;
  // TODO @hokyungh: This is best try on mapping between local and mid.
  // It might be best if server also gives mid so that we don't have to manage this mapping
  for (const auto& media_section : media_sections) {
    if (allocationInd >= subscribe_ack_frame.allocations_size() ||
        allocationInd >= (local_audio_sources_.size() + local_video_sources_.size())) {
      break;
    }
    const signal_sdk::SdkStreamAllocation& allocation = subscribe_ack_frame.allocations()[allocationInd];
    if (local_audio_sources_.find(media_section.mid) != local_audio_sources_.end()) {
      local_audio_sources_[media_section.mid].group_id = allocation.group_id();
      local_audio_sources_[media_section.mid].stream_id = allocation.stream_id();
      allocationInd++;
    } else if (local_video_sources_.find(media_section.mid) != local_video_sources_.end()) {
      local_video_sources_[media_section.mid].group_id = allocation.group_id();
      local_video_sources_[media_section.mid].stream_id = allocation.stream_id();
      allocationInd++;
    }
  }

  NotifySignalingObserver(
      [&sdp_answer](SignalingClientObserver* observer) -> void { observer->OnRemoteDescriptionReceived(sdp_answer); });
}