From d3c5ee75a4c47f136f315a61bc80e604d01881c3 Mon Sep 17 00:00:00 2001 From: bang9 Date: Fri, 1 Nov 2024 14:33:57 +0900 Subject: [PATCH] chore: support regional base host for RQA --- apps/testing/src/utils/paramsBuilder.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/testing/src/utils/paramsBuilder.ts b/apps/testing/src/utils/paramsBuilder.ts index 66fab5531..ee910b040 100644 --- a/apps/testing/src/utils/paramsBuilder.ts +++ b/apps/testing/src/utils/paramsBuilder.ts @@ -6,8 +6,6 @@ export interface InitialParams { userId?: string; nickname?: string; accessToken?: string; - customApiHost?: string; - customWebSocketHost?: string; } interface ParamsAsProps { @@ -18,18 +16,24 @@ interface ParamsAsProps { allowProfileEdit: boolean; isMultipleFilesMessageEnabled: boolean; uikitOptions: UIKitOptions; + customApiHost?: string; + customWebSocketHost?: string; } export const useConfigParams = (initParams: InitialParams): ParamsAsProps => { const [searchParams] = useSearchParams(); + const { customApiHost = searchParams.get('customApiHost'), customWebSocketHost = searchParams.get('customWebSocketHost') } = getHostBy( + searchParams.get('region'), + ); + const response = { appId: searchParams.get('appId') || initParams.appId, userId: searchParams.get('userId') || initParams.userId, nickname: searchParams.get('nickname') || initParams.nickname || initParams.userId, accessToken: searchParams.get('accessToken') || initParams.accessToken, - customApiHost: searchParams.get('customApiHost') || initParams.customApiHost, - customWebSocketHost: searchParams.get('customWebSocketHost') || initParams.customWebSocketHost, + customApiHost, + customWebSocketHost, allowProfileEdit: parseValue(searchParams.get('enableProfileEdit')) ?? true, isMultipleFilesMessageEnabled: parseValue(searchParams.get('enableMultipleFilesMessage')) ?? true, enableLegacyChannelModules: parseValue(searchParams.get('enableLegacyChannelModules')) ?? false, @@ -70,6 +74,17 @@ export const useConfigParams = (initParams: InitialParams): ParamsAsProps => { return response; }; +function getHostBy(region?: string | null) { + if (region?.startsWith('no')) { + return { + customApiHost: `https://api-${region}.sendbirdtest.com`, + customWebSocketHost: `wss://ws-${region}.sendbirdtest.com`, + }; + } + + return { customApiHost: undefined, customWebSocketHost: undefined }; +} + function parseValue(value?: string | null) { if (!value) return value; if (value.toLowerCase().match(/true/)) {