Skip to content

Commit f34b1ce

Browse files
committed
#3 connectionID should be the same for one peer connection
1 parent d7a5f8a commit f34b1ce

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

library/src/main/java/io/callstats/event/EventManager.kt

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package io.callstats.event
22

33
import io.callstats.CallstatsConfig
4-
import io.callstats.OnIceConnectionChange
54
import io.callstats.OnStats
65
import io.callstats.PeerEvent
76
import io.callstats.event.fabric.FabricSetupEvent
87
import io.callstats.event.fabric.FabricTerminatedEvent
98
import io.callstats.interceptor.Interceptor
10-
import io.callstats.utils.*
119
import org.webrtc.PeerConnection
12-
import org.webrtc.RTCStatsReport
1310
import java.util.Timer
1411
import kotlin.concurrent.timerTask
1512

@@ -25,8 +22,7 @@ internal interface EventManager {
2522
}
2623

2724
/**
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
3026
*/
3127
internal class EventManagerImpl(
3228
private val sender: EventSender,
@@ -36,18 +32,11 @@ internal class EventManagerImpl(
3632
private val config: CallstatsConfig,
3733
private val interceptors: Array<Interceptor> = emptyArray()): EventManager
3834
{
39-
internal var connectionID = ""
35+
private val connectionID = createConnectionID()
4036
private var statsTimer: Timer? = null
4137

4238
override fun process(event: PeerEvent) {
4339
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-
5140
// forward event
5241
interceptors.forEach { interceptor ->
5342
val events = interceptor.process(
@@ -79,19 +68,7 @@ internal class EventManagerImpl(
7968
statsTimer = null
8069
}
8170

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()
9673
}
9774
}

library/src/test/java/io/callstats/event/EventManagerTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ class EventManagerTest {
3333
connection,
3434
CallstatsConfig(),
3535
arrayOf(mockInterceptor1, mockInterceptor2))
36-
manager.connectionID = "con1"
3736

3837
whenever(connection.getStats(any())).thenAnswer {
3938
(it.arguments[0] as RTCStatsCollectorCallback).onStatsDelivered(RTCStatsReport(0, mapOf()))
4039
}
41-
4240
whenever(mockInterceptor1.process(any(), any(), any(), any(), any(), any())).thenReturn(emptyArray())
4341
whenever(mockInterceptor2.process(any(), any(), any(), any(), any(), any())).thenReturn(emptyArray())
4442
}

0 commit comments

Comments
 (0)