Honor autoSubscribe when subscription permissions are granted later (#381)
* Ensure autosubscribe is honored when subscription permissions were granted later * negotiate even if no media has been added * don't double-negotiate
This commit is contained in:
@@ -89,7 +89,7 @@ type Options struct {
|
||||
}
|
||||
|
||||
func NewWebSocketConn(host, token string, opts *Options) (*websocket.Conn, error) {
|
||||
u, err := url.Parse(host + "/rtc?protocol=3")
|
||||
u, err := url.Parse(host + "/rtc?protocol=6")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -341,6 +341,10 @@ func TestSingleNodeJoinAfterClose(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAutoCreate(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
disableAutoCreate := func(conf *config.Config) {
|
||||
conf.Room.AutoCreate = false
|
||||
}
|
||||
@@ -381,3 +385,57 @@ func TestAutoCreate(t *testing.T) {
|
||||
c1.Stop()
|
||||
})
|
||||
}
|
||||
|
||||
// don't give user subscribe permissions initially, and ensure autosubscribe is triggered afterwards
|
||||
func TestSingleNodeUpdateSubscriptionPermissions(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
_, finish := setupSingleNodeTest("TestSingleNodeUpdateSubscriptionPermissions")
|
||||
defer finish()
|
||||
|
||||
pub := createRTCClient("pub", defaultServerPort, nil)
|
||||
grant := &auth.VideoGrant{RoomJoin: true, Room: testRoom}
|
||||
grant.SetCanSubscribe(false)
|
||||
at := auth.NewAccessToken(testApiKey, testApiSecret).
|
||||
AddGrant(grant).
|
||||
SetIdentity("sub")
|
||||
token, err := at.ToJWT()
|
||||
require.NoError(t, err)
|
||||
sub := createRTCClientWithToken(token, defaultServerPort, nil)
|
||||
|
||||
waitUntilConnected(t, pub, sub)
|
||||
|
||||
writers := publishTracksForClients(t, pub)
|
||||
defer stopWriters(writers...)
|
||||
|
||||
// wait sub receives tracks
|
||||
testutils.WithTimeout(t, "waiting for sub to receive track metadata", func() bool {
|
||||
pubRemote := sub.GetRemoteParticipant(pub.ID())
|
||||
if pubRemote == nil {
|
||||
return false
|
||||
}
|
||||
if len(pubRemote.Tracks) != 2 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
// set permissions out of band
|
||||
ctx := contextWithToken(adminRoomToken(testRoom))
|
||||
_, err = roomClient.UpdateParticipant(ctx, &livekit.UpdateParticipantRequest{
|
||||
Room: testRoom,
|
||||
Identity: "sub",
|
||||
Permission: &livekit.ParticipantPermission{
|
||||
CanSubscribe: true,
|
||||
CanPublish: true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
testutils.WithTimeout(t, "waiting to get subscriptions", func() bool {
|
||||
tracks := sub.SubscribedTracks()[pub.ID()]
|
||||
return len(tracks) == 2
|
||||
})
|
||||
}
|
||||
|
||||
+17
-1
@@ -2,6 +2,7 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -184,7 +185,22 @@ func (s *webhookTestServer) Start() error {
|
||||
return err
|
||||
}
|
||||
go s.server.Serve(l)
|
||||
return nil
|
||||
|
||||
// wait for webhook server to start
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutils.ConnectTimeout)
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return errors.New("could not start webhook server after timeout")
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
// ensure we can connect to it
|
||||
res, err := http.Get(fmt.Sprintf("http://localhost%s", s.server.Addr))
|
||||
if err == nil && res.StatusCode == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *webhookTestServer) Stop() {
|
||||
|
||||
Reference in New Issue
Block a user