forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_go.go
63 lines (54 loc) · 1.66 KB
/
stats_go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// +build !js
package webrtc
// GetConnectionStats is a helper method to return the associated stats for a given PeerConnection
func (r StatsReport) GetConnectionStats(conn *PeerConnection) (PeerConnectionStats, bool) {
statsID := conn.getStatsID()
stats, ok := r[statsID]
if !ok {
return PeerConnectionStats{}, false
}
pcStats, ok := stats.(PeerConnectionStats)
if !ok {
return PeerConnectionStats{}, false
}
return pcStats, true
}
// GetDataChannelStats is a helper method to return the associated stats for a given DataChannel
func (r StatsReport) GetDataChannelStats(dc *DataChannel) (DataChannelStats, bool) {
statsID := dc.getStatsID()
stats, ok := r[statsID]
if !ok {
return DataChannelStats{}, false
}
dcStats, ok := stats.(DataChannelStats)
if !ok {
return DataChannelStats{}, false
}
return dcStats, true
}
// GetICECandidateStats is a helper method to return the associated stats for a given ICECandidate
func (r StatsReport) GetICECandidateStats(c *ICECandidate) (ICECandidateStats, bool) {
statsID := c.statsID
stats, ok := r[statsID]
if !ok {
return ICECandidateStats{}, false
}
candidateStats, ok := stats.(ICECandidateStats)
if !ok {
return ICECandidateStats{}, false
}
return candidateStats, true
}
// GetICECandidatePairStats is a helper method to return the associated stats for a given ICECandidatePair
func (r StatsReport) GetICECandidatePairStats(c *ICECandidatePair) (ICECandidatePairStats, bool) {
statsID := c.statsID
stats, ok := r[statsID]
if !ok {
return ICECandidatePairStats{}, false
}
candidateStats, ok := stats.(ICECandidatePairStats)
if !ok {
return ICECandidatePairStats{}, false
}
return candidateStats, true
}