Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLNP-6072] useConnectionHandler #1291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/hooks/useConnectionHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import { useState } from 'react';
import { ConnectionHandler, ConnectionState } from '@sendbird/chat';
import useSendbirdStateContext from './useSendbirdStateContext'
import uuidv4 from '../utils/uuid';

Copy link
Collaborator

Choose a reason for hiding this comment

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

may need to export the ConnectionHandler from UIKit, here

export ConnectionHandler

https://github.com/sendbird/sendbird-uikit-react/pulls?q=is%3Apr+is%3Aclosed+export+Handlers+thorough
예전에 @sendbird/chat의 인터페이스를 그대로 사용하던 고객에게서 Invalid Parameter Error가 발생한다는 이슈 리포트가 있었습니다. 좀 오래 되어서, 잘 기억은 안나지만 아마도 chat-js와 uikit의 디펜던시로 가지고 있는 chat-js간의 버전이 달라서 발생했던 이슈로 기억합니다. 해당 이슈가 발생할 수 있을지 검토가 필요해 보입니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@chrisallo chrisallo Jan 3, 2025

Choose a reason for hiding this comment

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

ConnectionHandler의 경우에는 v4 초반부터 있었던 핸들러이고 변경 내용이 거의 없어서 괜찮지 않을까 싶긴 한데 그래도 안전빵으로 바꿔두었습니다.

export const useConnectionState = (): ConnectionState => {
const { stores } = useSendbirdStateContext();
const { sdkStore } = stores;
const { sdk } = sdkStore;

const [connectionState, setConnectionState] = useState(sdk.connectionState)
sdk.addConnectionHandler(uuidv4(), new ConnectionHandler({
onConnected: () => setConnectionState(ConnectionState.OPEN),
onDisconnected: () => setConnectionState(ConnectionState.CLOSED),
onReconnectStarted: () => setConnectionState(ConnectionState.CONNECTING),
onReconnectSucceeded: () => setConnectionState(ConnectionState.OPEN),
onReconnectFailed: () => setConnectionState(ConnectionState.CLOSED),
}))
return connectionState
}
chrisallo marked this conversation as resolved.
Show resolved Hide resolved