Skip to content

Commit e11b089

Browse files
committed
Expose stats ID for use in interceptor factories
1 parent 7d8a700 commit e11b089

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

interceptor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func TestStatsInterceptorIsAddedByDefault(t *testing.T) {
374374

375375
// Also assert that the getter stored during interceptor Build matches
376376
// the one attached to this PeerConnection.
377-
getter, ok := lookupStats(pc.statsID)
377+
getter, ok := lookupStats(pc.id)
378378
assert.True(t, ok, "lookupStats should return a getter for this statsID")
379379
assert.NotNil(t, getter)
380380
assert.Equal(t,
@@ -392,7 +392,7 @@ func TestStatsGetterCleanup(t *testing.T) {
392392

393393
assert.NotNil(t, pc.statsGetter, "statsGetter should be non-nil after creation")
394394

395-
statsID := pc.statsID
395+
statsID := pc.id
396396
getter, exists := lookupStats(statsID)
397397
assert.True(t, exists, "global statsGetter map should contain entry for this PC")
398398
assert.NotNil(t, getter, "looked up getter should not be nil")

peerconnection.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
// peer-to-peer communications with another PeerConnection instance in a
3636
// browser, or to another endpoint implementing the required protocols.
3737
type PeerConnection struct {
38-
statsID string
39-
mu sync.RWMutex
38+
id string
39+
mu sync.RWMutex
4040

4141
sdpOrigin sdp.Origin
4242

@@ -118,7 +118,7 @@ func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection,
118118
// allow better readability to understand what is happening.
119119

120120
pc := &PeerConnection{
121-
statsID: fmt.Sprintf("PeerConnection-%d", time.Now().UnixNano()),
121+
id: fmt.Sprintf("PeerConnection-%d", time.Now().UnixNano()),
122122
configuration: Configuration{
123123
ICEServers: []ICEServer{},
124124
ICETransportPolicy: ICETransportPolicyAll,
@@ -145,12 +145,12 @@ func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection,
145145
pc.iceConnectionState.Store(ICEConnectionStateNew)
146146
pc.connectionState.Store(PeerConnectionStateNew)
147147

148-
i, err := api.interceptorRegistry.Build(pc.statsID)
148+
i, err := api.interceptorRegistry.Build(pc.id)
149149
if err != nil {
150150
return nil, err
151151
}
152152

153-
if getter, ok := lookupStats(pc.statsID); ok {
153+
if getter, ok := lookupStats(pc.id); ok {
154154
pc.statsGetter = getter
155155
}
156156

@@ -597,11 +597,11 @@ func (pc *PeerConnection) GetConfiguration() Configuration {
597597
return pc.configuration
598598
}
599599

600-
func (pc *PeerConnection) getStatsID() string {
600+
func (pc *PeerConnection) ID() string {
601601
pc.mu.RLock()
602602
defer pc.mu.RUnlock()
603603

604-
return pc.statsID
604+
return pc.id
605605
}
606606

607607
// hasLocalDescriptionChanged returns whether local media (rtpTransceivers) has changed
@@ -2482,7 +2482,7 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc
24822482
closeErrs = append(closeErrs, doGracefulCloseOps()...)
24832483

24842484
pc.statsGetter = nil
2485-
cleanupStats(pc.statsID)
2485+
cleanupStats(pc.id)
24862486

24872487
// Interceptor closes at the end to prevent Bind from being called after interceptor is closed
24882488
closeErrs = append(closeErrs, pc.api.interceptor.Close())
@@ -2623,7 +2623,7 @@ func (pc *PeerConnection) GetStats() StatsReport {
26232623
stats := PeerConnectionStats{
26242624
Timestamp: statsTimestampNow(),
26252625
Type: StatsTypePeerConnection,
2626-
ID: pc.statsID,
2626+
ID: pc.id,
26272627
DataChannelsAccepted: dataChannelsAccepted,
26282628
DataChannelsClosed: dataChannelsClosed,
26292629
DataChannelsOpened: dataChannelsOpened,

stats_go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// GetConnectionStats is a helper method to return the associated stats for a given PeerConnection.
1616
func (r StatsReport) GetConnectionStats(conn *PeerConnection) (PeerConnectionStats, bool) {
17-
statsID := conn.getStatsID()
17+
statsID := conn.ID()
1818
stats, ok := r[statsID]
1919
if !ok {
2020
return PeerConnectionStats{}, false

stats_go_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ func TestUnmarshalSCTPTransportStats_Error(t *testing.T) {
20372037

20382038
func TestStatsReport_GetConnectionStats_MissingEntry(t *testing.T) {
20392039
conn := &PeerConnection{}
2040-
conn.getStatsID()
2040+
conn.ID()
20412041

20422042
r := StatsReport{}
20432043
got, ok := r.GetConnectionStats(conn)
@@ -2048,7 +2048,7 @@ func TestStatsReport_GetConnectionStats_MissingEntry(t *testing.T) {
20482048

20492049
func TestStatsReport_GetConnectionStats_WrongType(t *testing.T) {
20502050
conn := &PeerConnection{}
2051-
id := conn.getStatsID()
2051+
id := conn.ID()
20522052

20532053
r := StatsReport{
20542054
id: DataChannelStats{ID: "not-a-pc-stats"},
@@ -2062,7 +2062,7 @@ func TestStatsReport_GetConnectionStats_WrongType(t *testing.T) {
20622062

20632063
func TestStatsReport_GetConnectionStats_Success(t *testing.T) {
20642064
conn := &PeerConnection{}
2065-
id := conn.getStatsID()
2065+
id := conn.ID()
20662066

20672067
want := PeerConnectionStats{
20682068
ID: id,

0 commit comments

Comments
 (0)