ice

package
v2.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TransportStateNew indicates the Transport is waiting
	// for remote candidates to be supplied.
	TransportStateNew = iota + 1

	// TransportStateChecking indicates the Transport has
	// received at least one remote candidate, and a local and remote
	// ICECandidateComplete dictionary was not added as the last candidate.
	TransportStateChecking

	// TransportStateConnected indicates the Transport has
	// received a response to an outgoing connectivity check, or has
	// received incoming DTLS/media after a successful response to an
	// incoming connectivity check, but is still checking other candidate
	// pairs to see if there is a better connection.
	TransportStateConnected

	// TransportStateCompleted indicates the Transport tested
	// all appropriate candidate pairs and at least one functioning
	// candidate pair has been found.
	TransportStateCompleted

	// TransportStateFailed indicates the Transport the last
	// candidate was added and all appropriate candidate pairs have either
	// failed connectivity checks or have lost consent.
	TransportStateFailed

	// TransportStateDisconnected indicates the Transport has received
	// at least one local and remote candidate, but the final candidate was
	// received yet and all appropriate candidate pairs thus far have been
	// tested and failed.
	TransportStateDisconnected

	// TransportStateClosed indicates the Transport has shut down
	// and is no longer responding to STUN requests.
	TransportStateClosed
)
View Source
const (
	// Unknown defines default public constant to use for "enum" like struct
	// comparisons when no value was defined.
	Unknown = iota
)

Variables

View Source
var (
	// ErrUnknownType indicates an error with Unknown info.
	ErrUnknownType = errors.New("unknown")

	// ErrNoTurnCredencials indicates that a TURN server URL was provided
	// without required credentials.
	ErrNoTurnCredencials = errors.New("turn server credentials required")

	// ErrTurnCredencials indicates that provided TURN credentials are partial
	// or malformed.
	ErrTurnCredencials = errors.New("invalid turn server credentials")
)

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Foundation     string        `json:"foundation"`
	Priority       uint32        `json:"priority"`
	IP             string        `json:"ip"`
	Protocol       Protocol      `json:"protocol"`
	Port           uint16        `json:"port"`
	Typ            CandidateType `json:"type"`
	Component      uint16        `json:"component"`
	RelatedAddress string        `json:"relatedAddress"`
	RelatedPort    uint16        `json:"relatedPort"`
}

Candidate represents a ice candidate

func (Candidate) String

func (c Candidate) String() string

type CandidateInit

type CandidateInit struct {
	Candidate        string  `json:"candidate"`
	SDPMid           *string `json:"sdpMid,omitempty"`
	SDPMLineIndex    *uint16 `json:"sdpMLineIndex,omitempty"`
	UsernameFragment string  `json:"usernameFragment"`
}

CandidateInit is used to serialize ice candidates

type CandidatePair

type CandidatePair struct {
	Local  *Candidate
	Remote *Candidate
}

CandidatePair represents an ICE Candidate pair

func NewCandidatePair

func NewCandidatePair(local, remote *Candidate) *CandidatePair

NewCandidatePair returns an initialized *CandidatePair for the given pair of Candidate instances

func (*CandidatePair) String

func (p *CandidatePair) String() string

type CandidateType

type CandidateType int

CandidateType represents the type of the ICE candidate used.

const (
	// CandidateTypeHost 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.
	CandidateTypeHost CandidateType = iota + 1

	// CandidateTypeSrflx indicates the 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.
	CandidateTypeSrflx

	// CandidateTypePrflx 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.
	CandidateTypePrflx

	// CandidateTypeRelay indicates the 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.
	CandidateTypeRelay
)

func NewCandidateType

func NewCandidateType(raw string) (CandidateType, error)

NewCandidateType takes a string and converts it into CandidateType

func (CandidateType) String

func (t CandidateType) String() string

type Component

type Component int

Component describes if the ice transport is used for RTP (or RTCP multiplexing).

const (
	// ComponentRTP 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.
	ComponentRTP Component = iota + 1

	// ComponentRTCP indicates that the ICE Transport is used for RTCP as
	// defined by https://tools.ietf.org/html/rfc5245#section-4.1.1.1. This
	// represents the component-id value 2 when encoded in candidate-attribute.
	ComponentRTCP
)

func (Component) String

func (t Component) String() string

type ConnectionState

type ConnectionState int

ConnectionState indicates signaling state of the ICE Connection.

const (
	// ConnectionStateNew 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.
	ConnectionStateNew ConnectionState = iota + 1

	// ConnectionStateChecking indicates that any of the ICETransports
	// are in the "checking" state and none of them are in the "disconnected"
	// or "failed" state.
	ConnectionStateChecking

	// ConnectionStateConnected indicates that all ICETransports are
	// in the "connected", "completed" or "closed" state and at least one of
	// them is in the "connected" state.
	ConnectionStateConnected

	// ConnectionStateCompleted indicates that all ICETransports are
	// in the "completed" or "closed" state and at least one of them is in the
	// "completed" state.
	ConnectionStateCompleted

	// ConnectionStateDisconnected indicates that any of the
	// ICETransports are in the "disconnected" state and none of them are
	// in the "failed" state.
	ConnectionStateDisconnected

	// ConnectionStateFailed indicates that any of the ICETransports
	// are in the "failed" state.
	ConnectionStateFailed

	// ConnectionStateClosed indicates that the PeerConnection's
	// isClosed is true.
	ConnectionStateClosed
)

func NewConnectionState

func NewConnectionState(raw string) ConnectionState

NewConnectionState takes a string and converts it to ConnectionState

func (ConnectionState) String

func (c ConnectionState) String() string

type CredentialType

type CredentialType int

CredentialType indicates the type of credentials used to connect to an ICE server.

const (
	// CredentialTypePassword describes username and pasword based
	// credentials as described in https://tools.ietf.org/html/rfc5389.
	CredentialTypePassword CredentialType = iota

	// CredentialTypeOauth describes token based credential as described
	// in https://tools.ietf.org/html/rfc7635.
	CredentialTypeOauth
)

func (CredentialType) String

func (t CredentialType) String() string

type GatherOptions

type GatherOptions struct {
	ICEServers      []Server
	ICEGatherPolicy TransportPolicy
}

GatherOptions provides options relating to the gathering of ICE candidates.

type GatherPolicy

type GatherPolicy = TransportPolicy

GatherPolicy is the ORTC equivalent of TransportPolicy

type Gatherer

type Gatherer struct {
	// contains filtered or unexported fields
}

Gatherer gathers local host, server reflexive and relay candidates, as well as enabling the retrieval of local Interactive Connectivity Establishment (ICE) parameters which can be exchanged in signaling.

func NewGatherer

func NewGatherer(
	portMin uint16,
	portMax uint16,
	connectionTimeout *time.Duration,
	keepaliveInterval *time.Duration,
	loggerFactory logging.LoggerFactory,
	networkTypes []NetworkType,
	opts GatherOptions,
) (*Gatherer, error)

NewGatherer creates a new Gatherer.

func (*Gatherer) AgentIsTrickle

func (g *Gatherer) AgentIsTrickle() bool

AgentIsTrickle returns true if agent is in trickle mode.

func (*Gatherer) Close

func (g *Gatherer) Close() error

Close prunes all local candidates, and closes the ports.

func (*Gatherer) Gather

func (g *Gatherer) Gather() error

Gather ICE candidates.

func (*Gatherer) GetLocalCandidates

func (g *Gatherer) GetLocalCandidates() ([]Candidate, error)

GetLocalCandidates returns the sequence of valid local candidates associated with the Gatherer.

func (*Gatherer) GetLocalParameters

func (g *Gatherer) GetLocalParameters() (Parameters, error)

GetLocalParameters returns the ICE parameters of the Gatherer.

func (*Gatherer) OnLocalCandidate

func (g *Gatherer) OnLocalCandidate(f func(*Candidate))

OnLocalCandidate sets an event handler which fires when a new local ICE candidate is available

func (*Gatherer) OnStateChange

func (g *Gatherer) OnStateChange(f func(GathererState))

OnStateChange fires any time the Gatherer changes

func (*Gatherer) State

func (g *Gatherer) State() GathererState

State indicates the current state of the ICE gatherer.

type GathererState

type GathererState byte

GathererState represents the current state of the ICE gatherer.

const (
	// GathererStateNew indicates object has been created but
	// gather() has not been called.
	GathererStateNew GathererState = iota + 1

	// GathererStateGathering indicates gather() has been called,
	// and the Gatherer is in the process of gathering candidates.
	GathererStateGathering

	// GathererStateComplete indicates the Gatherer has completed gathering.
	GathererStateComplete

	// GathererStateClosed indicates the closed state can only be entered
	// when the Gatherer has been closed intentionally by calling close().
	GathererStateClosed
)

func (GathererState) String

func (s GathererState) String() string

type GatheringState

type GatheringState int

GatheringState describes the state of the candidate gathering process.

const (
	// GatheringStateNew 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.
	GatheringStateNew GatheringState = iota + 1

	// GatheringStateGathering indicates that any of the ICETransports
	// are in the "gathering" state.
	GatheringStateGathering

	// GatheringStateComplete indicates that at least one Transport
	// exists, and all ICETransports are in the "completed" gathering state.
	GatheringStateComplete
)

func NewGatheringState

func NewGatheringState(raw string) GatheringState

NewGatheringState takes a string and converts it to GatheringState

func (GatheringState) String

func (t GatheringState) String() string

type NetworkType

type NetworkType int

NetworkType represents the type of network

const (
	// NetworkTypeUDP4 indicates UDP over IPv4.
	NetworkTypeUDP4 NetworkType = iota + 1

	// NetworkTypeUDP6 indicates UDP over IPv6.
	NetworkTypeUDP6

	// NetworkTypeTCP4 indicates TCP over IPv4.
	NetworkTypeTCP4

	// NetworkTypeTCP6 indicates TCP over IPv6.
	NetworkTypeTCP6
)

func (NetworkType) String

func (t NetworkType) String() string

type OAuthCredential

type OAuthCredential struct {
	// MACKey is a base64-url encoded format. It is used in STUN message
	// integrity hash calculation.
	MACKey string

	// AccessToken is a base64-encoded format. This is an encrypted
	// self-contained token that is opaque to the application.
	AccessToken string
}

OAuthCredential represents OAuth credential information which is used by the STUN/TURN client to connect to an ICE server as defined in https://tools.ietf.org/html/rfc7635. Note that the kid parameter is not located in OAuthCredential, but in Server's username member.

type Parameters

type Parameters struct {
	UsernameFragment string `json:"usernameFragment"`
	Password         string `json:"password"`
	ICELite          bool   `json:"iceLite"`
}

Parameters includes the ICE username fragment and password and other ICE-related parameters.

type Protocol

type Protocol int

Protocol indicates the transport protocol type that is used in the ice.URL structure.

const (
	// ProtocolUDP indicates the URL uses a UDP transport.
	ProtocolUDP Protocol = iota + 1

	// ProtocolTCP indicates the URL uses a TCP transport.
	ProtocolTCP
)

func NewProtocol

func NewProtocol(raw string) (Protocol, error)

NewProtocol takes a string and converts it to Protocol

func (Protocol) String

func (t Protocol) String() string

type Role

type Role int

Role describes the role ice.Agent is playing in selecting the preferred the candidate pair.

const (
	// RoleControlling indicates that the ICE agent that is responsible
	// for selecting the final choice of candidate pairs and signaling them
	// through STUN and an updated offer, if needed. In any session, one agent
	// is always controlling. The other is the controlled agent.
	RoleControlling Role = iota + 1

	// RoleControlled indicates that an ICE agent that waits for the
	// controlling agent to select the final choice of candidate pairs.
	RoleControlled
)

func (Role) String

func (t Role) String() string

type Server

type Server struct {
	URLs           []string
	Username       string
	Credential     interface{}
	CredentialType CredentialType
}

Server describes a single STUN and TURN server that can be used by the ICEAgent to establish a connection with a peer.

func (Server) Validate

func (s Server) Validate() error

Validate checks if the Server struct is valid

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport allows an application access to information about the ICE transport over which packets are sent and received.

func NewTransport

func NewTransport(gatherer *Gatherer, loggerFactory logging.LoggerFactory) *Transport

NewTransport creates a new NewTransport.

func (*Transport) AddRemoteCandidate

func (t *Transport) AddRemoteCandidate(remoteCandidate Candidate) error

AddRemoteCandidate adds a candidate associated with the remote Transport.

func (*Transport) NewEndpoint

func (t *Transport) NewEndpoint(f mux.MatchFunc) *mux.Endpoint

NewEndpoint registers a new endpoint on the underlying mux.

func (*Transport) OnConnectionStateChange

func (t *Transport) OnConnectionStateChange(f func(TransportState))

OnConnectionStateChange sets a handler that is fired when the ICE connection state changes.

func (*Transport) OnSelectedCandidatePairChange

func (t *Transport) OnSelectedCandidatePairChange(f func(*CandidatePair))

OnSelectedCandidatePairChange sets a handler that is invoked when a new ICE candidate pair is selected

func (*Transport) Role

func (t *Transport) Role() Role

Role indicates the current role of the ICE transport.

func (*Transport) SetRemoteCandidates

func (t *Transport) SetRemoteCandidates(remoteCandidates []Candidate) error

SetRemoteCandidates sets the sequence of candidates associated with the remote Transport.

func (*Transport) Start

func (t *Transport) Start(gatherer *Gatherer, params Parameters, role *Role) error

Start incoming connectivity checks based on its configured role.

func (*Transport) State

func (t *Transport) State() TransportState

State returns the current ice transport state.

func (*Transport) Stop

func (t *Transport) Stop() error

Stop irreversibly stops the Transport.

type TransportPolicy

type TransportPolicy int

TransportPolicy defines the ICE candidate policy surface the permitted candidates. Only these candidates are used for connectivity checks.

const (
	// TransportPolicyAll indicates any type of candidate is used.
	TransportPolicyAll TransportPolicy = iota

	// TransportPolicyRelay indicates only media relay candidates such
	// as candidates passing through a TURN server are used.
	TransportPolicyRelay
)

func NewTransportPolicy

func NewTransportPolicy(raw string) TransportPolicy

NewTransportPolicy takes a string and converts it to TransportPolicy

func (TransportPolicy) String

func (t TransportPolicy) String() string

type TransportState

type TransportState int

TransportState represents the current state of the ICE transport.

func (TransportState) String

func (c TransportState) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL