Skip to content

Commit

Permalink
NewAPI: register default codecs and interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrein committed Dec 1, 2023
1 parent eed2bb2 commit b479146
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ type API struct {

// NewAPI Creates a new API object for keeping semi-global settings to WebRTC objects
//
// WARNING: No Codecs or Interceptors are enabled by default. Unless configured properly a
// PeerConnection will not be able to transmit media. For an example of how to do that,
// see the body of the webrtc.NewPeerConnection() function.
// It uses the default Codecs and Interceptors unless you customize them
// using WithMediaEngine and WithInterceptorRegistry respectively.
func NewAPI(options ...func(*API)) *API {
a := &API{
interceptor: &interceptor.NoOp{},
settingEngine: &SettingEngine{},
mediaEngine: &MediaEngine{},
interceptorRegistry: &interceptor.Registry{},
interceptor: &interceptor.NoOp{},
settingEngine: &SettingEngine{},
}

for _, o := range options {
Expand All @@ -45,6 +42,24 @@ func NewAPI(options ...func(*API)) *API {
a.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
}

logger := a.settingEngine.LoggerFactory.NewLogger("api")

if a.mediaEngine == nil {
a.mediaEngine = &MediaEngine{}
err := a.mediaEngine.RegisterDefaultCodecs()
if err != nil {
logger.Errorf("Failed to register default codecs %s", err)
}
}

if a.interceptorRegistry == nil {
a.interceptorRegistry = &interceptor.Registry{}
err := RegisterDefaultInterceptors(a.mediaEngine, a.interceptorRegistry)
if err != nil {
logger.Errorf("Failed to register default interceptors %s", err)
}
}

return a
}

Expand Down

0 comments on commit b479146

Please sign in to comment.