ability to disable auto subscribe per participant
This commit is contained in:
@@ -5,11 +5,10 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/service"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/auth/authfakes"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuthMiddleware(t *testing.T) {
|
||||
@@ -30,23 +29,23 @@ func TestAuthMiddleware(t *testing.T) {
|
||||
at := auth.NewAccessToken(api, secret).
|
||||
AddGrant(orig)
|
||||
token, err := at.ToJWT()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
r := &http.Request{Header: http.Header{}}
|
||||
w := httptest.NewRecorder()
|
||||
service.SetAuthorizationToken(r, token)
|
||||
m.ServeHTTP(w, r, handler)
|
||||
|
||||
assert.NotNil(t, grants)
|
||||
assert.EqualValues(t, orig, grants.Video)
|
||||
require.NotNil(t, grants)
|
||||
require.EqualValues(t, orig, grants.Video)
|
||||
|
||||
// no authorization == no claims
|
||||
grants = nil
|
||||
w = httptest.NewRecorder()
|
||||
r = &http.Request{Header: http.Header{}}
|
||||
m.ServeHTTP(w, r, handler)
|
||||
assert.Nil(t, grants)
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
require.Nil(t, grants)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
// incorrect authorization: error
|
||||
grants = nil
|
||||
@@ -54,6 +53,6 @@ func TestAuthMiddleware(t *testing.T) {
|
||||
r = &http.Request{Header: http.Header{}}
|
||||
service.SetAuthorizationToken(r, "invalid token")
|
||||
m.ServeHTTP(w, r, handler)
|
||||
assert.Nil(t, grants)
|
||||
assert.Equal(t, http.StatusUnauthorized, w.Code)
|
||||
require.Nil(t, grants)
|
||||
require.Equal(t, http.StatusUnauthorized, w.Code)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@ package service_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/service"
|
||||
livekit "github.com/livekit/livekit-server/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParticipantPersisence(t *testing.T) {
|
||||
@@ -33,28 +32,28 @@ func TestParticipantPersisence(t *testing.T) {
|
||||
}
|
||||
|
||||
// create the participant
|
||||
assert.NoError(t, rs.PersistParticipant(roomName, p))
|
||||
require.NoError(t, rs.PersistParticipant(roomName, p))
|
||||
|
||||
// result should match
|
||||
pGet, err := rs.GetParticipant(roomName, p.Identity)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, p.Identity, pGet.Identity)
|
||||
assert.Equal(t, len(p.Tracks), len(pGet.Tracks))
|
||||
assert.Equal(t, p.Tracks[0].Sid, pGet.Tracks[0].Sid)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, p.Identity, pGet.Identity)
|
||||
require.Equal(t, len(p.Tracks), len(pGet.Tracks))
|
||||
require.Equal(t, p.Tracks[0].Sid, pGet.Tracks[0].Sid)
|
||||
|
||||
// list should return one participant
|
||||
participants, err := rs.ListParticipants(roomName)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, participants, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, participants, 1)
|
||||
|
||||
// deleting participant should return back to normal
|
||||
assert.NoError(t, rs.DeleteParticipant(roomName, p.Identity))
|
||||
require.NoError(t, rs.DeleteParticipant(roomName, p.Identity))
|
||||
|
||||
participants, err = rs.ListParticipants(roomName)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, participants, 0)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, participants, 0)
|
||||
|
||||
// shouldn't be able to get it
|
||||
_, err = rs.GetParticipant(roomName, p.Identity)
|
||||
assert.Equal(t, err, service.ErrParticipantNotFound)
|
||||
require.Equal(t, err, service.ErrParticipantNotFound)
|
||||
}
|
||||
|
||||
@@ -260,7 +260,10 @@ func (r *RoomManager) StartSession(roomName string, pi routing.ParticipantInit,
|
||||
}
|
||||
|
||||
// join room
|
||||
if err := room.Join(participant); err != nil {
|
||||
opts := rtc.ParticipantOptions{
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
}
|
||||
if err := room.Join(participant, &opts); err != nil {
|
||||
logger.Errorw("could not join room", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
roomName := r.FormValue("room")
|
||||
reconnectParam := r.FormValue("reconnect")
|
||||
protocolParam := r.FormValue("protocol")
|
||||
autoSubParam := r.FormValue("auto_subscribe")
|
||||
planBParam := r.FormValue("planb")
|
||||
|
||||
claims := GetGrants(r.Context())
|
||||
@@ -66,10 +67,18 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
pi := routing.ParticipantInit{
|
||||
Reconnect: boolValue(reconnectParam),
|
||||
Identity: claims.Identity,
|
||||
UsePlanB: boolValue(planBParam),
|
||||
Reconnect: boolValue(reconnectParam),
|
||||
Identity: claims.Identity,
|
||||
UsePlanB: boolValue(planBParam),
|
||||
AutoSubscribe: true,
|
||||
}
|
||||
if autoSubParam != "" {
|
||||
pi.AutoSubscribe = boolValue(autoSubParam)
|
||||
}
|
||||
if pv, err := strconv.Atoi(protocolParam); err == nil {
|
||||
pi.ProtocolVersion = int32(pv)
|
||||
}
|
||||
|
||||
// only use permissions if any of them are set, default permissive
|
||||
if claims.Video.CanPublish || claims.Video.CanSubscribe {
|
||||
pi.Permission = &livekit.ParticipantPermission{
|
||||
@@ -77,9 +86,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
CanPublish: claims.Video.CanPublish,
|
||||
}
|
||||
}
|
||||
if pv, err := strconv.Atoi(protocolParam); err == nil {
|
||||
pi.ProtocolVersion = int32(pv)
|
||||
}
|
||||
|
||||
onlyName, err := EnsureJoinPermission(r.Context())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user