pion / webrtc

Pure Go implementation of the WebRTC API
https://pion.ly
MIT License
13.41k stars 1.63k forks source link

Improve pluggability and testability across pion modules though Interfaces #2694

Open enobufs opened 6 months ago

enobufs commented 6 months ago

Summary

This is a pion/webrtc v4 item. We'd like to use interfaces between pion modules as much as possible to provide users with true pluggability. To achieve this, we'd also need to introduce customizable factories.

Motivation

Pion WebRTC is comprised of many modules (a poly-repo solution) with pluggability in mind. This has allowed us to manage each WebRTC sub-components with independent versions. It is, however, not flexible enough to achieve intended pluggability because a module depends on another via direct struct pointers rather than via interfaces.

By converting struct pointer to an interface, we can achieve the following:

Proposal: New Interfaces and CustomFactories

classDiagram
    `webrtc.API` --> `webrtc.CustomFactories` : newXxx()
    `webrtc.API` --> `webrtc.CustomFactories` : Replace factory
    `webrtc.CustomFactories` --> `ice.Agent` : &lt&ltcreate&gt&gt
    `ice.Agent` --> `ice.Conn` : &lt&ltcreate&gt&gt
    `webrtc.CustomFactories` --> `dtls.StreamRTP` : &lt&ltcreate&gt&gt
    `dtls.StreamRTP` --> `dtls.ReadStreamRTP` : &lt&ltcreate&gt&gt
    `dtls.StreamRTP` --> `dtls.WriteStreamRTP` : &lt&ltcreate&gt&gt
    `dtls.StreamRTCP` --> `dtls.ReadStreamRTCP` : &lt&ltcreate&gt&gt
    `dtls.StreamRTCP` --> `dtls.WriteStreamRTCP` : &lt&ltcreate&gt&gt
    `webrtc.CustomFactories` --> `dtls.StreamRTCP` : &lt&ltcreate&gt&gt
    `webrtc.CustomFactories` --> `sctp.Association` : &lt&ltcreate&gt&gt
    `sctp.Association` --> `sctp.Stream` : &lt&ltcreate&gt&gt
    `webrtc.CustomFactories` --> `datachannel.DataChannel` : &lt&ltcreate&gt&gt
    <<interface>>`ice.Agent`
    <<interface>>`ice.Conn`
    <<interface>>`dtls.StreamRTP`
    <<interface>>`dtls.ReadStreamRTP`
    <<interface>>`dtls.WriteStreamRTP`
    <<interface>>`dtls.StreamRTCP`
    <<interface>>`dtls.ReadStreamRTCP`
    <<interface>>`dtls.WriteStreamRTCP`
    <<interface>>`sctp.Association`
    <<interface>>`sctp.Stream`
    <<interface>>`datachannel.DataChannel`

Plan (high level)

enobufs commented 6 months ago

These are current candidates for converting to an interface: https://docs.google.com/spreadsheets/d/1uXNQQ0Qn3NfBXBgsXFSVgXmCpsYwtZrdQOGCQoAl-bA I have once locally tested based on this earlier. Please feel free to leave any comments.