Documentation ¶
Index ¶
- Constants
- Variables
- type ConnectionInfo
- type DatachannelToRelayPipeMetadata
- type RelayGRPCServer
- func (r *RelayGRPCServer) CallPeer(ctx context.Context, req *proto.CallRequest) (*proto.CallResponse, error)
- func (r *RelayGRPCServer) ConnectToPeer(ctx context.Context, req *proto.ConnectionRequest) (*proto.ConnectionResponse, error)
- func (r *RelayGRPCServer) DisconnectFromPeer(context.Context, *proto.ConnectionRequest) (*proto.ConnectionResponse, error)
- func (r *RelayGRPCServer) GetEventStream(req *proto.EventStreamRequest, stream proto.WebRTCRelay_GetEventStreamServer) error
- func (r *RelayGRPCServer) HangupPeer(context.Context, *proto.ConnectionRequest) (*proto.CallResponse, error)
- func (r *RelayGRPCServer) SendMsg(context.Context, *proto.SendMsgRequest) (*proto.SendMsgResponse, error)
- func (r *RelayGRPCServer) SendMsgStream(msgStream proto.WebRTCRelay_SendMsgStreamServer) error
- type RelayPeer
- func (p *RelayPeer) BlockUntilPeerStateChange() string
- func (p *RelayPeer) CallPeer(peerId string, track webrtc.TrackLocal, opts *peerjs.ConnectionOptions, ...) (*peerjs.MediaConnection, error)
- func (p *RelayPeer) Cleanup()
- func (p *RelayPeer) ConnectToPeer(peerId string, opts *peerjs.ConnectionOptions, exchangeId uint32) (*peerjs.DataConnection, error)
- func (p *RelayPeer) DisconnectFromPeer(peerId string) (error, error)
- func (p *RelayPeer) GetCurrentPeer() *peerjs.Peer
- func (p *RelayPeer) GetDataConnection(peerId string) *peerjs.DataConnection
- func (p *RelayPeer) GetMediaConnection(peerId string) *peerjs.MediaConnection
- func (p *RelayPeer) GetOpenDataConnections() map[string]openDataConnection
- func (p *RelayPeer) GetOpenMediaConnections() map[string]openMediaConnection
- func (p *RelayPeer) GetPeerId() string
- func (p *RelayPeer) GetRelayPeerId() string
- func (p *RelayPeer) GetSavedExchangeId() uint32
- func (p *RelayPeer) IncrementErrorCount()
- func (p *RelayPeer) SetSavedExchangeId(exchangeId uint32)
- func (p *RelayPeer) Start(onConnection func(*peerjs.DataConnection, uint32), ...) error
- type RelayPipeToDatachannelMetadata
- type TokenPersistanceStore
- type WebrtcConnectionCtrl
- type WebrtcRelay
- func (relay *WebrtcRelay) AddMediaTrackRawSource(trackName string) error
- func (relay *WebrtcRelay) AddMediaTrackRtpSource(track *proto.TrackInfo) error
- func (relay *WebrtcRelay) AddMediaTrackToCalls(targetPeerIds []string, relayPeerNumber uint32, newTrack *proto.TrackInfo, ...) error
- func (relay *WebrtcRelay) AutoCall(targetPeerId string)
- func (relay *WebrtcRelay) CallPeers(targetPeerIds []string, relayPeerNumber uint32, tracks []*proto.TrackInfo, ...) error
- func (relay *WebrtcRelay) CloseEventStream(evtStreamChan *<-chan *proto.RelayEventStream)
- func (relay *WebrtcRelay) ConnectToPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
- func (relay *WebrtcRelay) DisconnectFromPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
- func (relay *WebrtcRelay) GetEventStream() <-chan *proto.RelayEventStream
- func (relay *WebrtcRelay) HangupPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
- func (relay *WebrtcRelay) ReplaceMediaTrackInCalls(targetPeerIds []string, relayPeerNumber uint32, trackNameToReplace string, ...) error
- func (relay *WebrtcRelay) ReplaceMediaTrackSource(trackNameToReplace string, newTrack *proto.TrackInfo, exchangeId uint32) error
- func (relay *WebrtcRelay) SendMsg(targetPeerIds []string, msgPayload []byte, relayPeerNumber uint32, ...)
- func (relay *WebrtcRelay) Start()
- func (relay *WebrtcRelay) Stop()
Constants ¶
const ( RELAY_PEER_CONNECTED = "connected" RELAY_PEER_CONNECTING = "connecting" RELAY_PEER_RECONNECTING = "reconnecting" RELAY_PEER_DISCONNECTED = "disconnected" RELAY_PEER_DESTROYED = "destroyed" )
const ALL_RELAY_PEERS uint32 = 0
Variables ¶
var FATAL_PEER_ERROR_TYPES = []string{"network", "unavailable-id", "invalid-id", "invalid-key", "browser-incompatible", "webrtc", "server-error", "ssl-unavailable", "socket-error", "socket-closed"}
FATAL_PEER_ERROR_TYPES is a list of peer error types that the peerjs-go module can throw which should be handled by closing the peer and restarting the whole peer init -> peer server -> peer conection process.
Functions ¶
This section is empty.
Types ¶
type ConnectionInfo ¶
type ConnectionInfo struct { RelayPeer *RelayPeer DataConnection *peerjs.DataConnection MediaConnection *peerjs.MediaConnection TargetPeerId string }
type DatachannelToRelayPipeMetadata ¶
type DatachannelToRelayPipeMetadata struct { // PeerId is the peerjs ID of the sender browser peer. SrcPeerId string `json:"SrcPeerId,omitempty"` // Whenever a peer connects or disconnects this will be "connect" or "disconnect" with the connected or disconnected peer set in SrcPeerId PeerEvent string `json:"PeerEvent,omitempty"` // Err is the error message if there was an error with the previous metadata action command recived on the unix socket. Err string `json:"Err,omitempty"` }
DatachannelToRelayPipeMetadata is prepended (as a JSON string) to messages sent to your program through the named pipe message relay (when AddMetadataToBackendMessages config is True)
type RelayGRPCServer ¶
type RelayGRPCServer struct { proto.UnimplementedWebRTCRelayServer // contains filtered or unexported fields }
func (*RelayGRPCServer) CallPeer ¶
func (r *RelayGRPCServer) CallPeer(ctx context.Context, req *proto.CallRequest) (*proto.CallResponse, error)
func (*RelayGRPCServer) ConnectToPeer ¶
func (r *RelayGRPCServer) ConnectToPeer(ctx context.Context, req *proto.ConnectionRequest) (*proto.ConnectionResponse, error)
func (*RelayGRPCServer) DisconnectFromPeer ¶
func (r *RelayGRPCServer) DisconnectFromPeer(context.Context, *proto.ConnectionRequest) (*proto.ConnectionResponse, error)
func (*RelayGRPCServer) GetEventStream ¶
func (r *RelayGRPCServer) GetEventStream(req *proto.EventStreamRequest, stream proto.WebRTCRelay_GetEventStreamServer) error
func (*RelayGRPCServer) HangupPeer ¶
func (r *RelayGRPCServer) HangupPeer(context.Context, *proto.ConnectionRequest) (*proto.CallResponse, error)
func (*RelayGRPCServer) SendMsg ¶
func (r *RelayGRPCServer) SendMsg(context.Context, *proto.SendMsgRequest) (*proto.SendMsgResponse, error)
func (*RelayGRPCServer) SendMsgStream ¶
func (r *RelayGRPCServer) SendMsgStream(msgStream proto.WebRTCRelay_SendMsgStreamServer) error
type RelayPeer ¶
type RelayPeer struct {
// contains filtered or unexported fields
}
RelayPeer represents a peerjs instance used by this relay.
func NewRelayPeer ¶
func NewRelayPeer(connCtrl *WebrtcConnectionCtrl, peerConfig peerjs.Options, startingEndNumber uint32, relayPeerNumber uint32) *RelayPeer
NewRelayPeer creates a new RelayPeer instance.
func (*RelayPeer) BlockUntilPeerStateChange ¶
func (*RelayPeer) CallPeer ¶
func (p *RelayPeer) CallPeer(peerId string, track webrtc.TrackLocal, opts *peerjs.ConnectionOptions, exchangeId uint32) (*peerjs.MediaConnection, error)
func (*RelayPeer) ConnectToPeer ¶
func (p *RelayPeer) ConnectToPeer(peerId string, opts *peerjs.ConnectionOptions, exchangeId uint32) (*peerjs.DataConnection, error)
func (*RelayPeer) DisconnectFromPeer ¶
func (*RelayPeer) GetCurrentPeer ¶
func (*RelayPeer) GetDataConnection ¶
func (p *RelayPeer) GetDataConnection(peerId string) *peerjs.DataConnection
func (*RelayPeer) GetMediaConnection ¶
func (p *RelayPeer) GetMediaConnection(peerId string) *peerjs.MediaConnection
func (*RelayPeer) GetOpenDataConnections ¶
func (*RelayPeer) GetOpenMediaConnections ¶
func (*RelayPeer) GetRelayPeerId ¶
func (*RelayPeer) GetSavedExchangeId ¶
func (*RelayPeer) IncrementErrorCount ¶
func (p *RelayPeer) IncrementErrorCount()
func (*RelayPeer) SetSavedExchangeId ¶
type RelayPipeToDatachannelMetadata ¶
type RelayPipeToDatachannelMetadata struct { // TargetPeerIds is the list of peerjs peers (by peer id) this mesage should be sent to. An empty list means broadcast mesage to all connected peers. TargetPeerIds []string `json:"TargetPeerIds,omitempty"` // An action to be performed by this go code. Options are currently: "Media_Call_Peer" Action string `json:"Action,omitempty"` // Parameters used by the Action. // - When Action is "Media_Call_Peer": This param is an array in the following format ["stream name", "media MIME type eg: video/h264", "filename of media source pipe in the configured NamedPipeFolder eg: lowRezFrontCameraH264.pipe"] Params []string `json:"Params,omitempty"` }
RelayPipeToDatachannelMetadata is what is expected to be prepended (as JSON followed by the MessageMetadataSeparator string) to messages recived from your program through the named pipe message relay (when AddMetadataToBackendMessages config is True)
type TokenPersistanceStore ¶
type TokenPersistanceStore struct {
// contains filtered or unexported fields
}
func NewTokenPersistanceStore ¶
func NewTokenPersistanceStore(tokenStoreFilePath string, log *log.Logger) *TokenPersistanceStore
NewTokenPersistanceStore: Creates a new TokenPersistanceStore tps.tokenStoreFilePath
func (*TokenPersistanceStore) DiscardToken ¶
func (tps *TokenPersistanceStore) DiscardToken(peerId string) error
func (*TokenPersistanceStore) GetToken ¶
func (tps *TokenPersistanceStore) GetToken(peerId string) string
GetToken: Loads the token corresponding to the passed peerId from the json TokenPersistanceStore or creates and saves a new one if no token exists for that peer id
type WebrtcConnectionCtrl ¶
type WebrtcConnectionCtrl struct { // map of relayPeers owned by this WebrtcConnectionCtrl (key is the RelayPeerNumber specified in the peerInitConfig or when calling addRelayPeer()) RelayPeers map[uint32]*RelayPeer // contains filtered or unexported fields }
WebrtcConnectionCtrl: This is the main controller in charge of maintaining an open peer and accepting/connecting to other peers. While the fields here are public, they are NOT meant to be modified by the user, do so at your own risk.
func NewWebrtcConnectionCtrl ¶
func NewWebrtcConnectionCtrl(eventStream *util.EventSub[proto.RelayEventStream], config relay_config.WebrtcRelayConfig, logger *log.Logger) *WebrtcConnectionCtrl
func (*WebrtcConnectionCtrl) AddRelayPeer ¶
func (conn *WebrtcConnectionCtrl) AddRelayPeer(opts *relay_config.PeerInitOptions, exchangeId uint32)
AddRelayPeer creates a new peerjs peer and connects it to the specified peer server based on the passed config the peer will get added to the list of peers that this connection controller is managing. call stopRelayPeer() to stop the peer.
func (*WebrtcConnectionCtrl) StopRelayPeer ¶
func (conn *WebrtcConnectionCtrl) StopRelayPeer(relayPeerNumber uint32, exchangeId uint32)
StopRelayPeer: stops the relay peer with the specified relayPeerNumber and removes it from the list of peers this connection controller is managing.
type WebrtcRelay ¶
type WebrtcRelay struct { // Log: The logrus logger to use for debug logs within WebrtcRelay Code Log *log.Entry // contains filtered or unexported fields }
func NewWebrtcRelay ¶
func NewWebrtcRelay(config wrConfig.WebrtcRelayConfig) *WebrtcRelay
Creates a new webrtc-relay instance. Call Start() to start the relay.
Param config (WebrtcRelayConfig): The config options for the webrtc-relay including any relayPeers to start when Start() is run (peerInitOptions)
example:
import relay "github.com/kw-m/webrtc-relay/pkg" import relay_config "github.com/kw-m/webrtc-relay/pkg/config" relay.NewWebrtcRelay(relay_config.GetDefaultRelayConfig())
func (*WebrtcRelay) AddMediaTrackRawSource ¶
func (relay *WebrtcRelay) AddMediaTrackRawSource(trackName string) error
AddMediaTrackRawSource: Add a new pion-webrtc media track source to the relay media contoller to be used in media calls (does not start a call) TODO Fix docs! can be called again with the same peerid and stream name to add aditional tracks (audio/video) can be called again with the same peerid, stream name and trackName to replace the track (pass an empty rtpSourceUrl to stop the track) Param targetPeerIds ([]string): The peerIds of the peers to call or []string{"*"} to call all peers Param relayPeerNumber (int): The relayPeerNumber of the relay peer you want to close the connection on (if 0, every RelayPeer will attempt to connect to the peer in parallel) Param trackName (string): The name of the track within the stream we are adding / replacing Param rtpSourceUrl (string): The url of the rtp source to use for the track (empty string will stop the track if it exists)
func (*WebrtcRelay) AddMediaTrackRtpSource ¶
func (relay *WebrtcRelay) AddMediaTrackRtpSource(track *proto.TrackInfo) error
AddMediaTrackRtpSource: Adds a new rtp-based media track source to the media controller to be used in media calls (does not start a call)
func (*WebrtcRelay) AddMediaTrackToCalls ¶
func (relay *WebrtcRelay) AddMediaTrackToCalls(targetPeerIds []string, relayPeerNumber uint32, newTrack *proto.TrackInfo, exchangeId uint32) error
AddMediaTrackToCalls: Calls a peerjs peer with a pion media track object
func (*WebrtcRelay) AutoCall ¶
func (relay *WebrtcRelay) AutoCall(targetPeerId string)
func (*WebrtcRelay) CallPeers ¶
func (relay *WebrtcRelay) CallPeers(targetPeerIds []string, relayPeerNumber uint32, tracks []*proto.TrackInfo, exchangeId uint32) error
CallPeer: Calls one or more peerjs peers with a media channel/stream containing one or more tracks (audio or video) Param targetPeerIds ([]string): The peerIds of the peers to call or []string{"*"} to call all peers Param relayPeerNumber (int): The relayPeerNumber of the relay peer you want to close the connection on (if 0, every RelayPeer will attempt to connect to the peer in parallel) DEPRECATED Param streamId (string): The name of the media channel/stream (must be unique per peer connection) Param tracks (trackInfo): The details of the tracks to put in the media call. Param exchangeId (uint32): The exchangeId to
func (*WebrtcRelay) CloseEventStream ¶
func (relay *WebrtcRelay) CloseEventStream(evtStreamChan *<-chan *proto.RelayEventStream)
func (*WebrtcRelay) ConnectToPeer ¶
func (relay *WebrtcRelay) ConnectToPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
ConnectToPeer: Attempts to connect to a peerjs peer Param peerId (string): The peerId of the peer to connect to Param relayPeerNumber (int): The relayPeerNumber to use for the connection (if 0, every RelayPeer will attempt to connect to the peer in parallel)
func (*WebrtcRelay) DisconnectFromPeer ¶
func (relay *WebrtcRelay) DisconnectFromPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
DisconnectFromPeer: Closes the connection with a peer Param peerId (string): The peerId of the peer to disconnect from Param relayPeerNumber (int): The relayPeerNumber of the relay peer you want to close the connection on (if 0, every RelayPeer will attempt to connect to the peer in parallel)
func (*WebrtcRelay) GetEventStream ¶
func (relay *WebrtcRelay) GetEventStream() <-chan *proto.RelayEventStream
func (*WebrtcRelay) HangupPeer ¶
func (relay *WebrtcRelay) HangupPeer(peerId string, relayPeerNumber uint32, exchangeId uint32)
HangupPeer: Closes the media call with a peerjs peer Param peerId (string): The peerId of the peer to hangup
func (*WebrtcRelay) ReplaceMediaTrackInCalls ¶
func (relay *WebrtcRelay) ReplaceMediaTrackInCalls(targetPeerIds []string, relayPeerNumber uint32, trackNameToReplace string, newTrack *proto.TrackInfo, exchangeId uint32) error
ReplaceMediaTrackInCalls: Calls a peerjs peer with a pion media track object
func (*WebrtcRelay) ReplaceMediaTrackSource ¶
func (relay *WebrtcRelay) ReplaceMediaTrackSource(trackNameToReplace string, newTrack *proto.TrackInfo, exchangeId uint32) error
ReplaceMediaTrackSource: Replaces a media track source with a new one in the media contoller TODO: will cause all peer connections using this media track to switch to the new track (possibly renegotiate?)
func (*WebrtcRelay) SendMsg ¶
func (relay *WebrtcRelay) SendMsg(targetPeerIds []string, msgPayload []byte, relayPeerNumber uint32, exchangeId uint32)
SendMsg: Sends a message to one or more peerjs peer(s)
func (*WebrtcRelay) Stop ¶
func (relay *WebrtcRelay) Stop()
Stops & cleans up the webrtc-relay (non-blocking)