* add external modules and patches * migrate pion webrtc to vendored headlessclient, drop local pion replaces * use chrome ice credentials, one webrtc api per peer connection * send one user agent everywhere, use the vendored websocket * route the telemost joiner through headlessclient, drop the dead keylog * answer telemost dtls without a hello verify round trip * follow the headlessclient dtls 1.3 mimicry rename * follow the headless-client rename and apply the profile before the caller settings * build every webrtc api through relay/headlessapi * register chrome rtp header extensions for every pion consumer * dial vk webtransport signaling through the headless quic profile * dial dion and wb stream through the headless chrome profile * announce chrome's http/3 settings on the vk webtransport signaling * send chrome header blocks on bitrix http and livekit websocket * send chrome's webtransport connect headers on vk signaling * stop passing invented track names to the library * move wbp http paths onto the headlessclient profile * migrate to a published headlessclient * dedup go.mod
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package headlessapi
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
headless "github.com/kulikov0/headless-client"
|
|
"github.com/kulikov0/headless-client/webrtc"
|
|
)
|
|
|
|
type Options struct {
|
|
Profile headless.Profile
|
|
AnswerAsDTLSServer bool
|
|
Configure func(*webrtc.SettingEngine)
|
|
}
|
|
|
|
func resolveProfile(options Options) headless.Profile {
|
|
if options.Profile == (headless.Profile{}) {
|
|
return headless.ChromeWindows
|
|
}
|
|
|
|
return options.Profile
|
|
}
|
|
|
|
func WebRTCSettingEngine(options Options) (webrtc.SettingEngine, error) {
|
|
profile := resolveProfile(options)
|
|
|
|
settingEngine, err := profile.SettingEngine()
|
|
if err != nil {
|
|
return webrtc.SettingEngine{}, fmt.Errorf("build setting engine: %w", err)
|
|
}
|
|
if options.Configure != nil {
|
|
options.Configure(&settingEngine)
|
|
}
|
|
if options.AnswerAsDTLSServer {
|
|
if err := settingEngine.SetAnsweringDTLSRole(webrtc.DTLSRoleServer); err != nil {
|
|
return webrtc.SettingEngine{}, fmt.Errorf("set answering dtls role: %w", err)
|
|
}
|
|
}
|
|
|
|
return settingEngine, nil
|
|
}
|
|
|
|
func buildMediaEngine(options Options) (*webrtc.MediaEngine, error) {
|
|
mediaEngine := &webrtc.MediaEngine{}
|
|
if err := mediaEngine.RegisterDefaultCodecs(); err != nil {
|
|
return nil, fmt.Errorf("register default codecs: %w", err)
|
|
}
|
|
if err := resolveProfile(options).RegisterHeaderExtensions(mediaEngine); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return mediaEngine, nil
|
|
}
|
|
|
|
func WebRTCAPI(options Options, apiOptions ...func(*webrtc.API)) (*webrtc.API, error) {
|
|
settingEngine, err := WebRTCSettingEngine(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mediaEngine, err := buildMediaEngine(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
allAPIOptions := make([]func(*webrtc.API), 0, len(apiOptions)+2)
|
|
allAPIOptions = append(allAPIOptions, webrtc.WithMediaEngine(mediaEngine))
|
|
allAPIOptions = append(allAPIOptions, apiOptions...)
|
|
allAPIOptions = append(allAPIOptions, webrtc.WithSettingEngine(settingEngine))
|
|
|
|
return webrtc.NewAPI(allAPIOptions...), nil
|
|
}
|