reanimate wbstream dc mode

This commit is contained in:
kulikov0 committed 2026-05-21 22:29:20 +02:00
1 parent a02fd0af9b
commit c02843d6c3
14 files changed
+155 -45

No files matched your search

+36
View File
@@ -240,6 +240,17 @@ var WBStreamCookieAllowlist = []string{
"wbx-validation-key",
}
var ModeratorPermissions = []string{
"ROOM_PERMISSION_SEND_CHAT",
"ROOM_PERMISSION_SHARE_AUDIO",
"ROOM_PERMISSION_SHARE_SCREEN",
"ROOM_PERMISSION_SHARE_VIDEO",
"ROOM_PERMISSION_MODIFY_PERMISSIONS",
"ROOM_PERMISSION_MODERATE_ROOM",
"ROOM_PERMISSION_CALL_DATA_ACCESS",
"ROOM_PERMISSION_LOCAL_RECORD",
}
type slideV3Response struct {
Payload struct {
AccessToken string `json:"access_token"`
@@ -313,6 +324,31 @@ func joinAndGetDetails(client *http.Client, accessToken, roomID, displayName str
return roomID, roomToken, accessToken, serverURL, nil
}
func SetParticipantPermissions(client *http.Client, accessToken, roomID, participantID string, permissions []string) error {
setURL := fmt.Sprintf("%s/api-room-manager/api/v1/room/%s/participant/%s/set-permissions", APIBase, roomID, participantID)
body, err := json.Marshal(map[string]any{"permissions": permissions})
if err != nil {
return err
}
req, err := http.NewRequest(http.MethodPut, setURL, bytes.NewReader(body))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
setBearer(req, accessToken)
resp, err := httpDo(client, req)
if err != nil {
return err
}
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
if resp.StatusCode >= 400 {
return fmt.Errorf("set-permissions %s -> %d %s", participantID, resp.StatusCode, string(respBody))
}
return nil
}
func KickParticipant(client *http.Client, accessToken, roomID, participantID string) error {
if client == nil {
client = http.DefaultClient
+52 -30
View File
@@ -22,6 +22,7 @@ type peerEntry struct {
identity string
firstSeen time.Time
state int32
promoted bool
}
const (
@@ -96,8 +97,7 @@ func (s *Session) Start() error {
})
s.lk.OnReady = s.onLKReady
s.lk.OnTrack = s.onRemoteTrack
// DC tunnel disabled: WB Stream DC mode is dead.
// s.lk.OnDataChannel = s.onRemoteDataChannel
s.lk.OnDataChannel = s.onRemoteDataChannel
s.lk.OnPubConnected = s.startTunnel
if s.cfg.AccessToken != "" && s.cfg.RoomID != "" {
s.lk.OnParticipantUpdate = s.onParticipantUpdate
@@ -151,25 +151,24 @@ func (s *Session) onLKReady() {
return
}
// DC tunnel disabled: WB Stream DC mode is dead.
// ordered := true
// dc, err := pubPC.CreateDataChannel("_reliable", &webrtc.DataChannelInit{
// Ordered: &ordered,
// })
// if err != nil {
// s.cfg.LogFn("[lk] create reliable DC: %v", err)
// return
// }
// s.mu.Lock()
// s.pubReliableDC = dc
// s.mu.Unlock()
// dc.OnOpen(func() {
// s.cfg.LogFn("[lk] reliable DC open")
// s.mu.Lock()
// s.pubReliableDCReady = true
// s.mu.Unlock()
// s.maybeStartDCTunnel()
// })
ordered := true
dc, err := pubPC.CreateDataChannel("_reliable", &webrtc.DataChannelInit{
Ordered: &ordered,
})
if err != nil {
s.cfg.LogFn("[lk] create reliable DC: %v", err)
return
}
s.mu.Lock()
s.pubReliableDC = dc
s.mu.Unlock()
dc.OnOpen(func() {
s.cfg.LogFn("[lk] reliable DC open")
s.mu.Lock()
s.pubReliableDCReady = true
s.mu.Unlock()
s.maybeStartDCTunnel()
})
if err := s.lk.SendAddTrack(track.ID(), "videochannel",
livekit.TrackTypeVideo, livekit.TrackSourceCamera, 1280, 720); err != nil {
@@ -204,15 +203,13 @@ func (s *Session) startTunnel() {
s.mu.Unlock()
s.cfg.LogFn("[lk] vp8 tunnel writer started")
// DC tunnel disabled: only video mode is supported.
s.fireOnConnected(s.vp8tun)
// if s.cfg.TunnelMode == TunnelModeVideo {
// s.fireOnConnected(s.vp8tun)
// return
// }
// if s.cfg.TunnelMode == "" {
// s.vp8tun.SetOnData(func(payload []byte) { s.activate(s.vp8tun, payload) })
// }
if s.cfg.TunnelMode == TunnelModeVideo {
s.fireOnConnected(s.vp8tun)
return
}
if s.cfg.TunnelMode == "" {
s.vp8tun.SetOnData(func(payload []byte) { s.activate(s.vp8tun, payload) })
}
}
func (s *Session) maybeStartDCTunnel() {
@@ -428,6 +425,8 @@ func (s *Session) onParticipantUpdate(updates []livekit.ParticipantInfo) {
s.peersBySID = make(map[string]peerEntry)
}
newcomerSIDs := make(map[string]bool)
var toPromote []peerEntry
canPromote := s.cfg.AccessToken != "" && s.cfg.RoomID != ""
for _, p := range updates {
if p.SID == "" || p.SID == selfSID {
continue
@@ -445,6 +444,10 @@ func (s *Session) onParticipantUpdate(updates []livekit.ParticipantInfo) {
entry.identity = p.Identity
}
entry.state = p.State
if canPromote && !entry.promoted && entry.state == livekit.ParticipantStateActive && entry.identity != "" {
entry.promoted = true
toPromote = append(toPromote, entry)
}
s.peersBySID[p.SID] = entry
}
@@ -457,6 +460,11 @@ func (s *Session) onParticipantUpdate(updates []livekit.ParticipantInfo) {
}
}
s.mu.Unlock()
for _, e := range toPromote {
go s.promotePeer(e.sid, e.identity)
}
if len(stale) == 0 {
return
}
@@ -476,6 +484,20 @@ func (s *Session) onParticipantUpdate(updates []livekit.ParticipantInfo) {
}
}
func (s *Session) promotePeer(sid, identity string) {
if err := SetParticipantPermissions(http.DefaultClient, s.cfg.AccessToken, s.cfg.RoomID, identity, ModeratorPermissions); err != nil {
s.cfg.LogFn("[wb] promote failed identity=%s: %v", identity, err)
s.mu.Lock()
if entry, ok := s.peersBySID[sid]; ok {
entry.promoted = false
s.peersBySID[sid] = entry
}
s.mu.Unlock()
return
}
s.cfg.LogFn("[wb] promoted to moderator identity=%s sid=%s", identity, sid)
}
func (s *Session) Close() {
if s.lk != nil {
s.lk.Close()