diff --git a/nacos_config/rc-service-external/application.yml b/nacos_config/rc-service-external/application.yml index 199f98c0..e9a80763 100644 --- a/nacos_config/rc-service-external/application.yml +++ b/nacos_config/rc-service-external/application.yml @@ -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} diff --git a/rc-service/rc-service-external/external-infrastructure/src/main/java/com/red/circle/external/infra/config/TencentTrtcClientRegionConfiguration.java b/rc-service/rc-service-external/external-infrastructure/src/main/java/com/red/circle/external/infra/config/TencentTrtcClientRegionConfiguration.java new file mode 100644 index 00000000..4a6a9e01 --- /dev/null +++ b/rc-service/rc-service-external/external-infrastructure/src/main/java/com/red/circle/external/infra/config/TencentTrtcClientRegionConfiguration.java @@ -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); + } +}