Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into raja_firefox_screen…
Browse files Browse the repository at this point in the history
…share_and_camera
  • Loading branch information
boks1971 committed Jan 31, 2022
2 parents 9ee28c1 + 82b3ab5 commit 249c12e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -133,6 +133,7 @@ Reese <3253971+figadore@users.noreply.github.com>
rob-deutsch <robzyb+altgithub@gmail.com>
Robert Eperjesi <eperjesi@uber.com>
Robin Raymond <robin-raymond@users.noreply.github.com>
Roman Romanenko <roman.romanenko@aliexpress.ru>
Roman Romanenko <romandafe94@gmail.com>
ronan <ronan.jezequel@gmail.com>
Ryan Shumate <Ryan.Shumate@garmin.com>
Expand Down
31 changes: 13 additions & 18 deletions api.go
Expand Up @@ -23,38 +23,30 @@ type API struct {

// NewAPI Creates a new API object for keeping semi-global settings to WebRTC objects
func NewAPI(options ...func(*API)) *API {
a := &API{interceptor: &interceptor.NoOp{}}
a := &API{
interceptor: &interceptor.NoOp{},
settingEngine: &SettingEngine{},
mediaEngine: &MediaEngine{},
interceptorRegistry: &interceptor.Registry{},
}

for _, o := range options {
o(a)
}

if a.settingEngine == nil {
a.settingEngine = &SettingEngine{}
}

if a.settingEngine.LoggerFactory == nil {
a.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
}

if a.mediaEngine == nil {
a.mediaEngine = &MediaEngine{}
}

if a.interceptorRegistry == nil {
a.interceptorRegistry = &interceptor.Registry{}
}

return a
}

// WithMediaEngine allows providing a MediaEngine to the API.
// Settings can be changed after passing the engine to an API.
func WithMediaEngine(m *MediaEngine) func(a *API) {
return func(a *API) {
if m != nil {
a.mediaEngine = m
} else {
a.mediaEngine = m
if a.mediaEngine == nil {
a.mediaEngine = &MediaEngine{}
}
}
Expand All @@ -70,8 +62,11 @@ func WithSettingEngine(s SettingEngine) func(a *API) {

// WithInterceptorRegistry allows providing Interceptors to the API.
// Settings should not be changed after passing the registry to an API.
func WithInterceptorRegistry(interceptorRegistry *interceptor.Registry) func(a *API) {
func WithInterceptorRegistry(ir *interceptor.Registry) func(a *API) {
return func(a *API) {
a.interceptorRegistry = interceptorRegistry
a.interceptorRegistry = ir
if a.interceptorRegistry == nil {
a.interceptorRegistry = &interceptor.Registry{}
}
}
}
15 changes: 15 additions & 0 deletions api_test.go
Expand Up @@ -19,6 +19,10 @@ func TestNewAPI(t *testing.T) {
if api.mediaEngine == nil {
t.Error("Failed to init media engine")
}

if api.interceptorRegistry == nil {
t.Error("Failed to init interceptor registry")
}
}

func TestNewAPI_Options(t *testing.T) {
Expand All @@ -40,3 +44,14 @@ func TestNewAPI_Options(t *testing.T) {
t.Error("Failed to set media engine")
}
}

func TestNewAPI_OptionsDefaultize(t *testing.T) {
api := NewAPI(
WithMediaEngine(nil),
WithInterceptorRegistry(nil),
)

assert.NotNil(t, api.settingEngine)
assert.NotNil(t, api.mediaEngine)
assert.NotNil(t, api.interceptorRegistry)
}

0 comments on commit 249c12e

Please sign in to comment.