Implement Interceptors

Provide API so that handling around RTP can be easily defined by the
user. See the design doc here[0]

[0] https://github.com/pion/webrtc-v3-design/issues/34
This commit is contained in:
Adam Kiss
2020-11-20 14:05:33 +01:00
committed by Sean DuBois
parent 00ec48af63
commit 5bbc84e404
14 changed files with 528 additions and 71 deletions

14
api.go
View File

@@ -3,6 +3,7 @@
package webrtc
import (
"github.com/pion/interceptor"
"github.com/pion/logging"
)
@@ -13,6 +14,7 @@ import (
type API struct {
settingEngine *SettingEngine
mediaEngine *MediaEngine
interceptor interceptor.Interceptor
}
// NewAPI Creates a new API object for keeping semi-global settings to WebRTC objects
@@ -35,6 +37,10 @@ func NewAPI(options ...func(*API)) *API {
a.mediaEngine = &MediaEngine{}
}
if a.interceptor == nil {
a.interceptor = &interceptor.NoOp{}
}
return a
}
@@ -57,3 +63,11 @@ func WithSettingEngine(s SettingEngine) func(a *API) {
a.settingEngine = &s
}
}
// 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) {
return func(a *API) {
a.interceptor = interceptorRegistry.Build()
}
}