Skip to content

Commit 754f7f5

Browse files
sravan-sSravan S
and
Sravan S
authored
feat: Add session handler interface (#157)
Interface: ``` // its recommended to memoize configureSession function const memoizedConfigureSession = (sb) => { const sessionHandler = new sb.SessionHandler(); sessionHandler.onSessionTokenRequired = (onSuccess, onError) => { }; sessionHandler.onSessionClosed = () => { }; sessionHandler.onSessionRefreshed = () => { }; sessionHandler.onSessionError = err => { }; return sessionHandler; }; <SendbirdProvider configureSession={memoizedConfigureSession} /> ``` see: https://sendbird.com/docs/chat/v3/javascript/guides/authentication Fixes: https://sendbird.atlassian.net/browse/UIKIT-1796 Co-authored-by: Sravan S <[email protected]>
1 parent 3ba2194 commit 754f7f5

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

scripts/index_d_ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface SendBirdProviderProps {
5353
userId: string;
5454
appId: string;
5555
accessToken?: string;
56+
configureSession?: (sdk: SendBird.SendBirdInstance) => SendBird.SessionHandler;
5657
children?: React.ReactNode;
5758
theme?: 'light' | 'dark';
5859
nickname?: string;

src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface SendBirdProviderProps {
5959
userId: string;
6060
appId: string;
6161
accessToken?: string;
62+
configureSession?: (sdk: SendBird.SendBirdInstance) => SendBird.SessionHandler;
6263
children?: React.ReactNode;
6364
theme?: 'light' | 'dark';
6465
nickname?: string;

src/lib/Sendbird.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function Sendbird(props) {
2828
dateLocale,
2929
appId,
3030
accessToken,
31+
configureSession,
3132
children,
3233
disableUserProfile,
3334
renderUserProfile,
@@ -71,6 +72,7 @@ export default function Sendbird(props) {
7172
sdkStore,
7273
nickname,
7374
profileUrl,
75+
configureSession,
7476
sdk: sdkStore.sdk,
7577
logger,
7678
}, {
@@ -192,6 +194,7 @@ Sendbird.propTypes = {
192194
userId: PropTypes.string.isRequired,
193195
appId: PropTypes.string.isRequired,
194196
accessToken: PropTypes.string,
197+
configureSession: PropTypes.func,
195198
children: PropTypes.oneOfType([
196199
PropTypes.element,
197200
PropTypes.arrayOf(PropTypes.element),
@@ -241,6 +244,7 @@ Sendbird.propTypes = {
241244

242245
Sendbird.defaultProps = {
243246
accessToken: '',
247+
configureSession: null,
244248
theme: 'light',
245249
nickname: '',
246250
dateLocale: null,

src/lib/dux/sdk/thunks.js

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const handleConnection = ({
4040
nickname,
4141
profileUrl,
4242
accessToken,
43+
configureSession,
4344
sdk,
4445
logger,
4546
}, dispatchers) => {
@@ -54,9 +55,13 @@ export const handleConnection = ({
5455
logger,
5556
onDisconnect: () => {
5657
logger.info('Setup connection');
58+
let sessionHandler = null;
5759
sdkDispatcher({ type: SET_SDK_LOADING, payload: true });
5860
if (userId && appId) {
5961
const newSdk = new Sb({ appId });
62+
if (configureSession && typeof configureSession === 'function') {
63+
sessionHandler = configureSession(newSdk);
64+
}
6065
// to check if code is released version from rollup and *not from storybook*
6166
// see rollup config file
6267
if (IS_ROLLUP === IS_ROLLUP_REPLACE) {
@@ -89,6 +94,9 @@ export const handleConnection = ({
8994
.then((res) => connectCbSucess(res))
9095
.catch((err) => connectCbError(err));
9196
} else {
97+
if (sessionHandler) {
98+
newSdk.setSessionHandler(sessionHandler);
99+
}
92100
newSdk.connect(userId)
93101
.then((res) => connectCbSucess(res))
94102
.catch((err) => connectCbError(err));

0 commit comments

Comments
 (0)