Skip to content

Commit cd69522

Browse files
CYGCYG
authored andcommitted
[Android]update api reporter
1 parent 2c6e18f commit cd69522

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

KTVAPI/Android/lib_ktvapi/src/main/java/io/agora/ktvapi/APIReporter.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import io.agora.rtc2.RtcEngine
66
import org.json.JSONObject
77
import java.util.HashMap
88

9+
enum class APIType(val value: Int) {
10+
KTV(1), // K歌
11+
CALL(2), // 呼叫连麦
12+
BEAUTY(3), // 美颜
13+
VIDEO_LOADER(4), // 秒开秒切
14+
PK(5), // 团战
15+
VIRTUAL_SPACE(6), //
16+
SCREEN_SPACE(7), // 屏幕共享
17+
AUDIO_SCENARIO(8) // 音频
18+
}
19+
920
enum class ApiEventType(val value: Int) {
1021
API(0),
1122
COST(1),
@@ -27,12 +38,14 @@ object ApiCostEvent {
2738
}
2839

2940
class APIReporter(
30-
private val category: String,
41+
private val type: APIType,
42+
private val version: String,
3143
private val rtcEngine: RtcEngine
3244
) {
3345
private val tag = "APIReporter"
3446
private val messageId = "agora:scenarioAPI"
3547
private val durationEventStartMap = HashMap<String, Long>()
48+
private val category = "${type.value}_Android_$version"
3649

3750
init {
3851
configParameters()
@@ -53,23 +66,24 @@ class APIReporter(
5366
durationEventStartMap[name] = getCurrentTs()
5467
}
5568

56-
fun endDurationEvent(name: String) {
69+
fun endDurationEvent(name: String, ext: Map<String, Any>) {
5770
Log.d(tag, "endDurationEvent: $name")
5871
val beginTs = durationEventStartMap[name] ?: return
5972
durationEventStartMap.remove(name)
6073
val ts = getCurrentTs()
6174
val cost = (ts - beginTs).toInt()
6275

63-
innerReportCostEvent(ts, name, cost)
76+
innerReportCostEvent(ts, name, cost, ext)
6477
}
6578

6679
// 上报耗时打点信息
67-
fun reportCostEvent(name: String, cost: Int) {
80+
fun reportCostEvent(name: String, cost: Int, ext: Map<String, Any>) {
6881
durationEventStartMap.remove(name)
6982
innerReportCostEvent(
7083
ts = getCurrentTs(),
7184
name = name,
72-
cost = cost
85+
cost = cost,
86+
ext = ext
7387
)
7488
}
7589

@@ -105,11 +119,11 @@ class APIReporter(
105119
return System.currentTimeMillis()
106120
}
107121

108-
private fun innerReportCostEvent(ts: Long, name: String, cost: Int) {
109-
Log.d(tag, "reportCostEvent: $name cost: $cost ms")
122+
private fun innerReportCostEvent(ts: Long, name: String, cost: Int, ext: Map<String, Any>) {
123+
Log.d(tag, "reportCostEvent: $name cost: $cost ms ext: $ext")
110124
writeLog("reportCostEvent: $name cost: $cost ms", Constants.LOG_LEVEL_INFO)
111125
val eventMap = mapOf(ApiEventKey.TYPE to ApiEventType.COST.value, ApiEventKey.DESC to name)
112-
val labelMap = mapOf(ApiEventKey.TIMESTAMP to ts)
126+
val labelMap = mapOf(ApiEventKey.TIMESTAMP to ts, ApiEventKey.EXT to ext)
113127
val event = convertToJSONString(eventMap) ?: ""
114128
val label = convertToJSONString(labelMap) ?: ""
115129
rtcEngine.sendCustomReportMessage(messageId, category, event, label, cost)

KTVAPI/Android/lib_ktvapi/src/main/java/io/agora/ktvapi/KTVApiImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class KTVApiImpl(
2222
companion object {
2323
private val scheduledThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(5)
2424
const val tag = "KTV_API_LOG"
25-
const val version = "1_android_4.3.0"
25+
const val version = "4.3.0"
2626
const val lyricSyncVersion = 2
2727
}
2828

2929
private val mainHandler by lazy { Handler(Looper.getMainLooper()) }
3030
private var mRtcEngine: RtcEngineEx = ktvApiConfig.engine as RtcEngineEx
3131
private lateinit var mMusicCenter: IAgoraMusicContentCenter
3232
private var mPlayer: IMediaPlayer
33-
private val apiReporter: APIReporter = APIReporter(version, mRtcEngine)
33+
private val apiReporter: APIReporter = APIReporter(APIType.KTV, version, mRtcEngine)
3434

3535
private var innerDataStreamId: Int = 0
3636
private var subChorusConnection: RtcConnection? = null

KTVAPI/Android/lib_ktvapi/src/main/java/io/agora/ktvapi/KTVGiantChorusApiImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class KTVGiantChorusApiImpl(
2323
companion object {
2424
private val scheduledThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(5)
2525
private const val tag = "KTV_API_LOG_GIANT"
26-
private const val version = "1_android_4.3.0"
26+
private const val version = "4.3.0"
2727
private const val lyricSyncVersion = 2
2828
}
2929

3030
private val mainHandler by lazy { Handler(Looper.getMainLooper()) }
3131
private var mRtcEngine: RtcEngineEx = giantChorusApiConfig.engine as RtcEngineEx
3232
private lateinit var mMusicCenter: IAgoraMusicContentCenter
3333
private var mPlayer: IMediaPlayer
34-
private val apiReporter: APIReporter = APIReporter(version, mRtcEngine)
34+
private val apiReporter: APIReporter = APIReporter(APIType.KTV, version, mRtcEngine)
3535

3636
private var innerDataStreamId: Int = 0
3737
private var singChannelRtcConnection: RtcConnection? = null

0 commit comments

Comments
 (0)