fix external trtc region config

This commit is contained in:
hy001 2026-05-12 13:44:13 +08:00
parent f735b0a9a3
commit 41305adb9d
2 changed files with 39 additions and 0 deletions

View File

@ -40,6 +40,7 @@ red-circle:
secretId: ${LIKEI_TRTC_SECRET_ID}
secretKey: ${LIKEI_TRTC_SECRET_KEY}
endpoint: ${LIKEI_TRTC_ENDPOINT}
region: ${LIKEI_TRTC_REGION:ap-singapore}
sdkAppId: ${LIKEI_TRTC_SDK_APP_ID}
tencet-im:
appId: ${LIKEI_IM_APP_ID}

View File

@ -0,0 +1,38 @@
package com.red.circle.external.infra.config;
import com.red.circle.component.instant.msg.InstantMessageProperties;
import com.red.circle.component.instant.msg.tencet.props.TrtcTencetProperties;
import com.red.circle.component.instant.msg.tencet.service.endpoint.api.trtc.HyTrtcClient;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
@Configuration
public class TencentTrtcClientRegionConfiguration {
private static final String DEFAULT_TRTC_REGION = "ap-singapore";
@Bean
@Primary
public HyTrtcClient regionAwareHyTrtcClient(
InstantMessageProperties instantMessageProperties,
@Value("${red-circle.instant-message.tencet-trtc.region:" + DEFAULT_TRTC_REGION + "}")
String region) {
TrtcTencetProperties trtcProperties = instantMessageProperties.getTencetTrtc();
Credential credential = new Credential(
trtcProperties.getSecretId(),
trtcProperties.getSecretKey()
);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint(trtcProperties.getEndpoint());
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
String resolvedRegion = StringUtils.hasText(region) ? region.trim() : DEFAULT_TRTC_REGION;
return new HyTrtcClient(credential, resolvedRegion, clientProfile);
}
}