Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/index_d_ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
declare module "SendbirdUIKitGlobal" {
import type React from 'react';
import type SendbirdChat from '@sendbird/chat';
import { GroupChannelModule, ModuleNamespaces, OpenChannelModule } from '@sendbird/chat/lib/__definition';
import { GroupChannelModule, ModuleNamespaces, OpenChannelModule, SendbirdChatParams, Module } from '@sendbird/chat/lib/__definition';
import { SBUConfig } from '@sendbird/uikit-tools';
import type {
SendbirdError,
Expand Down Expand Up @@ -113,6 +113,7 @@ declare module "SendbirdUIKitGlobal" {
isTypingIndicatorEnabledOnChannelList?: boolean;
isMessageReceiptStatusEnabledOnChannelList?: boolean;
uikitOptions?: UIKitOptions;
sdkInitParams?: SendbirdChatParams<Module[]>;
}

export type Logger = {
Expand Down Expand Up @@ -292,6 +293,7 @@ declare module "SendbirdUIKitGlobal" {
isTypingIndicatorEnabledOnChannelList?: boolean;
isMessageReceiptStatusEnabledOnChannelList?: boolean;
uikitOptions?: UIKitOptions;
sdkInitParams?: SendbirdChatParams<Module[]>;
}

export interface SendBirdStateConfig {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Sendbird.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { useMarkAsDeliveredScheduler } from './hooks/useMarkAsDeliveredScheduler
import { getCaseResolvedReplyType, getCaseResolvedThreadReplySelectType } from './utils/resolvedReplyType';
import { useUnmount } from '../hooks/useUnmount';
import { disconnectSdk } from './hooks/useConnect/disconnectSdk';
import { UIKitOptions, CommonUIKitConfigProps } from './types';
import { UIKitOptions, CommonUIKitConfigProps, SendbirdChatInitParams } from './types';

export type UserListQueryType = {
hasNext?: boolean;
Expand Down Expand Up @@ -87,6 +87,7 @@ export interface SendbirdProviderProps extends CommonUIKitConfigProps {
onUserProfileMessage?: () => void;
uikitOptions?: UIKitOptions;
isUserIdUsedForNickname?: boolean;
sdkInitParams?: SendbirdChatInitParams;
}

function Sendbird(props: SendbirdProviderProps) {
Expand Down Expand Up @@ -148,6 +149,7 @@ const SendbirdSDK = ({
onUserProfileMessage = null,
breakpoint = false,
isUserIdUsedForNickname = true,
sdkInitParams,
}: SendbirdProviderProps): React.ReactElement => {
const {
logLevel = '',
Expand Down Expand Up @@ -177,6 +179,7 @@ const SendbirdSDK = ({
configureSession,
customApiHost,
customWebSocketHost,
sdkInitParams,
sdk,
sdkDispatcher,
userDispatcher,
Expand Down
19 changes: 19 additions & 0 deletions src/lib/hooks/useConnect/__test__/setupConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,23 @@ describe('useConnect/setupConnection/setUpParams', () => {
});
expect(newSdk).toEqual(mockSdk);
});

it('should call init with sdkInitParams', async () => {
const setUpConnectionProps = generateSetUpConnectionParams();
const { appId, sdkInitParams } = setUpConnectionProps;
const newSdk = setUpParams({ appId, sdkInitParams });
// @ts-ignore
expect(require('@sendbird/chat').init).toBeCalledWith({
appId,
newInstance: true,
modules: [
// @ts-ignore
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
// @ts-ignore
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
],
sdkInitParams,
});
expect(newSdk).toEqual(mockSdk);
});
});
2 changes: 2 additions & 0 deletions src/lib/hooks/useConnect/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function connect({
profileUrl,
accessToken,
sdk,
sdkInitParams,
}: ConnectTypes): Promise<void> {
await disconnectSdk({
logger,
Expand All @@ -36,5 +37,6 @@ export async function connect({
nickname,
profileUrl,
accessToken,
sdkInitParams,
});
}
3 changes: 3 additions & 0 deletions src/lib/hooks/useConnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function useConnect(triggerTypes: TriggerTypes, staticTypes: Stat
sdkDispatcher,
userDispatcher,
initDashboardConfigs,
sdkInitParams,
} = staticTypes;
logger?.info?.('SendbirdProvider | useConnect', { ...triggerTypes, ...staticTypes });

Expand All @@ -37,6 +38,7 @@ export default function useConnect(triggerTypes: TriggerTypes, staticTypes: Stat
userDispatcher,
initDashboardConfigs,
isUserIdUsedForNickname,
sdkInitParams,
});
} catch (error) {
logger?.error?.('SendbirdProvider | useConnect/useEffect', error);
Expand All @@ -61,6 +63,7 @@ export default function useConnect(triggerTypes: TriggerTypes, staticTypes: Stat
userDispatcher,
initDashboardConfigs,
isUserIdUsedForNickname,
sdkInitParams,
});
} catch (error) {
logger?.error?.('SendbirdProvider | useConnect/reconnect/useCallback', error);
Expand Down
6 changes: 6 additions & 0 deletions src/lib/hooks/useConnect/setupConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { USER_ACTIONS } from '../../dux/user/actionTypes';
import { isTextuallyNull } from '../../../utils';

import { SetupConnectionTypes } from './types';
import { SendbirdChatInitParams } from '../../types';

const APP_VERSION_STRING = '__react_dev_mode__';

Expand All @@ -25,10 +26,12 @@ export function setUpParams({
appId,
customApiHost,
customWebSocketHost,
sdkInitParams,
}: {
appId: string;
customApiHost?: string;
customWebSocketHost?: string;
sdkInitParams?: SendbirdChatInitParams;
}): SendbirdChat {
const params = {
appId,
Expand All @@ -37,6 +40,7 @@ export function setUpParams({
new OpenChannelModule(),
],
newInstance: true,
...sdkInitParams,
Copy link
Contributor

@sravan-s sravan-s Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined/null check necessary?
Also, probably we dont want to override appID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying spread from undefined happens nothing actually but always better to be explicit :) a2f0541

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm have crashed on me once before(dont remember the env)

};
if (customApiHost) {
params['customApiHost'] = customApiHost;
Expand Down Expand Up @@ -74,6 +78,7 @@ export async function setUpConnection({
profileUrl,
accessToken,
isUserIdUsedForNickname,
sdkInitParams,
}: SetupConnectionTypes): Promise<void> {
return new Promise((resolve, reject) => {
logger?.info?.('SendbirdProvider | useConnect/setupConnection/init', { userId, appId });
Expand All @@ -84,6 +89,7 @@ export async function setUpConnection({
appId,
customApiHost,
customWebSocketHost,
sdkInitParams,
});

if (configureSession && typeof configureSession === 'function') {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/hooks/useConnect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { UserActionTypes } from '../../dux/user/actionTypes';

import { Logger } from '../../SendbirdState';

import { SendbirdChatInitParams } from '../../types';

type SdkDispatcher = React.Dispatch<SdkActionTypes>;
type UserDispatcher = React.Dispatch<UserActionTypes>;

Expand All @@ -31,6 +33,7 @@ export type StaticTypes = {
sdkDispatcher: SdkDispatcher;
userDispatcher: UserDispatcher;
initDashboardConfigs: (sdk: SendbirdChat) => Promise<void>;
sdkInitParams?: SendbirdChatInitParams;
};

export type ConnectTypes = TriggerTypes & StaticTypes;
Expand Down
6 changes: 5 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type SendbirdChat from '@sendbird/chat';
import type { User } from '@sendbird/chat';
import type { User, SendbirdChatParams } from '@sendbird/chat';
import type {
GroupChannel,
GroupChannelCreateParams,
Expand Down Expand Up @@ -29,6 +29,8 @@ import { PartialDeep } from '../utils/typeHelpers/partialDeep';

import { SBUConfig } from '@sendbird/uikit-tools';

import { Module } from '@sendbird/chat/lib/__definition';

// note to SDK team:
// using enum inside .d.ts won’t work for jest, but const enum will work.
export const Role = {
Expand Down Expand Up @@ -244,3 +246,5 @@ export type UIKitOptions = PartialDeep<{
groupChannelSettings: SBUConfig['groupChannel']['setting'];
openChannel: SBUConfig['openChannel']['channel'];
}>;

export type SendbirdChatInitParams = SendbirdChatParams<Module[]>;
4 changes: 4 additions & 0 deletions src/modules/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function App(props) {
isMessageReceiptStatusEnabledOnChannelList,
uikitOptions,
isUserIdUsedForNickname,
sdkInitParams,
} = props;
const [currentChannel, setCurrentChannel] = useState(null);
return (
Expand Down Expand Up @@ -82,6 +83,7 @@ export default function App(props) {
showSearchIcon={showSearchIcon}
uikitOptions={uikitOptions}
isUserIdUsedForNickname={isUserIdUsedForNickname}
sdkInitParams={sdkInitParams}
>
<AppLayout
isReactionEnabled={isReactionEnabled}
Expand Down Expand Up @@ -154,6 +156,7 @@ App.propTypes = {
isTypingIndicatorEnabledOnChannelList: PropTypes.bool,
isMessageReceiptStatusEnabledOnChannelList: PropTypes.bool,
isUserIdUsedForNickname: PropTypes.bool,
sdkInitParams: PropTypes.shape({}),
};

App.defaultProps = {
Expand Down Expand Up @@ -194,4 +197,5 @@ App.defaultProps = {
isTypingIndicatorEnabledOnChannelList: undefined,
isMessageReceiptStatusEnabledOnChannelList: undefined,
isUserIdUsedForNickname: true,
sdkInitParams: undefined,
};
2 changes: 2 additions & 0 deletions src/modules/App/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UserListQuery,
RenderUserProfileProps,
SendBirdProviderConfig,
SendbirdChatInitParams,
} from '../../types';

export interface AppLayoutProps {
Expand Down Expand Up @@ -75,4 +76,5 @@ export default interface AppProps {
disableAutoSelect?: boolean;
isTypingIndicatorEnabledOnChannelList?: boolean;
isMessageReceiptStatusEnabledOnChannelList?: boolean;
sdkInitParams?: SendbirdChatInitParams;
}