Issue updated tokens to clients. (#365)
This ensures client reconnect attempts would be successful for long running rooms. It also fixes inaccurate permissions that were set incorrectly when full reconnections take place.
This commit is contained in:
+48
-3
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/twcc"
|
||||
"github.com/livekit/protocol/auth"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
@@ -56,6 +57,7 @@ type ParticipantParams struct {
|
||||
Recorder bool
|
||||
Logger logger.Logger
|
||||
SimTracks map[uint32]SimulcastTrackInfo
|
||||
Grants *auth.ClaimGrants
|
||||
}
|
||||
|
||||
type ParticipantImpl struct {
|
||||
@@ -109,9 +111,10 @@ type ParticipantImpl struct {
|
||||
onMetadataUpdate func(types.LocalParticipant)
|
||||
onDataPacket func(types.LocalParticipant, *livekit.DataPacket)
|
||||
|
||||
migrateState atomic.Value // types.MigrateState
|
||||
pendingOffer *webrtc.SessionDescription
|
||||
onClose func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID)
|
||||
migrateState atomic.Value // types.MigrateState
|
||||
pendingOffer *webrtc.SessionDescription
|
||||
onClose func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID)
|
||||
onClaimsChanged func(participant types.LocalParticipant)
|
||||
}
|
||||
|
||||
func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
@@ -236,15 +239,45 @@ func (p *ParticipantImpl) ConnectedAt() time.Time {
|
||||
|
||||
// SetMetadata attaches metadata to the participant
|
||||
func (p *ParticipantImpl) SetMetadata(metadata string) {
|
||||
p.lock.Lock()
|
||||
changed := p.metadata != metadata
|
||||
p.metadata = metadata
|
||||
p.params.Grants.Metadata = metadata
|
||||
p.lock.Unlock()
|
||||
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
|
||||
if p.onMetadataUpdate != nil {
|
||||
p.onMetadataUpdate(p)
|
||||
}
|
||||
if p.onClaimsChanged != nil {
|
||||
p.onClaimsChanged(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) ClaimGrants() *auth.ClaimGrants {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.params.Grants
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermission) {
|
||||
p.lock.Lock()
|
||||
p.permission = permission
|
||||
|
||||
// update grants with this
|
||||
if p.params.Grants != nil && p.params.Grants.Video != nil {
|
||||
video := p.params.Grants.Video
|
||||
video.SetCanSubscribe(permission.CanSubscribe)
|
||||
video.SetCanPublish(permission.CanPublish)
|
||||
video.SetCanPublishData(permission.CanPublishData)
|
||||
}
|
||||
p.lock.Unlock()
|
||||
if p.onClaimsChanged != nil {
|
||||
p.onClaimsChanged(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
||||
@@ -301,6 +334,10 @@ func (p *ParticipantImpl) OnClose(callback func(types.LocalParticipant, map[live
|
||||
p.onClose = callback
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnClaimsChanged(callback func(types.LocalParticipant)) {
|
||||
p.onClaimsChanged = callback
|
||||
}
|
||||
|
||||
// HandleOffer an offer from remote participant, used when clients make the initial connection
|
||||
func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error) {
|
||||
p.lock.Lock()
|
||||
@@ -650,6 +687,14 @@ func (p *ParticipantImpl) SendConnectionQualityUpdate(update *livekit.Connection
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SendRefreshToken(token string) error {
|
||||
return p.writeMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_RefreshToken{
|
||||
RefreshToken: token,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SetTrackMuted(trackID livekit.TrackID, muted bool, fromAdmin bool) {
|
||||
// when request is coming from admin, send message to current participant
|
||||
if fromAdmin {
|
||||
|
||||
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
@@ -74,15 +75,14 @@ type LocalParticipant interface {
|
||||
|
||||
State() livekit.ParticipantInfo_State
|
||||
IsReady() bool
|
||||
|
||||
IsRecorder() bool
|
||||
|
||||
SubscriberAsPrimary() bool
|
||||
|
||||
GetResponseSink() routing.MessageSink
|
||||
SetResponseSink(sink routing.MessageSink)
|
||||
|
||||
// permissions
|
||||
ClaimGrants() *auth.ClaimGrants
|
||||
SetPermission(permission *livekit.ParticipantPermission)
|
||||
CanPublish() bool
|
||||
CanSubscribe() bool
|
||||
@@ -119,6 +119,7 @@ type LocalParticipant interface {
|
||||
SendRoomUpdate(room *livekit.Room) error
|
||||
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
||||
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
||||
SendRefreshToken(token string) error
|
||||
|
||||
// callbacks
|
||||
OnStateChange(func(p LocalParticipant, oldState livekit.ParticipantInfo_State))
|
||||
@@ -129,6 +130,7 @@ type LocalParticipant interface {
|
||||
OnMetadataUpdate(callback func(LocalParticipant))
|
||||
OnDataPacket(callback func(LocalParticipant, *livekit.DataPacket))
|
||||
OnClose(_callback func(LocalParticipant, map[livekit.TrackID]livekit.ParticipantID))
|
||||
OnClaimsChanged(_callback func(LocalParticipant))
|
||||
|
||||
// session migration
|
||||
SetMigrateState(s MigrateState)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
webrtc "github.com/pion/webrtc/v3"
|
||||
)
|
||||
@@ -84,6 +85,16 @@ type FakeLocalParticipant struct {
|
||||
canSubscribeReturnsOnCall map[int]struct {
|
||||
result1 bool
|
||||
}
|
||||
ClaimGrantsStub func() *auth.ClaimGrants
|
||||
claimGrantsMutex sync.RWMutex
|
||||
claimGrantsArgsForCall []struct {
|
||||
}
|
||||
claimGrantsReturns struct {
|
||||
result1 *auth.ClaimGrants
|
||||
}
|
||||
claimGrantsReturnsOnCall map[int]struct {
|
||||
result1 *auth.ClaimGrants
|
||||
}
|
||||
CloseStub func(bool) error
|
||||
closeMutex sync.RWMutex
|
||||
closeArgsForCall []struct {
|
||||
@@ -297,6 +308,11 @@ type FakeLocalParticipant struct {
|
||||
negotiateMutex sync.RWMutex
|
||||
negotiateArgsForCall []struct {
|
||||
}
|
||||
OnClaimsChangedStub func(func(types.LocalParticipant))
|
||||
onClaimsChangedMutex sync.RWMutex
|
||||
onClaimsChangedArgsForCall []struct {
|
||||
arg1 func(types.LocalParticipant)
|
||||
}
|
||||
OnCloseStub func(func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID))
|
||||
onCloseMutex sync.RWMutex
|
||||
onCloseArgsForCall []struct {
|
||||
@@ -396,6 +412,17 @@ type FakeLocalParticipant struct {
|
||||
sendParticipantUpdateReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
SendRefreshTokenStub func(string) error
|
||||
sendRefreshTokenMutex sync.RWMutex
|
||||
sendRefreshTokenArgsForCall []struct {
|
||||
arg1 string
|
||||
}
|
||||
sendRefreshTokenReturns struct {
|
||||
result1 error
|
||||
}
|
||||
sendRefreshTokenReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
SendRoomUpdateStub func(*livekit.Room) error
|
||||
sendRoomUpdateMutex sync.RWMutex
|
||||
sendRoomUpdateArgsForCall []struct {
|
||||
@@ -957,6 +984,59 @@ func (fake *FakeLocalParticipant) CanSubscribeReturnsOnCall(i int, result1 bool)
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) ClaimGrants() *auth.ClaimGrants {
|
||||
fake.claimGrantsMutex.Lock()
|
||||
ret, specificReturn := fake.claimGrantsReturnsOnCall[len(fake.claimGrantsArgsForCall)]
|
||||
fake.claimGrantsArgsForCall = append(fake.claimGrantsArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ClaimGrantsStub
|
||||
fakeReturns := fake.claimGrantsReturns
|
||||
fake.recordInvocation("ClaimGrants", []interface{}{})
|
||||
fake.claimGrantsMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) ClaimGrantsCallCount() int {
|
||||
fake.claimGrantsMutex.RLock()
|
||||
defer fake.claimGrantsMutex.RUnlock()
|
||||
return len(fake.claimGrantsArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) ClaimGrantsCalls(stub func() *auth.ClaimGrants) {
|
||||
fake.claimGrantsMutex.Lock()
|
||||
defer fake.claimGrantsMutex.Unlock()
|
||||
fake.ClaimGrantsStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) ClaimGrantsReturns(result1 *auth.ClaimGrants) {
|
||||
fake.claimGrantsMutex.Lock()
|
||||
defer fake.claimGrantsMutex.Unlock()
|
||||
fake.ClaimGrantsStub = nil
|
||||
fake.claimGrantsReturns = struct {
|
||||
result1 *auth.ClaimGrants
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) ClaimGrantsReturnsOnCall(i int, result1 *auth.ClaimGrants) {
|
||||
fake.claimGrantsMutex.Lock()
|
||||
defer fake.claimGrantsMutex.Unlock()
|
||||
fake.ClaimGrantsStub = nil
|
||||
if fake.claimGrantsReturnsOnCall == nil {
|
||||
fake.claimGrantsReturnsOnCall = make(map[int]struct {
|
||||
result1 *auth.ClaimGrants
|
||||
})
|
||||
}
|
||||
fake.claimGrantsReturnsOnCall[i] = struct {
|
||||
result1 *auth.ClaimGrants
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) Close(arg1 bool) error {
|
||||
fake.closeMutex.Lock()
|
||||
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
||||
@@ -2087,6 +2167,38 @@ func (fake *FakeLocalParticipant) NegotiateCalls(stub func()) {
|
||||
fake.NegotiateStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) OnClaimsChanged(arg1 func(types.LocalParticipant)) {
|
||||
fake.onClaimsChangedMutex.Lock()
|
||||
fake.onClaimsChangedArgsForCall = append(fake.onClaimsChangedArgsForCall, struct {
|
||||
arg1 func(types.LocalParticipant)
|
||||
}{arg1})
|
||||
stub := fake.OnClaimsChangedStub
|
||||
fake.recordInvocation("OnClaimsChanged", []interface{}{arg1})
|
||||
fake.onClaimsChangedMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.OnClaimsChangedStub(arg1)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) OnClaimsChangedCallCount() int {
|
||||
fake.onClaimsChangedMutex.RLock()
|
||||
defer fake.onClaimsChangedMutex.RUnlock()
|
||||
return len(fake.onClaimsChangedArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) OnClaimsChangedCalls(stub func(func(types.LocalParticipant))) {
|
||||
fake.onClaimsChangedMutex.Lock()
|
||||
defer fake.onClaimsChangedMutex.Unlock()
|
||||
fake.OnClaimsChangedStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) OnClaimsChangedArgsForCall(i int) func(types.LocalParticipant) {
|
||||
fake.onClaimsChangedMutex.RLock()
|
||||
defer fake.onClaimsChangedMutex.RUnlock()
|
||||
argsForCall := fake.onClaimsChangedArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) OnClose(arg1 func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID)) {
|
||||
fake.onCloseMutex.Lock()
|
||||
fake.onCloseArgsForCall = append(fake.onCloseArgsForCall, struct {
|
||||
@@ -2660,6 +2772,67 @@ func (fake *FakeLocalParticipant) SendParticipantUpdateReturnsOnCall(i int, resu
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshToken(arg1 string) error {
|
||||
fake.sendRefreshTokenMutex.Lock()
|
||||
ret, specificReturn := fake.sendRefreshTokenReturnsOnCall[len(fake.sendRefreshTokenArgsForCall)]
|
||||
fake.sendRefreshTokenArgsForCall = append(fake.sendRefreshTokenArgsForCall, struct {
|
||||
arg1 string
|
||||
}{arg1})
|
||||
stub := fake.SendRefreshTokenStub
|
||||
fakeReturns := fake.sendRefreshTokenReturns
|
||||
fake.recordInvocation("SendRefreshToken", []interface{}{arg1})
|
||||
fake.sendRefreshTokenMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshTokenCallCount() int {
|
||||
fake.sendRefreshTokenMutex.RLock()
|
||||
defer fake.sendRefreshTokenMutex.RUnlock()
|
||||
return len(fake.sendRefreshTokenArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshTokenCalls(stub func(string) error) {
|
||||
fake.sendRefreshTokenMutex.Lock()
|
||||
defer fake.sendRefreshTokenMutex.Unlock()
|
||||
fake.SendRefreshTokenStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshTokenArgsForCall(i int) string {
|
||||
fake.sendRefreshTokenMutex.RLock()
|
||||
defer fake.sendRefreshTokenMutex.RUnlock()
|
||||
argsForCall := fake.sendRefreshTokenArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshTokenReturns(result1 error) {
|
||||
fake.sendRefreshTokenMutex.Lock()
|
||||
defer fake.sendRefreshTokenMutex.Unlock()
|
||||
fake.SendRefreshTokenStub = nil
|
||||
fake.sendRefreshTokenReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRefreshTokenReturnsOnCall(i int, result1 error) {
|
||||
fake.sendRefreshTokenMutex.Lock()
|
||||
defer fake.sendRefreshTokenMutex.Unlock()
|
||||
fake.SendRefreshTokenStub = nil
|
||||
if fake.sendRefreshTokenReturnsOnCall == nil {
|
||||
fake.sendRefreshTokenReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.sendRefreshTokenReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendRoomUpdate(arg1 *livekit.Room) error {
|
||||
fake.sendRoomUpdateMutex.Lock()
|
||||
ret, specificReturn := fake.sendRoomUpdateReturnsOnCall[len(fake.sendRoomUpdateArgsForCall)]
|
||||
@@ -3625,6 +3798,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.canPublishDataMutex.RUnlock()
|
||||
fake.canSubscribeMutex.RLock()
|
||||
defer fake.canSubscribeMutex.RUnlock()
|
||||
fake.claimGrantsMutex.RLock()
|
||||
defer fake.claimGrantsMutex.RUnlock()
|
||||
fake.closeMutex.RLock()
|
||||
defer fake.closeMutex.RUnlock()
|
||||
fake.connectedAtMutex.RLock()
|
||||
@@ -3667,6 +3842,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.migrateStateMutex.RUnlock()
|
||||
fake.negotiateMutex.RLock()
|
||||
defer fake.negotiateMutex.RUnlock()
|
||||
fake.onClaimsChangedMutex.RLock()
|
||||
defer fake.onClaimsChangedMutex.RUnlock()
|
||||
fake.onCloseMutex.RLock()
|
||||
defer fake.onCloseMutex.RUnlock()
|
||||
fake.onDataPacketMutex.RLock()
|
||||
@@ -3693,6 +3870,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.sendJoinResponseMutex.RUnlock()
|
||||
fake.sendParticipantUpdateMutex.RLock()
|
||||
defer fake.sendParticipantUpdateMutex.RUnlock()
|
||||
fake.sendRefreshTokenMutex.RLock()
|
||||
defer fake.sendRefreshTokenMutex.RUnlock()
|
||||
fake.sendRoomUpdateMutex.RLock()
|
||||
defer fake.sendRoomUpdateMutex.RUnlock()
|
||||
fake.sendSpeakerUpdateMutex.RLock()
|
||||
|
||||
Reference in New Issue
Block a user