Skip to content

Commit 2926b99

Browse files
aalekseevxSean-Der
authored andcommitted
Stats: improve JSON support, add missing structs
- 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
1 parent 6453346 commit 2926b99

File tree

8 files changed

+1554
-33
lines changed

8 files changed

+1554
-33
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Adrian Cable <[email protected]>
1212
1313
1414
15+
Aleksandr Alekseev <[email protected]>
1516
Aleksandr Razumov <[email protected]>
1617
1718
Alex Browne <[email protected]>

datachannelstate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,14 @@ func (t DataChannelState) String() string {
6262
return ErrUnknownType.Error()
6363
}
6464
}
65+
66+
// MarshalText implements encoding.TextMarshaler
67+
func (t DataChannelState) MarshalText() ([]byte, error) {
68+
return []byte(t.String()), nil
69+
}
70+
71+
// UnmarshalText implements encoding.TextUnmarshaler
72+
func (t *DataChannelState) UnmarshalText(b []byte) error {
73+
*t = newDataChannelState(string(b))
74+
return nil
75+
}

dtlstransportstate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ func (t DTLSTransportState) String() string {
7272
return ErrUnknownType.Error()
7373
}
7474
}
75+
76+
// MarshalText implements encoding.TextMarshaler
77+
func (t DTLSTransportState) MarshalText() ([]byte, error) {
78+
return []byte(t.String()), nil
79+
}
80+
81+
// UnmarshalText implements encoding.TextUnmarshaler
82+
func (t *DTLSTransportState) UnmarshalText(b []byte) error {
83+
*t = newDTLSTransportState(string(b))
84+
return nil
85+
}

icecandidatetype.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ func getCandidateType(candidateType ice.CandidateType) (ICECandidateType, error)
9595
return ICECandidateType(Unknown), err
9696
}
9797
}
98+
99+
// MarshalText implements the encoding.TextMarshaler interface.
100+
func (t ICECandidateType) MarshalText() ([]byte, error) {
101+
return []byte(t.String()), nil
102+
}
103+
104+
// UnmarshalText implements the encoding.TextUnmarshaler interface.
105+
func (t *ICECandidateType) UnmarshalText(b []byte) error {
106+
var err error
107+
*t, err = NewICECandidateType(string(b))
108+
return err
109+
}

icegatherer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ func (g *ICEGatherer) collectStats(collector *statsReportCollector) {
347347
Timestamp: statsTimestampFrom(candidateStats.Timestamp),
348348
ID: candidateStats.ID,
349349
Type: StatsTypeLocalCandidate,
350-
NetworkType: networkType,
351350
IP: candidateStats.IP,
352351
Port: int32(candidateStats.Port),
353352
Protocol: networkType.Protocol(),
@@ -376,7 +375,6 @@ func (g *ICEGatherer) collectStats(collector *statsReportCollector) {
376375
Timestamp: statsTimestampFrom(candidateStats.Timestamp),
377376
ID: candidateStats.ID,
378377
Type: StatsTypeRemoteCandidate,
379-
NetworkType: networkType,
380378
IP: candidateStats.IP,
381379
Port: int32(candidateStats.Port),
382380
Protocol: networkType.Protocol(),

icerole.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ func (t ICERole) String() string {
4646
return ErrUnknownType.Error()
4747
}
4848
}
49+
50+
// MarshalText implements encoding.TextMarshaler
51+
func (t ICERole) MarshalText() ([]byte, error) {
52+
return []byte(t.String()), nil
53+
}
54+
55+
// UnmarshalText implements encoding.TextUnmarshaler
56+
func (t *ICERole) UnmarshalText(b []byte) error {
57+
*t = newICERole(string(b))
58+
return nil
59+
}

0 commit comments

Comments
 (0)