import {getServers} from "./icesettings.js";

export async function getServerConfig() {
  const protocolEndPoint = location.origin + '/config';
  const createResponse = await fetch(protocolEndPoint);
  return await createResponse.json();
}

export function getRTCConfiguration() {
  let config = {};
  config.sdpSemantics = 'unified-plan';
  config.iceServers = getServers();

  // 添加音频处理选项，增强回声消除
  config.mediaConstraints = {
    audio: {
      echoCancellation: true,
      noiseSuppression: true,
      autoGainControl: true,
      highpassFilter: true,
      typingNoiseDetection: true
    }
  };

  // 添加WebRTC音频处理选项
  config.rtcConfiguration = {
    'googEchoCancellation': true,
    'googEchoCancellation2': true,
    'googNoiseSuppression': true,
    'googNoiseSuppression2': true,
    'googAutoGainControl': true,
    'googAutoGainControl2': true,
    'googHighpassFilter': true,
    'googTypingNoiseDetection': true
  };

  return config;
}
