snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
Fuzz / fuzz (push) Failing after 0s
CodeQL / analyze (push) Failing after 0s
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
Fuzz / fuzz (push) Failing after 0s
CodeQL / analyze (push) Failing after 0s
This commit is contained in:
119
icecandidatetype.go
Normal file
119
icecandidatetype.go
Normal file
@@ -0,0 +1,119 @@
|
||||
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pion/ice/v4"
|
||||
)
|
||||
|
||||
// ICECandidateType represents the type of the ICE candidate used.
|
||||
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
|
||||
|
||||
// ICECandidateTypeSrflx indicates the candidate is of Server
|
||||
// Reflexive type as described
|
||||
// https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A candidate type
|
||||
// whose IP address and port are a binding allocated by a NAT for an ICE
|
||||
// agent after it sends a packet through the NAT to a server, such as a
|
||||
// STUN server.
|
||||
ICECandidateTypeSrflx
|
||||
|
||||
// ICECandidateTypePrflx indicates that the candidate is of Peer
|
||||
// Reflexive type. A candidate type whose IP address and port are a binding
|
||||
// allocated by a NAT for an ICE agent after it sends a packet through the
|
||||
// NAT to its peer.
|
||||
ICECandidateTypePrflx
|
||||
|
||||
// ICECandidateTypeRelay indicates the candidate is of Relay type as
|
||||
// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A
|
||||
// candidate type obtained from a relay server, such as a TURN server.
|
||||
ICECandidateTypeRelay
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
iceCandidateTypeHostStr = "host"
|
||||
iceCandidateTypeSrflxStr = "srflx"
|
||||
iceCandidateTypePrflxStr = "prflx"
|
||||
iceCandidateTypeRelayStr = "relay"
|
||||
)
|
||||
|
||||
// NewICECandidateType takes a string and converts it into ICECandidateType.
|
||||
func NewICECandidateType(raw string) (ICECandidateType, error) {
|
||||
switch raw {
|
||||
case iceCandidateTypeHostStr:
|
||||
return ICECandidateTypeHost, nil
|
||||
case iceCandidateTypeSrflxStr:
|
||||
return ICECandidateTypeSrflx, nil
|
||||
case iceCandidateTypePrflxStr:
|
||||
return ICECandidateTypePrflx, nil
|
||||
case iceCandidateTypeRelayStr:
|
||||
return ICECandidateTypeRelay, nil
|
||||
default:
|
||||
return ICECandidateTypeUnknown, fmt.Errorf("%w: %s", errICECandidateTypeUnknown, raw)
|
||||
}
|
||||
}
|
||||
|
||||
func (t ICECandidateType) String() string {
|
||||
switch t {
|
||||
case ICECandidateTypeHost:
|
||||
return iceCandidateTypeHostStr
|
||||
case ICECandidateTypeSrflx:
|
||||
return iceCandidateTypeSrflxStr
|
||||
case ICECandidateTypePrflx:
|
||||
return iceCandidateTypePrflxStr
|
||||
case ICECandidateTypeRelay:
|
||||
return iceCandidateTypeRelayStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func getCandidateType(candidateType ice.CandidateType) (ICECandidateType, error) {
|
||||
switch candidateType {
|
||||
case ice.CandidateTypeHost:
|
||||
return ICECandidateTypeHost, nil
|
||||
case ice.CandidateTypeServerReflexive:
|
||||
return ICECandidateTypeSrflx, nil
|
||||
case ice.CandidateTypePeerReflexive:
|
||||
return ICECandidateTypePrflx, nil
|
||||
case ice.CandidateTypeRelay:
|
||||
return ICECandidateTypeRelay, nil
|
||||
default:
|
||||
// NOTE: this should never happen[tm]
|
||||
err := fmt.Errorf("%w: %s", errICEInvalidConvertCandidateType, candidateType.String())
|
||||
|
||||
return ICECandidateTypeUnknown, err
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
func (t ICECandidateType) MarshalText() ([]byte, error) { //nolint:staticcheck
|
||||
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
|
||||
}
|
||||
|
||||
func (r ICECandidateType) toICE() ice.CandidateType {
|
||||
//nolint:gosec // G115, no overflow, ICECandidateType matches ice.CandidateType in granularity.
|
||||
return ice.CandidateType(r)
|
||||
}
|
||||
Reference in New Issue
Block a user