Pion SFU is a server for transmitting video and audio in real time using WebRTC technologies. This SFU (Selective Forwarding Unit) is designed to provide high-quality video and audio conferencing, providing efficient and scalable solution.
The Peer structure is an implementation of the PeerInterface interface and is used to manage the WebRTC connection, process offers and answers, and adding and deleting remote media tracks. Each Peer instance is associated with a unique identifier (id) and provides secure multithreaded communication using a mutex.
type PeerInterface interface {
SetSocket(ws_conn *websocket.Conn)
AddRemoteTrack(track *webrtc.TrackRemote)
RemoveRemoteTrack(track *webrtc.TrackRemote)
SetPeerConnection(conn *webrtc.PeerConnection)
ReactOnOffer(offer webrtc.SessionDescription)
}type Peer struct {
id string
connection *webrtc.PeerConnection
streams map[string]*webrtc.TrackRemote
mutex sync.RWMutex
socket *websocket.Conn
}The Room structure represents the room object that manages the connection and media tracks for participants. It implements the Session interface and provides methods for adding and deleting participants, as well as processing media tracks. The Signal method is used for synchronization state of the room with the state of all participants.
type Session interface {
JoinRoom(id string)
AddPeer(peer *Peer)
RemovePeer(peer_id string)
AddTrack(track *webrtc.TrackRemote)
RemoveTrack(track *webrtc.TrackRemote)
SendAnswer(message webrtc.SessionDescription, peer_id string)
Signal()
}type Room struct {
id string
mutex sync.RWMutex
peers map[string]*Peer
tracks map[string]*webrtc.TrackLocalStaticRTP
} The Coordinator structure is a coordinator for managing rooms (Room). Implements Lobby interface and provides methods for creating, deleting rooms, adding and removing users from the room. The ObtainEvent method is used to handle events from WebSocket such as attach to the room, disconnecting, transmitting proposals and responses, and ICE candidates.
type Lobby interface {
CreateRoom(id string)
RemoveRoom(id string)
AddUserToRoom(self_id string, room_id string, socket *websocket.Conn)
RemoveUserFromRoom(self_id string, room_id string, socket *websocket.Conn)
}type Coordinator struct {
sessioins map[string]*Room
}Trickle ICE is the process of sharing addresses as soon as they are gathered. This parallelizes establishing a connection with a remote peer and starting sessions with TURN servers. Using Trickle ICE can dramatically reduce the amount of time it takes to establish a WebRTC connection.
Trickle ICE isn't mandatory to use, but highly recommended.
Renegotiation in the Twenties WebRTC Represents Process Changes connection parameters between participants in a communication session. This may include includes adding or removing media streams, changing codecs, as well as security options such as the use of encryption.
The renegotiation process is usually initiated by one of the session participants, who wants to make changes to the present connection. This can lead to for various reasons such as adding a new component, changing quality transfer or connection of a new device.
docker build -t <your image name>
docker run -p 8080:8080 <your image name>