NewAPI Creates a new API object for keeping semi-global settings to WebRTC objects It uses the default Codecs and Interceptors unless you customize them using WithMediaEngine and WithInterceptorRegistry respectively.
(options ...func(*API))
| 28 | // It uses the default Codecs and Interceptors unless you customize them |
| 29 | // using WithMediaEngine and WithInterceptorRegistry respectively. |
| 30 | func NewAPI(options ...func(*API)) *API { |
| 31 | api := &API{ |
| 32 | interceptor: &interceptor.NoOp{}, |
| 33 | settingEngine: &SettingEngine{}, |
| 34 | } |
| 35 | |
| 36 | for _, o := range options { |
| 37 | o(api) |
| 38 | } |
| 39 | |
| 40 | if api.settingEngine.LoggerFactory == nil { |
| 41 | api.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory() |
| 42 | } |
| 43 | |
| 44 | logger := api.settingEngine.LoggerFactory.NewLogger("api") |
| 45 | |
| 46 | if api.mediaEngine == nil { |
| 47 | api.mediaEngine = &MediaEngine{} |
| 48 | err := api.mediaEngine.RegisterDefaultCodecs() |
| 49 | if err != nil { |
| 50 | logger.Errorf("Failed to register default codecs %s", err) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if api.interceptorRegistry == nil { |
| 55 | api.interceptorRegistry = &interceptor.Registry{} |
| 56 | err := RegisterDefaultInterceptorsWithOptions(api.mediaEngine, api.interceptorRegistry, |
| 57 | WithInterceptorLoggerFactory(api.settingEngine.LoggerFactory)) |
| 58 | if err != nil { |
| 59 | logger.Errorf("Failed to register default interceptors %s", err) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return api |
| 64 | } |
| 65 | |
| 66 | // WithMediaEngine allows providing a MediaEngine to the API. |
| 67 | // Settings can be changed after passing the engine to an API. |
searching dependent graphs…