mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 07:06:51 +08:00
NewAPI: register default codecs and interceptors
This commit is contained in:

committed by
Sean DuBois

parent
2fcd8a195b
commit
21c5a711d8
29
api.go
29
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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user