Documentation
¶
Overview ¶
Package campfire implements the "camp fire" protocol.
Index ¶
Constants ¶
const PSKSize = 32
PSKSize is the size of the PSK in bytes.
const Protocol = "/webmesh/campfire/1.0.0"
Protocol is the campfire protocol.
Variables ¶
var Now = time.Now
Now is the current time. It is a variable so it can be mocked out in tests.
Functions ¶
func GetDefaultTURNServers ¶
func GetDefaultTURNServers() []string
GetDefaultTURNServers returns the default list of TURN servers.
Types ¶
type CampFire ¶
type CampFire struct {
// contains filtered or unexported fields
}
CampFire is a connection to one or more peers sharing the same pre-shared key.
func Join ¶
func Join(ctx context.Context, room WaitingRoom) *CampFire
Join joins a camp fire with the given pre-shared key on the list of turn servers.
func (*CampFire) Accept ¶
func (cf *CampFire) Accept() (datachannel.ReadWriteCloser, error)
type Location ¶
type Location struct {
// Secret is the computed ID from the PSK.
Secret string
// TURNServer is the selected TURN server.
TURNServer string
// ExpiresAt is the time at which the campfire expires.
ExpiresAt time.Time
}
Location is the secret and location of a campfire.
type Message ¶
type Message struct {
// Type is the type of message.
Type MessageType
// Candidate is an ICE candidate.
Candidate string
// SDP is an SDP offer or answer.
SDP string
}
Message is a campfire message.
func NewCandidateMessage ¶
NewCandidateMessage creates a new candidate message.
func NewSDPMessage ¶
NewSDPMessage creates a new SDP message.
func (Message) UnmarshalSDP ¶
UnmarshalSDP unmarshals the SDP into a SessionDescription.
type MessageType ¶
type MessageType int
MessageType indicates the type of message sent to a peer in a waiting room.
const ( // CandidateMessageType is a message containing an ICE candidate. CandidateMessageType MessageType = iota // SDPMessageType is a message containing an SDP offer or answer. SDPMessageType )
type Options ¶
type Options struct {
// PSK is the pre-shared key.
PSK []byte
// TURNServers is an optional list of turn servers to use.
TURNServers []string
}
Options are options for creating or joining a new camp fire.
type Stream ¶
type Stream interface {
// PeerID returns the peer ID of the remote peer.
PeerID() string
// SendCandidate sends an ICE candidate on the stream.
// This is a convenience method for sending a Candidate message.
SendCandidate(candidate string) error
// SendOffer sends an SDP offer on the stream.
// This is a convenience method for sending an SDP message.
SendOffer(offer webrtc.SessionDescription) error
// Receive receives a message from the stream.
Receive() (Message, error)
// Close closes the stream.
Close() error
}
Stream is a campfire stream.
type WaitingRoom ¶
type WaitingRoom interface {
// Connetions returns a channel that receives new incoming connections.
Connections() <-chan Stream
// Peers returns a channel that receives new peers that have joined the
// campfire. A new stream to the peer is opened for each peer and sent
// on the channel.
Peers() <-chan Stream
// Location returns the location of the campfire.
Location() *Location
// Errors returns a channel that receives errors.
Errors() <-chan error
// Close closes the waiting room.
Close() error
}
WaitingRoom is an interface for a waiting for others to join the campfire.