Note!
아래 모든 함수들은 모두 비동기 작업. 따라서, callback Handler를 달아서 하는게 좋다. 특히, channel 권장
fun init(initParams: InitParams, handler: InitResultHandler): UnitSendBird.clearCachedData 후 다시 init 호출SendbirdChat.init(
InitParams(APP_ID, applicationContext, useCaching = true),
object : InitResultHandler {
override fun onMigrationStarted() {
Log.i("Application", "Called when there's an migration in local cache.")
}
override fun onInitFailed(e: SendbirdException) {
when (e.code) {
SendbirdError.ERR_INITIALIZATION_CANCELED -> {
Log.i("Application", "Called when initialize failed for some reason such as empth APP_ID. Retry SendbirdChat.init() again with correct InitParams.")
}
SendbirdError.ERR_DATABASE_ERROR_ENCRYPTION -> {
Log.i("Application", "Called when initialize failed when InitParams.LocalCacheConfig.SqlcipherConfig is set but SqlCipher dependency is not set. Please add the dependency and try SendbirdChat.init again.")
}
else -> {
Log.i("Application", "Called when initialize failed. SDK will still operate properly as if useLocalCaching is set to false.")
}
}
}
override fun onInitSucceed() {
Log.i("Application", "Called when initialization is completed.")
}
}
)
fun connect(userId: String, authToken: String? = COMPILED_CODE, handler: ConnectHandler?): UnitSendbirdChat.connect(userId) { user, e ->
if (user != null) {
if (e != null) {
// Proceed in offline mode with the data stored in the local database.ConnectionHandler.onReconnectSucceeded().
} else {
// Proceed in online mode.
}
} else {
// Handle error.
}
}
무조건 init이 성공한 이후 불러야함.
OpenChannel.createChannel(OpenChannelCreateParams()) { channel, e ->
if (e != null) {
// Handle error.
}
// An open channel is successfully created.
}
OpenChannel.createChannel(OpenChannelCreateParams()) { channel, e ->
if (e != null) {
// Handle error.
}
// Call the instance method of the result object in the openChannel parameter
channel?.enter { e ->
if (e != null) {
// Handle error.
}
// The current user has successfully entered the open channel,
}
}
sendUserMessage 호출openChannel.sendUserMessage(UserMessageCreateParams(MESSAGE)) { message, e ->
if (e != null) {
// Handle error.
}
// The message has been successfully sent to the channel.
}
distinct = false : 유저 A,B,C가 기존 Channel이 아닌 새로운 Channel을 만들어도, 기존 Channel이 사용됨
super = true: 매우 많은 사용자를 참여시킬 수 있음.
- super가 true면 distinct 지원 X