share vp8 config push and ice resolve, fix vk ice hosts, widen kick greps
This commit is contained in:
1 parent
2f366b1128
commit
69de2bd8b7
10 files changed
+83
-162
No files matched your search
@@ -2,13 +2,8 @@ package joiner
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"whitelist-bypass/relay/tunnel"
|
||||
)
|
||||
|
||||
const configResendPeriod = 3 * time.Second
|
||||
|
||||
type configAckTracker struct {
|
||||
mu sync.Mutex
|
||||
acked chan struct{}
|
||||
@@ -46,23 +41,3 @@ func (t *configAckTracker) mark() {
|
||||
close(t.acked)
|
||||
}
|
||||
}
|
||||
|
||||
func sendVP8ConfigUntilAcked(acked, cancel <-chan struct{}, stopCh <-chan struct{}, tun tunnel.DataTunnel, fps, batch, trackCount int, logFn func(string, ...any), logPrefix string) {
|
||||
tun.SendData(tunnel.EncodeVP8Config(fps, batch, trackCount))
|
||||
ticker := time.NewTicker(configResendPeriod)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-acked:
|
||||
return
|
||||
case <-cancel:
|
||||
return
|
||||
case <-stopCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
logFn("%s: resending vp8 config fps=%d batch=%d trackCount=%d, no ack yet",
|
||||
logPrefix, fps, batch, trackCount)
|
||||
tun.SendData(tunnel.EncodeVP8Config(fps, batch, trackCount))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -517,7 +516,7 @@ func (j *TelemostHeadlessJoiner) initPC() {
|
||||
trackCount = 2
|
||||
}
|
||||
acked, cancel := j.configAck.arm()
|
||||
go sendVP8ConfigUntilAcked(acked, cancel, j.stopCh, active,
|
||||
go tunnel.SendVP8ConfigUntilAcked(acked, cancel, j.stopCh, active,
|
||||
vp8tun.FPS(), vp8tun.Batch(), trackCount, j.logFn, "telemost-joiner")
|
||||
j.logFn("telemost-joiner: pushed vp8 config to creator fps=%d batch=%d", vp8tun.FPS(), vp8tun.Batch())
|
||||
}
|
||||
@@ -920,38 +919,17 @@ func (j *TelemostHeadlessJoiner) parseICEServersFromHello(sh map[string]interfac
|
||||
if u, ok := sm["urls"].([]interface{}); ok {
|
||||
for _, v := range u {
|
||||
if vs, ok := v.(string); ok {
|
||||
urls = append(urls, common.FixICEURL(vs))
|
||||
urls = append(urls, vs)
|
||||
}
|
||||
}
|
||||
}
|
||||
ice := webrtc.ICEServer{URLs: urls}
|
||||
ice := webrtc.ICEServer{URLs: common.ResolveICEHosts(urls, j.ResolveFn, j.logFn, "telemost-joiner")}
|
||||
if u, ok := sm["username"].(string); ok && u != "" {
|
||||
ice.Username = u
|
||||
ice.Credential, _ = sm["credential"].(string)
|
||||
}
|
||||
iceServers = append(iceServers, ice)
|
||||
}
|
||||
resolved := make(map[string]string)
|
||||
for i, s := range iceServers {
|
||||
for k, u := range s.URLs {
|
||||
host := common.ExtractICEHost(u)
|
||||
if host == "" || net.ParseIP(host) != nil {
|
||||
continue
|
||||
}
|
||||
ip, ok := resolved[host]
|
||||
if !ok {
|
||||
var err error
|
||||
ip, err = j.ResolveFn(host)
|
||||
if err != nil {
|
||||
j.logFn("telemost-joiner: resolve ICE host %s failed: %s", common.MaskAddr(host), common.MaskError(err))
|
||||
continue
|
||||
}
|
||||
resolved[host] = ip
|
||||
j.logFn("telemost-joiner: resolved ICE host %s -> %s", host, ip)
|
||||
}
|
||||
iceServers[i].URLs[k] = strings.Replace(u, host, ip, 1)
|
||||
}
|
||||
}
|
||||
j.iceServers = iceServers
|
||||
for i, s := range iceServers {
|
||||
j.logFn("telemost-joiner: ICE server %d: urls=%v", i, s.URLs)
|
||||
|
||||
@@ -557,11 +557,13 @@ func (h *VKHeadlessJoiner) handleConnection(msg map[string]interface{}) {
|
||||
func (h *VKHeadlessJoiner) initPC() {
|
||||
var iceServers []webrtc.ICEServer
|
||||
if len(h.joinResp.StunServer.URLs) > 0 {
|
||||
iceServers = append(iceServers, webrtc.ICEServer{URLs: h.joinResp.StunServer.URLs})
|
||||
iceServers = append(iceServers, webrtc.ICEServer{
|
||||
URLs: common.ResolveICEHosts(h.joinResp.StunServer.URLs, h.ResolveFn, h.logFn, "vk-joiner"),
|
||||
})
|
||||
}
|
||||
if len(h.joinResp.TurnServer.URLs) > 0 {
|
||||
iceServers = append(iceServers, webrtc.ICEServer{
|
||||
URLs: h.joinResp.TurnServer.URLs,
|
||||
URLs: common.ResolveICEHosts(h.joinResp.TurnServer.URLs, h.ResolveFn, h.logFn, "vk-joiner"),
|
||||
Username: h.joinResp.TurnServer.Username,
|
||||
Credential: h.joinResp.TurnServer.Credential,
|
||||
})
|
||||
@@ -658,7 +660,7 @@ func (h *VKHeadlessJoiner) initPC() {
|
||||
vp8tun := h.vp8tunnel
|
||||
if !h.configAck.acknowledged() {
|
||||
acked, cancel := h.configAck.arm()
|
||||
go sendVP8ConfigUntilAcked(acked, cancel, h.stopCh, vp8tun,
|
||||
go tunnel.SendVP8ConfigUntilAcked(acked, cancel, h.stopCh, vp8tun,
|
||||
vp8tun.FPS(), vp8tun.Batch(), trackCount, h.logFn, "vk-joiner")
|
||||
h.logFn("vk-joiner: pushed vp8 config to creator fps=%d batch=%d trackCount=%d", vp8tun.FPS(), vp8tun.Batch(), trackCount)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user