@@ -6,8 +6,6 @@ export interface InitialParams {
66 userId ?: string ;
77 nickname ?: string ;
88 accessToken ?: string ;
9- customApiHost ?: string ;
10- customWebSocketHost ?: string ;
119}
1210
1311interface ParamsAsProps {
@@ -18,18 +16,24 @@ interface ParamsAsProps {
1816 allowProfileEdit : boolean ;
1917 isMultipleFilesMessageEnabled : boolean ;
2018 uikitOptions : UIKitOptions ;
19+ customApiHost ?: string ;
20+ customWebSocketHost ?: string ;
2121}
2222
2323export const useConfigParams = ( initParams : InitialParams ) : ParamsAsProps => {
2424 const [ searchParams ] = useSearchParams ( ) ;
2525
26+ const { customApiHost = searchParams . get ( 'customApiHost' ) , customWebSocketHost = searchParams . get ( 'customWebSocketHost' ) } = getHostBy (
27+ searchParams . get ( 'region' ) ,
28+ ) ;
29+
2630 const response = {
2731 appId : searchParams . get ( 'appId' ) || initParams . appId ,
2832 userId : searchParams . get ( 'userId' ) || initParams . userId ,
2933 nickname : searchParams . get ( 'nickname' ) || initParams . nickname || initParams . userId ,
3034 accessToken : searchParams . get ( 'accessToken' ) || initParams . accessToken ,
31- customApiHost : searchParams . get ( 'customApiHost' ) || initParams . customApiHost ,
32- customWebSocketHost : searchParams . get ( 'customWebSocketHost' ) || initParams . customWebSocketHost ,
35+ customApiHost,
36+ customWebSocketHost,
3337 allowProfileEdit : parseValue ( searchParams . get ( 'enableProfileEdit' ) ) ?? true ,
3438 isMultipleFilesMessageEnabled : parseValue ( searchParams . get ( 'enableMultipleFilesMessage' ) ) ?? true ,
3539 enableLegacyChannelModules : parseValue ( searchParams . get ( 'enableLegacyChannelModules' ) ) ?? false ,
@@ -70,6 +74,17 @@ export const useConfigParams = (initParams: InitialParams): ParamsAsProps => {
7074 return response ;
7175} ;
7276
77+ function getHostBy ( region ?: string | null ) {
78+ if ( region ?. startsWith ( 'no' ) ) {
79+ return {
80+ customApiHost : `https://api-${ region } .sendbirdtest.com` ,
81+ customWebSocketHost : `wss://ws-${ region } .sendbirdtest.com` ,
82+ } ;
83+ }
84+
85+ return { customApiHost : undefined , customWebSocketHost : undefined } ;
86+ }
87+
7388function parseValue ( value ?: string | null ) {
7489 if ( ! value ) return value ;
7590 if ( value . toLowerCase ( ) . match ( / t r u e / ) ) {
0 commit comments