refactor(agora): 코드 파악을 좀 더 쉽게 할 수 있도록 코드 재배치
This commit is contained in:
		@@ -35,6 +35,21 @@ class Agora(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private fun initAgoraEngine() {
 | 
					    private fun initAgoraEngine() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            initRtcEngine()
 | 
				
			||||||
 | 
					            initRtmClient()
 | 
				
			||||||
 | 
					        } catch (e: Exception) {
 | 
				
			||||||
 | 
					            e.printStackTrace()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun deInitAgoraEngine() {
 | 
				
			||||||
 | 
					        deInitRtcEngine()
 | 
				
			||||||
 | 
					        deInitRtmChannelAndClient()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // region RtcEngine
 | 
				
			||||||
 | 
					    @Throws(Exception::class)
 | 
				
			||||||
 | 
					    private fun initRtcEngine() {
 | 
				
			||||||
        rtcEngine = RtcEngine.create(
 | 
					        rtcEngine = RtcEngine.create(
 | 
				
			||||||
            context,
 | 
					            context,
 | 
				
			||||||
            BuildConfig.AGORA_APP_ID,
 | 
					            BuildConfig.AGORA_APP_ID,
 | 
				
			||||||
@@ -48,49 +63,6 @@ class Agora(
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
        rtcEngine!!.enableAudio()
 | 
					        rtcEngine!!.enableAudio()
 | 
				
			||||||
        rtcEngine!!.enableAudioVolumeIndication(500, 3, true)
 | 
					        rtcEngine!!.enableAudioVolumeIndication(500, 3, true)
 | 
				
			||||||
 | 
					 | 
				
			||||||
            rtmClient = RtmClient.createInstance(
 | 
					 | 
				
			||||||
                context,
 | 
					 | 
				
			||||||
                BuildConfig.AGORA_APP_ID,
 | 
					 | 
				
			||||||
                rtmClientListener
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
        } catch (e: Exception) {
 | 
					 | 
				
			||||||
            e.printStackTrace()
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fun deInitAgoraEngine() {
 | 
					 | 
				
			||||||
        if (rtcEngine != null) {
 | 
					 | 
				
			||||||
            rtcEngine!!.leaveChannel()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            thread {
 | 
					 | 
				
			||||||
                RtcEngine.destroy()
 | 
					 | 
				
			||||||
                rtcEngine = null
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        rtmChannel?.leave(null)
 | 
					 | 
				
			||||||
        rtmChannel?.release()
 | 
					 | 
				
			||||||
        rtmClient?.logout(null)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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 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