extract shared dial helpers for headless joiners

This commit is contained in:
kulikov0 committed 2026-10-25 12:45:32 +01:00
1 parent e0e82f5212
commit 95f22d464b
5 files changed
+43 -92

No files matched your search

@@ -1,16 +1,12 @@
package joiner
import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"sync"
"sync/atomic"
"time"
"github.com/kulikov0/headless-client"
"github.com/kulikov0/headless-client/webrtc"
"whitelist-bypass/relay/common"
"whitelist-bypass/relay/dion"
@@ -61,7 +57,7 @@ func (j *DionHeadlessJoiner) RunWithParams(jsonParams string) {
params.DisplayName = "Joiner"
}
httpClient := j.makeHTTPClient()
httpClient := resolvingHTTPClient(j.ResolveFn)
j.logFn("dion-joiner: room=%s name=%s", slug, params.DisplayName)
var configureSettingEngine func(*webrtc.SettingEngine)
@@ -117,7 +113,7 @@ func (j *DionHeadlessJoiner) runOnce(httpClient *http.Client, slug, displayName
DisplayName: displayName,
LogFn: j.logFn,
ConfigureSettingEngine: configureSettingEngine,
NetDialContext: j.makeDialContext(),
NetDialContext: resolvingDialContext(j.ResolveFn),
ResolveICEHost: j.ResolveFn,
Role: dion.RoleJoiner,
})
@@ -184,29 +180,6 @@ func (j *DionHeadlessJoiner) Close() {
}
}
func (j *DionHeadlessJoiner) makeDialContext() func(ctx context.Context, network, addr string) (net.Conn, error) {
if j.ResolveFn == nil {
return nil
}
return func(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, _ := net.SplitHostPort(addr)
resolvedIP, err := j.ResolveFn(host)
if err != nil {
return nil, err
}
dialer := headless.ChromeDialer()
dialer.Timeout = 10 * time.Second
return dialer.DialContext(ctx, network, resolvedIP+":"+port)
}
}
func (j *DionHeadlessJoiner) makeHTTPClient() *http.Client {
return &http.Client{
Timeout: 60 * time.Second,
Transport: headless.ChromeWindows.Transport(headless.TLSOptions{DialContext: j.makeDialContext()}),
}
}
// normalizeDionSlug accepts a bare slug, a dion:// URI, or a full
// https://dion.vc/event/<slug> URL and returns the slug portion.
func normalizeDionSlug(input string) string {