-
Notifications
You must be signed in to change notification settings - Fork 141
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
chrisallo
wants to merge
2
commits into
main
Choose a base branch
from
feat/clnp-6072
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
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
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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, herehttps://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간의 버전이 달라서 발생했던 이슈로 기억합니다. 해당 이슈가 발생할 수 있을지 검토가 필요해 보입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: https://github.com/sendbird/sendbird-uikit-react/tree/main/src/lib/handlers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConnectionHandler
의 경우에는 v4 초반부터 있었던 핸들러이고 변경 내용이 거의 없어서 괜찮지 않을까 싶긴 한데 그래도 안전빵으로 바꿔두었습니다.