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 authored and Sean-Der committed Aug 17, 2023
1 parent 6453346 commit 2926b99
Show file tree
Hide file tree
Showing 8 changed files with 1,554 additions and 33 deletions.
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
}
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 2926b99

Please sign in to comment.