diff --git a/api.go b/api.go index 61e52eee11c..369b1a9a378 100644 --- a/api.go +++ b/api.go @@ -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 { @@ -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 }