Documentation
¶
Index ¶
- Constants
- type Peer
- func (peer *Peer) Close()
- func (core Peer) GetContext() context.Context
- func (peer *Peer) GetDeviceProperties() audiodevice.DeviceProperties
- func (peer *Peer) GetStream() <-chan frame.PCMFrame
- func (core Peer) Identifier() signalling.PeerIdentifier
- func (peer *Peer) SetStream(sourceChannel <-chan frame.PCMFrame)
- type PeerFactory
Constants ¶
const (
HEARTBEAT_PERIOD time.Duration = 5 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
The logical representation of a connected peer across the network.
This struct is a wrapper peerCore (handling the actual connection) and channels in/out to handle audio from this client and the remote client.
A Peer object should not be constructed directly. Instead, use a connectionManager with the corresponding Dial and ListenForConnection methods, which in turn call the injected PeerFactory methods NewOfferingPeer and NewAnsweringPeer methods respectively.
The PeerFactory constructs a peerCore, which then waits to be fully connected (failed connections are closed gracefully) before being wrapped into a Peer, which finally are passed back to the connectionManager to be sent along the ConnectedPeerChannel, ready for processing by the application.
func (*Peer) Close ¶
func (peer *Peer) Close()
Shutdown this peer. Handles disconnecting to remote peer and stopping streams. Also called the peer.ctx cancel function, so peer.ctx.Done() will signal.
This function is idempotent.
Shadow of the peerCore method
func (Peer) GetContext ¶
Get the context of this peer May be used to determine if the peer is shutting down by listening for <-ctx.Done()
func (*Peer) GetDeviceProperties ¶
func (peer *Peer) GetDeviceProperties() audiodevice.DeviceProperties
The DeviceProperties of a Peer define both the source and sink properties. That is, the audio properties being sent to the peer (to be forwarded across the network) match the audio properties being received by the peer. Both of these values are determined by the negotiated codec.
func (*Peer) GetStream ¶
Get the audioSourceChannel of this peer. The returned channel produces raw PCM Frames from the remote peer.
When this peer is shutdown, the given channel is closed (hence, no data is to be sent on it anymore)
func (Peer) Identifier ¶
func (core Peer) Identifier() signalling.PeerIdentifier
type PeerFactory ¶
type PeerFactory struct {
// contains filtered or unexported fields
}
func NewPeerFactory ¶
func NewPeerFactory( audioTrackRTPCodecCapability webrtc.RTPCodecCapability, opusFactory encoderdecoder.OpusFactory, logger *slog.Logger, ) *PeerFactory
Create a new PeerFactory.
audioTrackRTPCodecCapability defines the preferred configuration to use for all audio tracks created on peer connections. See https://github.com/pion/webrtc for details on these options. Valid codecs are defined in github.com/Honorable-Knights-of-the-Roundtable/Roundtable/internal/networking/codecs.go
logger allows for a child logger to be used specifically for this client. Create a child logger like: ```go childLogger := slog.Default().With(
slog.Group("PeerFactory"),
) ``` If no logger is given, slog.Default() is used.
func (*PeerFactory) NewAnsweringPeer ¶
func (factory *PeerFactory) NewAnsweringPeer( identifier signalling.PeerIdentifier, connection *webrtc.PeerConnection, onConnectedCallback func(*Peer), ) error
Handle creation of a new peer on the answering side of the connection.
Takes a created (but not processed) *webrtc.PeerConnection, and adds an outgoing audio track. The heartbeat channel is made by the offering peer.
If anything goes wrong, this method returns a nil Peer and a non-nil error.
func (*PeerFactory) NewOfferingPeer ¶
func (factory *PeerFactory) NewOfferingPeer( identifier signalling.PeerIdentifier, connection *webrtc.PeerConnection, onConnectedCallback func(*Peer), ) error
Handle creation of a new peer on the offering side of the connection.
Takes a created (but not processed) *webrtc.PeerConnection, and adds heartbeat and outgoing audio track.
The given identifier is to represent the *remote* peer, not the local peer.
If anything goes wrong, this method returns a nil Peer and a non-nil error.