Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func TestStatsInterceptorIsAddedByDefault(t *testing.T) {

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

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

statsID := pc.statsID
statsID := pc.id
getter, exists := lookupStats(statsID)
assert.True(t, exists, "global statsGetter map should contain entry for this PC")
assert.NotNil(t, getter, "looked up getter should not be nil")
Expand Down
18 changes: 9 additions & 9 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
// peer-to-peer communications with another PeerConnection instance in a
// browser, or to another endpoint implementing the required protocols.
type PeerConnection struct {
statsID string
mu sync.RWMutex
id string
mu sync.RWMutex

sdpOrigin sdp.Origin

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

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

i, err := api.interceptorRegistry.Build(pc.statsID)
i, err := api.interceptorRegistry.Build(pc.id)
if err != nil {
return nil, err
}

if getter, ok := lookupStats(pc.statsID); ok {
if getter, ok := lookupStats(pc.id); ok {
pc.statsGetter = getter
}

Expand Down Expand Up @@ -597,11 +597,11 @@ func (pc *PeerConnection) GetConfiguration() Configuration {
return pc.configuration
}

func (pc *PeerConnection) getStatsID() string {
func (pc *PeerConnection) ID() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeTurki just checking, does this method need to exist in peerconnection_js.go in order for consumers compiling to wasm to be able to access this method (and do we care)? I suspect the wasm build tests are passing because this is a new method, but checking whether it's ok to introduce a new public method here but not in the js/wasm equivalent file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, we currently don't support stats API in wasm, it would be cool to provide a fallback for stats and pion's interceptor but it will be a lot of work, and we can't support everything.
Thank you.

pc.mu.RLock()
defer pc.mu.RUnlock()

return pc.statsID
return pc.id
}

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

pc.statsGetter = nil
cleanupStats(pc.statsID)
cleanupStats(pc.id)

// Interceptor closes at the end to prevent Bind from being called after interceptor is closed
closeErrs = append(closeErrs, pc.api.interceptor.Close())
Expand Down Expand Up @@ -2623,7 +2623,7 @@ func (pc *PeerConnection) GetStats() StatsReport {
stats := PeerConnectionStats{
Timestamp: statsTimestampNow(),
Type: StatsTypePeerConnection,
ID: pc.statsID,
ID: pc.id,
DataChannelsAccepted: dataChannelsAccepted,
DataChannelsClosed: dataChannelsClosed,
DataChannelsOpened: dataChannelsOpened,
Expand Down
2 changes: 1 addition & 1 deletion stats_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// 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()
statsID := conn.ID()
stats, ok := r[statsID]
if !ok {
return PeerConnectionStats{}, false
Expand Down
6 changes: 3 additions & 3 deletions stats_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ func TestUnmarshalSCTPTransportStats_Error(t *testing.T) {

func TestStatsReport_GetConnectionStats_MissingEntry(t *testing.T) {
conn := &PeerConnection{}
conn.getStatsID()
conn.ID()

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

func TestStatsReport_GetConnectionStats_WrongType(t *testing.T) {
conn := &PeerConnection{}
id := conn.getStatsID()
id := conn.ID()

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

func TestStatsReport_GetConnectionStats_Success(t *testing.T) {
conn := &PeerConnection{}
id := conn.getStatsID()
id := conn.ID()

want := PeerConnectionStats{
ID: id,
Expand Down
Loading