1
1
package io.callstats.event
2
2
3
3
import io.callstats.CallstatsConfig
4
- import io.callstats.OnIceConnectionChange
5
4
import io.callstats.OnStats
6
5
import io.callstats.PeerEvent
7
6
import io.callstats.event.fabric.FabricSetupEvent
8
7
import io.callstats.event.fabric.FabricTerminatedEvent
9
8
import io.callstats.interceptor.Interceptor
10
- import io.callstats.utils.*
11
9
import org.webrtc.PeerConnection
12
- import org.webrtc.RTCStatsReport
13
10
import java.util.Timer
14
11
import kotlin.concurrent.timerTask
15
12
@@ -25,8 +22,7 @@ internal interface EventManager {
25
22
}
26
23
27
24
/* *
28
- * If it is WebRTC events, forward to interceptors and let them create events
29
- * If it is Application events, convert to event directly
25
+ * Forward to interceptors and let them create events
30
26
*/
31
27
internal class EventManagerImpl (
32
28
private val sender : EventSender ,
@@ -36,18 +32,11 @@ internal class EventManagerImpl(
36
32
private val config : CallstatsConfig ,
37
33
private val interceptors : Array <Interceptor > = emptyArray()): EventManager
38
34
{
39
- internal var connectionID = " "
35
+ private val connectionID = createConnectionID()
40
36
private var statsTimer: Timer ? = null
41
37
42
38
override fun process (event : PeerEvent ) {
43
39
connection.getStats { report ->
44
- // every time ice connected, update connection ID
45
- if (event is OnIceConnectionChange && event.state == PeerConnection .IceConnectionState .CONNECTED ) {
46
- connectionID = createConnectionID(report)
47
- }
48
- // no connection ID, don't send
49
- if (connectionID.isEmpty()) return @getStats
50
-
51
40
// forward event
52
41
interceptors.forEach { interceptor ->
53
42
val events = interceptor.process(
@@ -79,19 +68,7 @@ internal class EventManagerImpl(
79
68
statsTimer = null
80
69
}
81
70
82
- private fun createConnectionID (report : RTCStatsReport ): String {
83
- // create connection ID from local and remote candidate IP + Port
84
- val stats = report.statsMap
85
- return stats.selectedCandidatePairId()
86
- // find selected pair
87
- ?.let { selectId -> stats.candidatePairs().firstOrNull { it.id == selectId } }
88
- // find candidates and create ID
89
- ?.let { pair ->
90
- val local = stats.localCandidates().firstOrNull { it.id == pair.localCandidateId }
91
- val remote = stats.remoteCandidates().firstOrNull { it.id == pair.remoteCandidateId }
92
- if (local != null && remote != null ) {
93
- md5(" ${local.ip}${local.port}${remote.ip}${remote.port} " )
94
- } else null
95
- } ? : " "
71
+ private fun createConnectionID (): String {
72
+ return System .currentTimeMillis().toString()
96
73
}
97
74
}
0 commit comments