Skip to content

Commit

Permalink
Stats: improve JSON support, add missing structs
Browse files Browse the repository at this point in the history
- Fix json marshalling of stats containing enums
- Add UnmarshalStatsJSON helper
- Add marshalling/unmarshalling tests
- Add missing AudioSourceStats, VideoSourceStats AudioPlayoutStats
  defined in https://www.w3.org/TR/webrtc-stats
- Deprecate ICECandidateStats' NetworkType, use plain string
  instead of enum which does not suite the definition:
  https://clck.ru/354H9r
  • Loading branch information
aalekseevx committed Jul 20, 2023
1 parent 3cddada commit 5e7641b
Show file tree
Hide file tree
Showing 34 changed files with 1,554 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Files: README.md DESIGN.md **/README.md AUTHORS.txt renovate.json go.mod go.sum
Copyright: 2023 The Pion community <https://pion.ly>
License: MIT

Files: testdata/fuzz/* **/testdata/fuzz/* api/*.txt
Files: testdata/* testdata/fuzz/* **/testdata/fuzz/* api/*.txt
Copyright: 2023 The Pion community <https://pion.ly>
License: CC0-1.0
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Adrian Cable <[email protected]>
adwpc <[email protected]>
aggresss <[email protected]>
akil <[email protected]>
Aleksandr Alekseev <[email protected]>
Aleksandr Razumov <[email protected]>
aler9 <[email protected]>
Alex Browne <[email protected]>
Expand Down
11 changes: 11 additions & 0 deletions datachannelstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ func (t DataChannelState) String() string {
return ErrUnknownType.Error()
}
}

// MarshalText implements encoding.TextMarshaler
func (t DataChannelState) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}

// UnmarshalText implements encoding.TextUnmarshaler
func (t *DataChannelState) UnmarshalText(b []byte) error {
*t = newDataChannelState(string(b))
return nil
}
11 changes: 11 additions & 0 deletions dtlstransportstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ func (t DTLSTransportState) String() string {
return ErrUnknownType.Error()
}
}

// MarshalText implements encoding.TextMarshaler
func (t DTLSTransportState) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}

// UnmarshalText implements encoding.TextUnmarshaler
func (t *DTLSTransportState) UnmarshalText(b []byte) error {
*t = newDTLSTransportState(string(b))
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/pion/webrtc/v3
go 1.13

require (
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.17.0 // indirect
github.com/pion/datachannel v1.5.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
12 changes: 12 additions & 0 deletions icecandidatetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ func getCandidateType(candidateType ice.CandidateType) (ICECandidateType, error)
return ICECandidateType(Unknown), err
}
}

// MarshalText implements the encoding.TextMarshaler interface.
func (t ICECandidateType) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (t *ICECandidateType) UnmarshalText(b []byte) error {
var err error
*t, err = NewICECandidateType(string(b))
return err
}
2 changes: 0 additions & 2 deletions icegatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ func (g *ICEGatherer) collectStats(collector *statsReportCollector) {
Timestamp: statsTimestampFrom(candidateStats.Timestamp),
ID: candidateStats.ID,
Type: StatsTypeLocalCandidate,
NetworkType: networkType,
IP: candidateStats.IP,
Port: int32(candidateStats.Port),
Protocol: networkType.Protocol(),
Expand Down Expand Up @@ -376,7 +375,6 @@ func (g *ICEGatherer) collectStats(collector *statsReportCollector) {
Timestamp: statsTimestampFrom(candidateStats.Timestamp),
ID: candidateStats.ID,
Type: StatsTypeRemoteCandidate,
NetworkType: networkType,
IP: candidateStats.IP,
Port: int32(candidateStats.Port),
Protocol: networkType.Protocol(),
Expand Down
11 changes: 11 additions & 0 deletions icerole.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ func (t ICERole) String() string {
return ErrUnknownType.Error()
}
}

// MarshalText implements encoding.TextMarshaler
func (t ICERole) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}

// UnmarshalText implements encoding.TextUnmarshaler
func (t *ICERole) UnmarshalText(b []byte) error {
*t = newICERole(string(b))
return nil
}
Loading

0 comments on commit 5e7641b

Please sign in to comment.