refactor(agora): 코드 파악을 좀 더 쉽게 할 수 있도록 코드 재배치
This commit is contained in:
@@ -35,62 +35,34 @@ class Agora(
|
|||||||
|
|
||||||
private fun initAgoraEngine() {
|
private fun initAgoraEngine() {
|
||||||
try {
|
try {
|
||||||
rtcEngine = RtcEngine.create(
|
initRtcEngine()
|
||||||
context,
|
initRtmClient()
|
||||||
BuildConfig.AGORA_APP_ID,
|
|
||||||
rtcEventHandler
|
|
||||||
)
|
|
||||||
|
|
||||||
rtcEngine!!.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING)
|
|
||||||
rtcEngine!!.setAudioProfile(
|
|
||||||
Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO,
|
|
||||||
Constants.AUDIO_SCENARIO_GAME_STREAMING
|
|
||||||
)
|
|
||||||
rtcEngine!!.enableAudio()
|
|
||||||
rtcEngine!!.enableAudioVolumeIndication(500, 3, true)
|
|
||||||
|
|
||||||
rtmClient = RtmClient.createInstance(
|
|
||||||
context,
|
|
||||||
BuildConfig.AGORA_APP_ID,
|
|
||||||
rtmClientListener
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deInitAgoraEngine() {
|
fun deInitAgoraEngine() {
|
||||||
if (rtcEngine != null) {
|
deInitRtcEngine()
|
||||||
rtcEngine!!.leaveChannel()
|
deInitRtmChannelAndClient()
|
||||||
|
|
||||||
thread {
|
|
||||||
RtcEngine.destroy()
|
|
||||||
rtcEngine = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rtmChannel?.leave(null)
|
|
||||||
rtmChannel?.release()
|
|
||||||
rtmClient?.logout(null)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun inputChat(message: String) {
|
// region RtcEngine
|
||||||
val rtmMessage = rtmClient!!.createMessage()
|
@Throws(Exception::class)
|
||||||
rtmMessage.text = message
|
private fun initRtcEngine() {
|
||||||
|
rtcEngine = RtcEngine.create(
|
||||||
rtmChannel!!.sendMessage(
|
context,
|
||||||
rtmMessage,
|
BuildConfig.AGORA_APP_ID,
|
||||||
object : ResultCallback<Void?> {
|
rtcEventHandler
|
||||||
override fun onSuccess(p0: Void?) {
|
|
||||||
Logger.e("sendMessage - onSuccess")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(p0: ErrorInfo) {
|
|
||||||
Logger.e("sendMessage fail - ${p0.errorCode}")
|
|
||||||
Logger.e("sendMessage fail - ${p0.errorDescription}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rtcEngine!!.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING)
|
||||||
|
rtcEngine!!.setAudioProfile(
|
||||||
|
Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO,
|
||||||
|
Constants.AUDIO_SCENARIO_GAME_STREAMING
|
||||||
|
)
|
||||||
|
rtcEngine!!.enableAudio()
|
||||||
|
rtcEngine!!.enableAudioVolumeIndication(500, 3, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun joinRtcChannel(uid: Int, rtcToken: String, channelName: String) {
|
fun joinRtcChannel(uid: Int, rtcToken: String, channelName: String) {
|
||||||
@@ -102,6 +74,44 @@ class Agora(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setClientRole(role: Int) {
|
||||||
|
rtcEngine!!.setClientRole(role)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun muteLocalAudioStream(muted: Boolean) {
|
||||||
|
rtcEngine?.muteLocalAudioStream(muted)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun muteAllRemoteAudioStreams(mute: Boolean) {
|
||||||
|
rtcEngine?.muteAllRemoteAudioStreams(mute)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getConnectionState(): Int {
|
||||||
|
return rtcEngine!!.connectionState
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deInitRtcEngine() {
|
||||||
|
if (rtcEngine != null) {
|
||||||
|
rtcEngine!!.leaveChannel()
|
||||||
|
|
||||||
|
thread {
|
||||||
|
RtcEngine.destroy()
|
||||||
|
rtcEngine = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region RtmClient
|
||||||
|
@Throws(Exception::class)
|
||||||
|
private fun initRtmClient() {
|
||||||
|
rtmClient = RtmClient.createInstance(
|
||||||
|
context,
|
||||||
|
BuildConfig.AGORA_APP_ID,
|
||||||
|
rtmClientListener
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun createRtmChannelAndLogin(
|
fun createRtmChannelAndLogin(
|
||||||
uid: String,
|
uid: String,
|
||||||
rtmToken: String,
|
rtmToken: String,
|
||||||
@@ -134,6 +144,25 @@ class Agora(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun inputChat(message: String) {
|
||||||
|
val rtmMessage = rtmClient!!.createMessage()
|
||||||
|
rtmMessage.text = message
|
||||||
|
|
||||||
|
rtmChannel!!.sendMessage(
|
||||||
|
rtmMessage,
|
||||||
|
object : ResultCallback<Void?> {
|
||||||
|
override fun onSuccess(p0: Void?) {
|
||||||
|
Logger.e("sendMessage - onSuccess")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(p0: ErrorInfo) {
|
||||||
|
Logger.e("sendMessage fail - ${p0.errorCode}")
|
||||||
|
Logger.e("sendMessage fail - ${p0.errorDescription}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun sendRawMessageToGroup(
|
fun sendRawMessageToGroup(
|
||||||
rawMessage: ByteArray,
|
rawMessage: ByteArray,
|
||||||
onSuccess: (() -> Unit)? = null,
|
onSuccess: (() -> Unit)? = null,
|
||||||
@@ -158,18 +187,6 @@ class Agora(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setClientRole(role: Int) {
|
|
||||||
rtcEngine!!.setClientRole(role)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun muteLocalAudioStream(muted: Boolean) {
|
|
||||||
rtcEngine?.muteLocalAudioStream(muted)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun muteAllRemoteAudioStreams(mute: Boolean) {
|
|
||||||
rtcEngine?.muteAllRemoteAudioStreams(mute)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun sendRawMessageToPeer(
|
fun sendRawMessageToPeer(
|
||||||
receiverUid: String,
|
receiverUid: String,
|
||||||
requestType: LiveRoomRequestType? = null,
|
requestType: LiveRoomRequestType? = null,
|
||||||
@@ -200,7 +217,10 @@ class Agora(
|
|||||||
return rtmChannel == null
|
return rtmChannel == null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConnectionState(): Int {
|
fun deInitRtmChannelAndClient() {
|
||||||
return rtcEngine!!.connectionState
|
rtmChannel?.leave(null)
|
||||||
|
rtmChannel?.release()
|
||||||
|
rtmClient?.logout(null)
|
||||||
}
|
}
|
||||||
|
// endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.content.Context
|
|||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.text.TextUtils
|
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -21,11 +20,8 @@ import kr.co.vividnext.sodalive.R
|
|||||||
import kr.co.vividnext.sodalive.common.CustomTypefaceSpan
|
import kr.co.vividnext.sodalive.common.CustomTypefaceSpan
|
||||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||||
import kr.co.vividnext.sodalive.databinding.ItemLiveRoomChatBinding
|
import kr.co.vividnext.sodalive.databinding.ItemLiveRoomChatBinding
|
||||||
import kr.co.vividnext.sodalive.databinding.ItemLiveRoomDonationStatusChatBinding
|
|
||||||
import kr.co.vividnext.sodalive.databinding.ItemLiveRoomJoinChatBinding
|
import kr.co.vividnext.sodalive.databinding.ItemLiveRoomJoinChatBinding
|
||||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
|
||||||
import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationStatusResponse
|
|
||||||
|
|
||||||
enum class LiveRoomChatType {
|
enum class LiveRoomChatType {
|
||||||
@SerializedName("CHAT")
|
@SerializedName("CHAT")
|
||||||
|
|||||||
Reference in New Issue
Block a user