You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do I handle initialization and connection when using Sendbird Live and Sendbird UIKit together?
Guide & Snippet
Live uses the term authenticate and UIKit uses the term connect, but I will use the term connect in the following discussion.
When using Sendbird Live with Sendbird UIKit, how to initialize both is important.
Both Live connect and UIKit connect use the same connection internally, the connection state is shared.
After receiving the onInitSucceed callback from the SendbirdLive.init and SendbirdUIKit.init function, you should start UIKit and Live contents.
For initialization, we recommend to invoke SendbirdLive.init and SendbirdUIKit.init in the Application class.
The logic below is a custom snippet with a simple example.
importandroid.app.Applicationimportandroidx.lifecycle.MutableLiveDataimportcom.sendbird.android.exception.SendbirdExceptionimportcom.sendbird.live.AuthenticateParamsimportcom.sendbird.live.InitParamsimportcom.sendbird.live.SendbirdLiveimportcom.sendbird.live.handler.InitResultHandlerimportcom.sendbird.uikit.SendbirdUIKitimportcom.sendbird.uikit.adapter.SendbirdUIKitAdapterimportcom.sendbird.uikit.interfaces.UserInfovalAPP_ID="YOUR_APP_ID"valUSER_ID="YOUR_USER_ID"valUSER_NICKNAME="YOUR_USER_NICKNAME"enumclassInitState {
/** * Indicates the migrating state.*/MIGRATING,
/** * Indicates the failed state.*/FAILED,
/** * Indicates the succeeded state.*/SUCCEED,
/** * Indicates nothing is set.*/NONE,
}
classBaseApplication : Application() {
internalval initState =MutableLiveData(InitState.NONE)
overridefunonCreate() {
super.onCreate()
val params =InitParams(APP_ID, applicationContext)
SendbirdLive.init(params, object:InitResultHandler {
overridefunonInitFailed(e: com.sendbird.webrtc.SendbirdException) {}
overridefunonInitSucceed() {
val params =AuthenticateParams(USER_ID, null)
SendbirdLive.authenticate(params) { user, e ->if (e !=null) {
//handle errorreturn@authenticate
}
SendbirdUIKit.init(object:SendbirdUIKitAdapter {
overridefungetAppId(): String {
returnAPP_ID// Specify your Sendbird application ID.
}
overridefungetAccessToken(): String {
return""// Specify your user's access token.
}
overridefungetUserInfo(): UserInfo {
returnobject:UserInfo {
overridefungetUserId(): String {
returnUSER_ID// Use the ID of a user you've created on the dashboard.
}
overridefungetNickname(): String {
returnUSER_NICKNAME// Specify your user nickname. Optional.
}
overridefungetProfileUrl(): String {
return""
}
}
}
overridefungetInitResultHandler(): com.sendbird.android.handler.InitResultHandler {
returnobject: com.sendbird.android.handler.InitResultHandler {
overridefunonMigrationStarted() {
// DB migration has started.
}
overridefunonInitFailed(e:SendbirdException) {
TODO("Not yet implemented")
}
overridefunonInitSucceed() {
// If DB migration is successful, this method is called and you can proceed to the next step.
initState.value =InitState.SUCCEED
}
}
}
}, this@BaseApplication)
}
}
overridefunonMigrationStarted() {}
})
}
}
You should set the BaseApplication class in the AndroidManifest.xml file.
In your activity or your screen, you can observe the MutableLiveData<InitState> initState value and proceed to the next screen when the initialization is successful.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
Guide & Snippet
onInitSucceed
callback from theSendbirdLive.init
andSendbirdUIKit.init
function, you should start UIKit and Live contents.SendbirdLive.init
andSendbirdUIKit.init
in theApplication
class.MutableLiveData<InitState> initState
value and proceed to the next screen when the initialization is successful.Reference
Beta Was this translation helpful? Give feedback.
All reactions