Skip to content

Commit

Permalink
Support more data from webrtc stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Tarasiuk authored and aalekseevx committed Oct 5, 2024
1 parent 5637661 commit dccfbb2
Show file tree
Hide file tree
Showing 3 changed files with 546 additions and 120 deletions.
56 changes: 49 additions & 7 deletions icetransportstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,53 @@ const (
ICETransportStateClosed
)

const (
iceTransportStateNewStr = "new"
iceTransportStateCheckingStr = "checking"
iceTransportStateConnectedStr = "connected"
iceTransportStateCompletedStr = "completed"
iceTransportStateFailedStr = "failed"
iceTransportStateDisconnectedStr = "disconnected"
iceTransportStateClosedStr = "closed"
)

func newICETransportState(raw string) ICETransportState {
switch raw {
case iceTransportStateNewStr:
return ICETransportStateNew
case iceTransportStateCheckingStr:
return ICETransportStateChecking

Check warning on line 67 in icetransportstate.go

View check run for this annotation

Codecov / codecov/patch

icetransportstate.go#L64-L67

Added lines #L64 - L67 were not covered by tests
case iceTransportStateConnectedStr:
return ICETransportStateConnected
case iceTransportStateCompletedStr:
return ICETransportStateCompleted
case iceTransportStateFailedStr:
return ICETransportStateFailed
case iceTransportStateDisconnectedStr:
return ICETransportStateDisconnected
case iceTransportStateClosedStr:
return ICETransportStateClosed
default:
return ICETransportStateUnknown

Check warning on line 79 in icetransportstate.go

View check run for this annotation

Codecov / codecov/patch

icetransportstate.go#L70-L79

Added lines #L70 - L79 were not covered by tests
}
}

func (c ICETransportState) String() string {
switch c {
case ICETransportStateNew:
return "new"
return iceTransportStateNewStr
case ICETransportStateChecking:
return "checking"
return iceTransportStateCheckingStr
case ICETransportStateConnected:
return "connected"
return iceTransportStateConnectedStr
case ICETransportStateCompleted:
return "completed"
return iceTransportStateCompletedStr
case ICETransportStateFailed:
return "failed"
return iceTransportStateFailedStr
case ICETransportStateDisconnected:
return "disconnected"
return iceTransportStateDisconnectedStr
case ICETransportStateClosed:
return "closed"
return iceTransportStateClosedStr
default:
return ErrUnknownType.Error()
}
Expand Down Expand Up @@ -111,3 +142,14 @@ func (c ICETransportState) toICE() ice.ConnectionState {
return ice.ConnectionStateUnknown
}
}

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

// UnmarshalText implements encoding.TextUnmarshaler
func (c *ICETransportState) UnmarshalText(b []byte) error {
*c = newICETransportState(string(b))
return nil
}
Loading

0 comments on commit dccfbb2

Please sign in to comment.