Skip to content

Commit

Permalink
Remove the "Unknown" constant
Browse files Browse the repository at this point in the history
This commit replaces the Unknown constant with
separate constants for each enumeration that
uses it.

Fixes #1293
  • Loading branch information
wdouglass authored and Sean-Der committed Sep 12, 2023
1 parent 7e598b5 commit 1345033
Show file tree
Hide file tree
Showing 50 changed files with 163 additions and 122 deletions.
7 changes: 5 additions & 2 deletions bundlepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import (
type BundlePolicy int

const (
// BundlePolicyUnknown is the enum's zero-value
BundlePolicyUnknown BundlePolicy = iota

// BundlePolicyBalanced indicates to gather ICE candidates for each
// media type in use (audio, video, and data). If the remote endpoint is
// not bundle-aware, negotiate only one audio and video track on separate
// transports.
BundlePolicyBalanced BundlePolicy = iota + 1
BundlePolicyBalanced

// BundlePolicyMaxCompat indicates to gather ICE candidates for each
// track. If the remote endpoint is not bundle-aware, negotiate all media
Expand Down Expand Up @@ -47,7 +50,7 @@ func newBundlePolicy(raw string) BundlePolicy {
case bundlePolicyMaxBundleStr:
return BundlePolicyMaxBundle
default:
return BundlePolicy(Unknown)
return BundlePolicyUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions bundlepolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewBundlePolicy(t *testing.T) {
policyString string
expectedPolicy BundlePolicy
}{
{unknownStr, BundlePolicy(Unknown)},
{ErrUnknownType.Error(), BundlePolicyUnknown},
{"balanced", BundlePolicyBalanced},
{"max-compat", BundlePolicyMaxCompat},
{"max-bundle", BundlePolicyMaxBundle},
Expand All @@ -34,7 +34,7 @@ func TestBundlePolicy_String(t *testing.T) {
policy BundlePolicy
expectedString string
}{
{BundlePolicy(Unknown), unknownStr},
{BundlePolicyUnknown, ErrUnknownType.Error()},
{BundlePolicyBalanced, "balanced"},
{BundlePolicyMaxCompat, "max-compat"},
{BundlePolicyMaxBundle, "max-bundle"},
Expand Down
5 changes: 0 additions & 5 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ package webrtc
import "github.com/pion/dtls/v2"

const (
// Unknown defines default public constant to use for "enum" like struct
// comparisons when no value was defined.
Unknown = iota
unknownStr = "unknown"

// Equal to UDP MTU
receiveMTU = 1460

Expand Down
7 changes: 5 additions & 2 deletions datachannelstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ package webrtc
type DataChannelState int

const (
// DataChannelStateUnknown is the enum's zero-value
DataChannelStateUnknown DataChannelState = iota

// DataChannelStateConnecting indicates that the data channel is being
// established. This is the initial state of DataChannel, whether created
// with CreateDataChannel, or dispatched as a part of an DataChannelEvent.
DataChannelStateConnecting DataChannelState = iota + 1
DataChannelStateConnecting

// DataChannelStateOpen indicates that the underlying data transport is
// established and communication is possible.
Expand Down Expand Up @@ -44,7 +47,7 @@ func newDataChannelState(raw string) DataChannelState {
case dataChannelStateClosedStr:
return DataChannelStateClosed
default:
return DataChannelState(Unknown)
return DataChannelStateUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions datachannelstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewDataChannelState(t *testing.T) {
stateString string
expectedState DataChannelState
}{
{unknownStr, DataChannelState(Unknown)},
{ErrUnknownType.Error(), DataChannelStateUnknown},
{"connecting", DataChannelStateConnecting},
{"open", DataChannelStateOpen},
{"closing", DataChannelStateClosing},
Expand All @@ -35,7 +35,7 @@ func TestDataChannelState_String(t *testing.T) {
state DataChannelState
expectedString string
}{
{DataChannelState(Unknown), unknownStr},
{DataChannelStateUnknown, ErrUnknownType.Error()},
{DataChannelStateConnecting, "connecting"},
{DataChannelStateOpen, "open"},
{DataChannelStateClosing, "closing"},
Expand Down
7 changes: 5 additions & 2 deletions dtlsrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
type DTLSRole byte

const (
// DTLSRoleUnknown is the enum's zero-value
DTLSRoleUnknown DTLSRole = iota

// DTLSRoleAuto defines the DTLS role is determined based on
// the resolved ICE role: the ICE controlled role acts as the DTLS
// client and the ICE controlling role acts as the DTLS server.
DTLSRoleAuto DTLSRole = iota + 1
DTLSRoleAuto

// DTLSRoleClient defines the DTLS client role.
DTLSRoleClient
Expand Down Expand Up @@ -51,7 +54,7 @@ func (r DTLSRole) String() string {
case DTLSRoleServer:
return "server"
default:
return unknownStr
return ErrUnknownType.Error()
}
}

Expand Down
2 changes: 1 addition & 1 deletion dtlsrole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestDTLSRole_String(t *testing.T) {
role DTLSRole
expectedString string
}{
{DTLSRole(Unknown), unknownStr},
{DTLSRoleUnknown, ErrUnknownType.Error()},
{DTLSRoleAuto, "auto"},
{DTLSRoleClient, "client"},
{DTLSRoleServer, "server"},
Expand Down
7 changes: 5 additions & 2 deletions dtlstransportstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ package webrtc
type DTLSTransportState int

const (
// DTLSTransportStateUnknown is the enum's zero-value
DTLSTransportStateUnknown DTLSTransportState = iota

// DTLSTransportStateNew indicates that DTLS has not started negotiating
// yet.
DTLSTransportStateNew DTLSTransportState = iota + 1
DTLSTransportStateNew

// DTLSTransportStateConnecting indicates that DTLS is in the process of
// negotiating a secure connection and verifying the remote fingerprint.
Expand Down Expand Up @@ -52,7 +55,7 @@ func newDTLSTransportState(raw string) DTLSTransportState {
case dtlsTransportStateFailedStr:
return DTLSTransportStateFailed
default:
return DTLSTransportState(Unknown)
return DTLSTransportStateUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions dtlstransportstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewDTLSTransportState(t *testing.T) {
stateString string
expectedState DTLSTransportState
}{
{unknownStr, DTLSTransportState(Unknown)},
{ErrUnknownType.Error(), DTLSTransportStateUnknown},
{"new", DTLSTransportStateNew},
{"connecting", DTLSTransportStateConnecting},
{"connected", DTLSTransportStateConnected},
Expand All @@ -36,7 +36,7 @@ func TestDTLSTransportState_String(t *testing.T) {
state DTLSTransportState
expectedString string
}{
{DTLSTransportState(Unknown), unknownStr},
{DTLSTransportStateUnknown, ErrUnknownType.Error()},
{DTLSTransportStateNew, "new"},
{DTLSTransportStateConnecting, "connecting"},
{DTLSTransportStateConnected, "connected"},
Expand Down
9 changes: 6 additions & 3 deletions icecandidatetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import (
type ICECandidateType int

const (
// ICECandidateTypeUnknown is the enum's zero-value
ICECandidateTypeUnknown ICECandidateType = iota

// ICECandidateTypeHost indicates that the candidate is of Host type as
// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.1. A
// candidate obtained by binding to a specific port from an IP address on
// the host. This includes IP addresses on physical interfaces and logical
// ones, such as ones obtained through VPNs.
ICECandidateTypeHost ICECandidateType = iota + 1
ICECandidateTypeHost

// ICECandidateTypeSrflx indicates the the candidate is of Server
// Reflexive type as described
Expand Down Expand Up @@ -60,7 +63,7 @@ func NewICECandidateType(raw string) (ICECandidateType, error) {
case iceCandidateTypeRelayStr:
return ICECandidateTypeRelay, nil
default:
return ICECandidateType(Unknown), fmt.Errorf("%w: %s", errICECandidateTypeUnknown, raw)
return ICECandidateTypeUnknown, fmt.Errorf("%w: %s", errICECandidateTypeUnknown, raw)
}
}

Expand Down Expand Up @@ -92,7 +95,7 @@ func getCandidateType(candidateType ice.CandidateType) (ICECandidateType, error)
default:
// NOTE: this should never happen[tm]
err := fmt.Errorf("%w: %s", errICEInvalidConvertCandidateType, candidateType.String())
return ICECandidateType(Unknown), err
return ICECandidateTypeUnknown, err
}
}

Expand Down
4 changes: 2 additions & 2 deletions icecandidatetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestICECandidateType(t *testing.T) {
shouldFail bool
expectedType ICECandidateType
}{
{unknownStr, true, ICECandidateType(Unknown)},
{ErrUnknownType.Error(), true, ICECandidateTypeUnknown},
{"host", false, ICECandidateTypeHost},
{"srflx", false, ICECandidateTypeSrflx},
{"prflx", false, ICECandidateTypePrflx},
Expand All @@ -40,7 +40,7 @@ func TestICECandidateType_String(t *testing.T) {
cType ICECandidateType
expectedString string
}{
{ICECandidateType(Unknown), unknownStr},
{ICECandidateTypeUnknown, ErrUnknownType.Error()},
{ICECandidateTypeHost, "host"},
{ICECandidateTypeSrflx, "srflx"},
{ICECandidateTypePrflx, "prflx"},
Expand Down
7 changes: 5 additions & 2 deletions icecomponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ package webrtc
type ICEComponent int

const (
// ICEComponentUnknown is the enum's zero-value
ICEComponentUnknown ICEComponent = iota

// ICEComponentRTP indicates that the ICE Transport is used for RTP (or
// RTCP multiplexing), as defined in
// https://tools.ietf.org/html/rfc5245#section-4.1.1.1. Protocols
// multiplexed with RTP (e.g. data channel) share its component ID. This
// represents the component-id value 1 when encoded in candidate-attribute.
ICEComponentRTP ICEComponent = iota + 1
ICEComponentRTP

// ICEComponentRTCP indicates that the ICE Transport is used for RTCP as
// defined by https://tools.ietf.org/html/rfc5245#section-4.1.1.1. This
Expand All @@ -34,7 +37,7 @@ func newICEComponent(raw string) ICEComponent {
case iceComponentRTCPStr:
return ICEComponentRTCP
default:
return ICEComponent(Unknown)
return ICEComponentUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions icecomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestICEComponent(t *testing.T) {
componentString string
expectedComponent ICEComponent
}{
{unknownStr, ICEComponent(Unknown)},
{ErrUnknownType.Error(), ICEComponentUnknown},
{"rtp", ICEComponentRTP},
{"rtcp", ICEComponentRTCP},
}
Expand All @@ -33,7 +33,7 @@ func TestICEComponent_String(t *testing.T) {
state ICEComponent
expectedString string
}{
{ICEComponent(Unknown), unknownStr},
{ICEComponentUnknown, ErrUnknownType.Error()},
{ICEComponentRTP, "rtp"},
{ICEComponentRTCP, "rtcp"},
}
Expand Down
7 changes: 5 additions & 2 deletions iceconnectionstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ package webrtc
type ICEConnectionState int

const (
// ICEConnectionStateUnknown is the enum's zero-value
ICEConnectionStateUnknown ICEConnectionState = iota

// ICEConnectionStateNew indicates that any of the ICETransports are
// in the "new" state and none of them are in the "checking", "disconnected"
// or "failed" state, or all ICETransports are in the "closed" state, or
// there are no transports.
ICEConnectionStateNew ICEConnectionState = iota + 1
ICEConnectionStateNew

// ICEConnectionStateChecking indicates that any of the ICETransports
// are in the "checking" state and none of them are in the "disconnected"
Expand Down Expand Up @@ -71,7 +74,7 @@ func NewICEConnectionState(raw string) ICEConnectionState {
case iceConnectionStateClosedStr:
return ICEConnectionStateClosed
default:
return ICEConnectionState(Unknown)
return ICEConnectionStateUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions iceconnectionstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewICEConnectionState(t *testing.T) {
stateString string
expectedState ICEConnectionState
}{
{unknownStr, ICEConnectionState(Unknown)},
{ErrUnknownType.Error(), ICEConnectionStateUnknown},
{"new", ICEConnectionStateNew},
{"checking", ICEConnectionStateChecking},
{"connected", ICEConnectionStateConnected},
Expand All @@ -38,7 +38,7 @@ func TestICEConnectionState_String(t *testing.T) {
state ICEConnectionState
expectedString string
}{
{ICEConnectionState(Unknown), unknownStr},
{ICEConnectionStateUnknown, ErrUnknownType.Error()},
{ICEConnectionStateNew, "new"},
{ICEConnectionStateChecking, "checking"},
{ICEConnectionStateConnected, "connected"},
Expand Down
7 changes: 5 additions & 2 deletions icegathererstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (
type ICEGathererState uint32

const (
// ICEGathererStateUnknown is the enum's zero-value
ICEGathererStateUnknown ICEGathererState = iota

// ICEGathererStateNew indicates object has been created but
// gather() has not been called.
ICEGathererStateNew ICEGathererState = iota + 1
ICEGathererStateNew

// ICEGathererStateGathering indicates gather() has been called,
// and the ICEGatherer is in the process of gathering candidates.
Expand All @@ -38,7 +41,7 @@ func (s ICEGathererState) String() string {
case ICEGathererStateClosed:
return "closed"
default:
return unknownStr
return ErrUnknownType.Error()
}
}

Expand Down
2 changes: 1 addition & 1 deletion icegathererstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestICEGathererState_String(t *testing.T) {
state ICEGathererState
expectedString string
}{
{ICEGathererState(Unknown), unknownStr},
{ICEGathererStateUnknown, ErrUnknownType.Error()},
{ICEGathererStateNew, "new"},
{ICEGathererStateGathering, "gathering"},
{ICEGathererStateComplete, "complete"},
Expand Down
7 changes: 5 additions & 2 deletions icegatheringstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ package webrtc
type ICEGatheringState int

const (
// ICEGatheringStateUnknown is the enum's zero-value
ICEGatheringStateUnknown ICEGatheringState = iota

// ICEGatheringStateNew indicates that any of the ICETransports are
// in the "new" gathering state and none of the transports are in the
// "gathering" state, or there are no transports.
ICEGatheringStateNew ICEGatheringState = iota + 1
ICEGatheringStateNew

// ICEGatheringStateGathering indicates that any of the ICETransports
// are in the "gathering" state.
Expand Down Expand Up @@ -38,7 +41,7 @@ func NewICEGatheringState(raw string) ICEGatheringState {
case iceGatheringStateCompleteStr:
return ICEGatheringStateComplete
default:
return ICEGatheringState(Unknown)
return ICEGatheringStateUnknown
}
}

Expand Down
4 changes: 2 additions & 2 deletions icegatheringstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewICEGatheringState(t *testing.T) {
stateString string
expectedState ICEGatheringState
}{
{unknownStr, ICEGatheringState(Unknown)},
{ErrUnknownType.Error(), ICEGatheringStateUnknown},
{"new", ICEGatheringStateNew},
{"gathering", ICEGatheringStateGathering},
{"complete", ICEGatheringStateComplete},
Expand All @@ -34,7 +34,7 @@ func TestICEGatheringState_String(t *testing.T) {
state ICEGatheringState
expectedString string
}{
{ICEGatheringState(Unknown), unknownStr},
{ICEGatheringStateUnknown, ErrUnknownType.Error()},
{ICEGatheringStateNew, "new"},
{ICEGatheringStateGathering, "gathering"},
{ICEGatheringStateComplete, "complete"},
Expand Down
Loading

0 comments on commit 1345033

Please sign in to comment.