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 Aug 8, 2023
1 parent 6453346 commit ec5f6f2
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 <adrian.cable@gmail.com>
adwpc <adwpc@hotmail.com>
aggresss <aggresss@163.com>
akil <akil@everycrave.me>
Aleksandr Alekseev <alekseev-dev@yandex-team.ru>
Aleksandr Razumov <ar@gortc.io>
aler9 <46489434+aler9@users.noreply.github.com>
Alex Browne <stephenalexbrowne@gmail.com>
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 ec5f6f2

Please sign in to comment.