* 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
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"regexp"
|
|
|
|
"github.com/kulikov0/headless-client"
|
|
)
|
|
|
|
type TMConfig struct {
|
|
AppVersion string
|
|
SDKVersion string
|
|
}
|
|
|
|
func fetchConfig() (TMConfig, error) {
|
|
var cfg TMConfig
|
|
|
|
page, err := tmHttpGet("https://telemost.yandex.ru/", headless.DestDocument)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("failed to fetch telemost.yandex.ru: %w", err)
|
|
}
|
|
|
|
stateRe := regexp.MustCompile(`<script[^>]*id="preloaded-state"[^>]*>([\s\S]*?)</script>`)
|
|
stateMatch := stateRe.FindSubmatch(page)
|
|
if stateMatch == nil {
|
|
return cfg, fmt.Errorf("preloaded-state not found in page")
|
|
}
|
|
var state struct {
|
|
Config struct {
|
|
AppVersion string `json:"appVersion"`
|
|
} `json:"config"`
|
|
AppVersion string `json:"appVersion"`
|
|
}
|
|
if err := json.Unmarshal(stateMatch[1], &state); err != nil {
|
|
return cfg, fmt.Errorf("failed to parse preloaded-state: %w", err)
|
|
}
|
|
cfg.AppVersion = state.Config.AppVersion
|
|
if cfg.AppVersion == "" {
|
|
cfg.AppVersion = state.AppVersion
|
|
}
|
|
if cfg.AppVersion == "" {
|
|
return cfg, fmt.Errorf("appVersion not found in preloaded-state")
|
|
}
|
|
log.Printf("[config] appVersion=%s", cfg.AppVersion)
|
|
|
|
bundleRe := regexp.MustCompile(`https://telemost\.yastatic\.net/s3/telemost/_/main\.\w+\.[a-f0-9]+\.js`)
|
|
bundleURL := bundleRe.FindString(string(page))
|
|
if bundleURL == "" {
|
|
return cfg, fmt.Errorf("main bundle URL not found in page")
|
|
}
|
|
log.Printf("[config] Found bundle: %s", bundleURL)
|
|
|
|
bundle, err := tmHttpGet(bundleURL, headless.DestScript)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("failed to fetch bundle: %w", err)
|
|
}
|
|
|
|
sdkVerPatterns := []*regexp.Regexp{
|
|
regexp.MustCompile(`goloom_sdk_version:"(\d+\.\d+\.\d+)"`),
|
|
regexp.MustCompile(`"@yandex-video-platform/goloom-sdk":"(\d+\.\d+\.\d+)"`),
|
|
regexp.MustCompile(`goloom-sdk\.(\d+\.\d+\.\d+)\.js`),
|
|
}
|
|
for _, re := range sdkVerPatterns {
|
|
if m := re.FindSubmatch(bundle); m != nil {
|
|
cfg.SDKVersion = string(m[1])
|
|
break
|
|
}
|
|
}
|
|
if cfg.SDKVersion == "" {
|
|
return cfg, fmt.Errorf("goloom SDK version not found in bundle")
|
|
}
|
|
|
|
log.Printf("[config] app=%s sdk=%s", cfg.AppVersion, cfg.SDKVersion)
|
|
return cfg, nil
|
|
}
|
|
|
|
func tmHttpGet(endpoint string, dest headless.RequestDest) ([]byte, error) {
|
|
request, err := http.NewRequest("GET", endpoint, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
request.Header = headless.ChromeWindows.Headers(dest)
|
|
if dest == headless.DestScript {
|
|
request.Header.Set("Referer", "https://telemost.yandex.ru/")
|
|
}
|
|
response, err := headless.ChromeWindows.HTTPClient().Do(request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
return io.ReadAll(response.Body)
|
|
}
|