Send error response when update metadata fails. (#2849)
Keeping it simple for the first implementation. - Send error response only if request_id != 0 - Two kinds of errors notified o does not have permissions - NOT_ALLOWED o attributes exceeds size limits - INVALID_ARGUMENT
This commit is contained in:
@@ -197,6 +197,18 @@ func (p *ParticipantImpl) SendRefreshToken(token string) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) SendErrorResponse(errorResponse *livekit.ErrorResponse) error {
|
||||||
|
if errorResponse.RequestId == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.writeMessage(&livekit.SignalResponse{
|
||||||
|
Message: &livekit.SignalResponse_ErrorResponse{
|
||||||
|
ErrorResponse: errorResponse,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) HandleReconnectAndSendResponse(reconnectReason livekit.ReconnectReason, reconnectResponse *livekit.ReconnectResponse) error {
|
func (p *ParticipantImpl) HandleReconnectAndSendResponse(reconnectReason livekit.ReconnectReason, reconnectResponse *livekit.ReconnectResponse) error {
|
||||||
p.TransportManager.HandleClientReconnect(reconnectReason)
|
p.TransportManager.HandleClientReconnect(reconnectReason)
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ func HandleParticipantSignal(room types.Room, participant types.LocalParticipant
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *livekit.SignalRequest_UpdateMetadata:
|
case *livekit.SignalRequest_UpdateMetadata:
|
||||||
|
var errorResponse *livekit.ErrorResponse
|
||||||
if participant.ClaimGrants().Video.GetCanUpdateOwnMetadata() {
|
if participant.ClaimGrants().Video.GetCanUpdateOwnMetadata() {
|
||||||
err := room.UpdateParticipantMetadata(
|
err := room.UpdateParticipantMetadata(
|
||||||
participant,
|
participant,
|
||||||
@@ -101,7 +102,25 @@ func HandleParticipantSignal(room types.Room, participant types.LocalParticipant
|
|||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pLogger.Warnw("could not update metadata", err)
|
pLogger.Warnw("could not update metadata", err)
|
||||||
|
|
||||||
|
switch err {
|
||||||
|
case ErrAttributeExceedsLimits:
|
||||||
|
errorResponse = &livekit.ErrorResponse{
|
||||||
|
Reason: livekit.ErrorResponse_INVALID_ARGUMENT,
|
||||||
|
Message: "exceeds attributes size limit",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
errorResponse = &livekit.ErrorResponse{
|
||||||
|
Reason: livekit.ErrorResponse_NOT_ALLOWED,
|
||||||
|
Message: "does not have permission to update own metadata",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if errorResponse != nil {
|
||||||
|
errorResponse.RequestId = msg.UpdateMetadata.RequestId
|
||||||
|
participant.SendErrorResponse(errorResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *livekit.SignalRequest_UpdateAudioTrack:
|
case *livekit.SignalRequest_UpdateAudioTrack:
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ type LocalParticipant interface {
|
|||||||
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
||||||
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
||||||
SendRefreshToken(token string) error
|
SendRefreshToken(token string) error
|
||||||
|
SendErrorResponse(errorResponse *livekit.ErrorResponse) error
|
||||||
HandleReconnectAndSendResponse(reconnectReason livekit.ReconnectReason, reconnectResponse *livekit.ReconnectResponse) error
|
HandleReconnectAndSendResponse(reconnectReason livekit.ReconnectReason, reconnectResponse *livekit.ReconnectResponse) error
|
||||||
IssueFullReconnect(reason ParticipantCloseReason)
|
IssueFullReconnect(reason ParticipantCloseReason)
|
||||||
|
|
||||||
|
|||||||
@@ -677,6 +677,17 @@ type FakeLocalParticipant struct {
|
|||||||
sendDataPacketReturnsOnCall map[int]struct {
|
sendDataPacketReturnsOnCall map[int]struct {
|
||||||
result1 error
|
result1 error
|
||||||
}
|
}
|
||||||
|
SendErrorResponseStub func(*livekit.ErrorResponse) error
|
||||||
|
sendErrorResponseMutex sync.RWMutex
|
||||||
|
sendErrorResponseArgsForCall []struct {
|
||||||
|
arg1 *livekit.ErrorResponse
|
||||||
|
}
|
||||||
|
sendErrorResponseReturns struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
|
sendErrorResponseReturnsOnCall map[int]struct {
|
||||||
|
result1 error
|
||||||
|
}
|
||||||
SendJoinResponseStub func(*livekit.JoinResponse) error
|
SendJoinResponseStub func(*livekit.JoinResponse) error
|
||||||
sendJoinResponseMutex sync.RWMutex
|
sendJoinResponseMutex sync.RWMutex
|
||||||
sendJoinResponseArgsForCall []struct {
|
sendJoinResponseArgsForCall []struct {
|
||||||
@@ -4576,6 +4587,67 @@ func (fake *FakeLocalParticipant) SendDataPacketReturnsOnCall(i int, result1 err
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponse(arg1 *livekit.ErrorResponse) error {
|
||||||
|
fake.sendErrorResponseMutex.Lock()
|
||||||
|
ret, specificReturn := fake.sendErrorResponseReturnsOnCall[len(fake.sendErrorResponseArgsForCall)]
|
||||||
|
fake.sendErrorResponseArgsForCall = append(fake.sendErrorResponseArgsForCall, struct {
|
||||||
|
arg1 *livekit.ErrorResponse
|
||||||
|
}{arg1})
|
||||||
|
stub := fake.SendErrorResponseStub
|
||||||
|
fakeReturns := fake.sendErrorResponseReturns
|
||||||
|
fake.recordInvocation("SendErrorResponse", []interface{}{arg1})
|
||||||
|
fake.sendErrorResponseMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub(arg1)
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponseCallCount() int {
|
||||||
|
fake.sendErrorResponseMutex.RLock()
|
||||||
|
defer fake.sendErrorResponseMutex.RUnlock()
|
||||||
|
return len(fake.sendErrorResponseArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponseCalls(stub func(*livekit.ErrorResponse) error) {
|
||||||
|
fake.sendErrorResponseMutex.Lock()
|
||||||
|
defer fake.sendErrorResponseMutex.Unlock()
|
||||||
|
fake.SendErrorResponseStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponseArgsForCall(i int) *livekit.ErrorResponse {
|
||||||
|
fake.sendErrorResponseMutex.RLock()
|
||||||
|
defer fake.sendErrorResponseMutex.RUnlock()
|
||||||
|
argsForCall := fake.sendErrorResponseArgsForCall[i]
|
||||||
|
return argsForCall.arg1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponseReturns(result1 error) {
|
||||||
|
fake.sendErrorResponseMutex.Lock()
|
||||||
|
defer fake.sendErrorResponseMutex.Unlock()
|
||||||
|
fake.SendErrorResponseStub = nil
|
||||||
|
fake.sendErrorResponseReturns = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SendErrorResponseReturnsOnCall(i int, result1 error) {
|
||||||
|
fake.sendErrorResponseMutex.Lock()
|
||||||
|
defer fake.sendErrorResponseMutex.Unlock()
|
||||||
|
fake.SendErrorResponseStub = nil
|
||||||
|
if fake.sendErrorResponseReturnsOnCall == nil {
|
||||||
|
fake.sendErrorResponseReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.sendErrorResponseReturnsOnCall[i] = struct {
|
||||||
|
result1 error
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) SendJoinResponse(arg1 *livekit.JoinResponse) error {
|
func (fake *FakeLocalParticipant) SendJoinResponse(arg1 *livekit.JoinResponse) error {
|
||||||
fake.sendJoinResponseMutex.Lock()
|
fake.sendJoinResponseMutex.Lock()
|
||||||
ret, specificReturn := fake.sendJoinResponseReturnsOnCall[len(fake.sendJoinResponseArgsForCall)]
|
ret, specificReturn := fake.sendJoinResponseReturnsOnCall[len(fake.sendJoinResponseArgsForCall)]
|
||||||
@@ -6633,6 +6705,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.sendConnectionQualityUpdateMutex.RUnlock()
|
defer fake.sendConnectionQualityUpdateMutex.RUnlock()
|
||||||
fake.sendDataPacketMutex.RLock()
|
fake.sendDataPacketMutex.RLock()
|
||||||
defer fake.sendDataPacketMutex.RUnlock()
|
defer fake.sendDataPacketMutex.RUnlock()
|
||||||
|
fake.sendErrorResponseMutex.RLock()
|
||||||
|
defer fake.sendErrorResponseMutex.RUnlock()
|
||||||
fake.sendJoinResponseMutex.RLock()
|
fake.sendJoinResponseMutex.RLock()
|
||||||
defer fake.sendJoinResponseMutex.RUnlock()
|
defer fake.sendJoinResponseMutex.RUnlock()
|
||||||
fake.sendParticipantUpdateMutex.RLock()
|
fake.sendParticipantUpdateMutex.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user