api_js.go 780 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. //go:build js && wasm
  4. // +build js,wasm
  5. package webrtc
  6. // API bundles the global funcions of the WebRTC and ORTC API.
  7. type API struct {
  8. settingEngine *SettingEngine
  9. }
  10. // NewAPI Creates a new API object for keeping semi-global settings to WebRTC objects
  11. func NewAPI(options ...func(*API)) *API {
  12. a := &API{}
  13. for _, o := range options {
  14. o(a)
  15. }
  16. if a.settingEngine == nil {
  17. a.settingEngine = &SettingEngine{}
  18. }
  19. return a
  20. }
  21. // WithSettingEngine allows providing a SettingEngine to the API.
  22. // Settings should not be changed after passing the engine to an API.
  23. func WithSettingEngine(s SettingEngine) func(a *API) {
  24. return func(a *API) {
  25. a.settingEngine = &s
  26. }
  27. }