-
Notifications
You must be signed in to change notification settings - Fork 1.7k
TransportDesign
Concurrency/Race issues -- Golang provides an excellent API for sharing data between threads (channels) and we aren't taking advantage of them at all. There is a big mental burden (and chance of error) by locking/unlocking in the networkManager.
Maintainability -- people find the current design confusing. Would prefer more clear boundaries between components. This would also look like the ECMAScript WebRTC API. However, they have zero relation. This is internal to pion-WebRTC and has no effect on a user.
Callback heavy -- Everytime we want to add new features we add a new callback, and it is making things cumbersome
Manages all network traffic. To send a packet call a method on the networkManager.
Responding to an inbound packet is done via callbacks. When you create a networkManager we have multiple distinct callbacks for events (RTP, SCTP, ICE etc..)
Handles ICE status. NetworkManager pushes packets on it, and uses callbacks when it wants to send traffic.
Handles encryption for SCTP packets, and DTLS handshake. NetworkManager pushes packets on it, and uses callbacks when it wants to send traffic.
Protocol used by DataChannels. NetworkManager pushes packets on it, and uses callbacks when it wants to send traffic.
Used for Encrypting/Decrypting audio/video data. This is used by the NetworkManager directly, it isn't async so provides simple Encrypt/Decrypt blocking APIs
The new API is designed to take advantage of Go channels, and copies the paradigm of 'Transport Chaining'
A new package will be created internal/transport
, this package will contain chainable transports that all inherit from a generic
interface. Transports that that implement it will also add their own generic APIs, but MUST be MT safe.
type Transport interface {
// Stop tears down the transport, cleaning up any state.
Stop()
// Start the transport, passing any linked Transports
Start(Transport...) error
// Send pushes data to the transport and takes ownership
Send(interface{}) error
// Recv pulls data from the transport, puller takes ownership
Recv() (interface{}, error)
}
With the following instances
- internal/Transport.ICE
- internal/Transport.DTLS
- internal/Transport.SCTP
- internal/Transport.SRTP
package webrtc
type RTCPeerConnection struct {
iceTransport *Transport.ICE
dtlsTransport *Transport.DTLS
sctpTransport *Transport.SCTP
srtpTransport *Transport.SRTP
}
// Not a real API call, just an example starting transports for an RTCPeerConnection
func (r *RTCPeerConnection) Start() {
dtlsTransport.Start(iceTransport, srtpTransport, sctpTransport)
iceTransport.Start(dtlsTransport, srtpTransport)
srtpTransport.Start(iceTransport)
sctpTransport.Start(dtlsTransport)
go func() {
rtpPacket, err := srtpTransport.Recv()
// Distribute packet to user, we will also do the same for SCTP (distributing message to proper DataChannel
}()
// Not a real API call, just an example of sending a packet
func (r *RTCPeerConnection) SendRTPPacket(p *rtp.Packet) {
r.srtpTransport.Send(p)
}
Sign up for the Golang Slack and join the #pion channel for discussions and support
If you need commercial support/don't want to use public methods you can contact us at [email protected]