Fix participant update version generation. (#477)
Previously it was stuck at 1
This commit is contained in:
@@ -107,7 +107,7 @@ type ParticipantImpl struct {
|
|||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
once sync.Once
|
once sync.Once
|
||||||
updateLock sync.Mutex
|
updateLock sync.Mutex
|
||||||
version uint32
|
version atomic.Uint32
|
||||||
|
|
||||||
dataTrack *DataTrack
|
dataTrack *DataTrack
|
||||||
|
|
||||||
@@ -137,8 +137,8 @@ func NewParticipant(params ParticipantParams, perms *livekit.ParticipantPermissi
|
|||||||
disallowedSubscriptions: make(map[livekit.TrackID]livekit.ParticipantID),
|
disallowedSubscriptions: make(map[livekit.TrackID]livekit.ParticipantID),
|
||||||
connectedAt: time.Now(),
|
connectedAt: time.Now(),
|
||||||
rttUpdatedAt: time.Now(),
|
rttUpdatedAt: time.Now(),
|
||||||
version: params.InitialVersion,
|
|
||||||
}
|
}
|
||||||
|
p.version.Store(params.InitialVersion)
|
||||||
p.migrateState.Store(types.MigrateStateInit)
|
p.migrateState.Store(types.MigrateStateInit)
|
||||||
p.state.Store(livekit.ParticipantInfo_JOINING)
|
p.state.Store(livekit.ParticipantInfo_JOINING)
|
||||||
p.SetPermission(perms)
|
p.SetPermission(perms)
|
||||||
@@ -307,7 +307,7 @@ func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
|||||||
JoinedAt: p.ConnectedAt().Unix(),
|
JoinedAt: p.ConnectedAt().Unix(),
|
||||||
Hidden: p.Hidden(),
|
Hidden: p.Hidden(),
|
||||||
Recorder: p.IsRecorder(),
|
Recorder: p.IsRecorder(),
|
||||||
Version: atomic.NewUint32(p.version).Inc(),
|
Version: p.version.Inc(),
|
||||||
}
|
}
|
||||||
info.Tracks = p.UpTrackManager.ToProto()
|
info.Tracks = p.UpTrackManager.ToProto()
|
||||||
if p.params.Grants != nil {
|
if p.params.Grants != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -167,27 +168,22 @@ func TestTrackPublishing(t *testing.T) {
|
|||||||
|
|
||||||
func TestOutOfOrderUpdates(t *testing.T) {
|
func TestOutOfOrderUpdates(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
p.SetMetadata("initial metadata")
|
||||||
sink := p.GetResponseSink().(*routingfakes.FakeMessageSink)
|
sink := p.GetResponseSink().(*routingfakes.FakeMessageSink)
|
||||||
pi := &livekit.ParticipantInfo{
|
pi1 := p.ToProto()
|
||||||
Sid: "PA_test2",
|
p.SetMetadata("second update")
|
||||||
Identity: "test2",
|
pi2 := p.ToProto()
|
||||||
Metadata: "123",
|
|
||||||
Version: 2,
|
|
||||||
}
|
|
||||||
require.NoError(t, p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi}))
|
|
||||||
|
|
||||||
pi = &livekit.ParticipantInfo{
|
require.Greater(t, pi2.Version, pi1.Version)
|
||||||
Sid: "PA_test2",
|
|
||||||
Identity: "test2",
|
// send the second update first
|
||||||
Metadata: "456",
|
require.NoError(t, p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi2}))
|
||||||
Version: 1,
|
require.NoError(t, p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi1}))
|
||||||
}
|
|
||||||
require.NoError(t, p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi}))
|
|
||||||
|
|
||||||
// only sent once, and it's the earlier message
|
// only sent once, and it's the earlier message
|
||||||
require.Equal(t, 1, sink.WriteMessageCallCount())
|
require.Equal(t, 1, sink.WriteMessageCallCount())
|
||||||
sent := sink.WriteMessageArgsForCall(0).(*livekit.SignalResponse)
|
sent := sink.WriteMessageArgsForCall(0).(*livekit.SignalResponse)
|
||||||
require.Equal(t, "123", sent.GetUpdate().Participants[0].Metadata)
|
require.Equal(t, "second update", sent.GetUpdate().Participants[0].Metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// after disconnection, things should continue to function and not panic
|
// after disconnection, things should continue to function and not panic
|
||||||
@@ -373,6 +369,9 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
|||||||
Sink: &routingfakes.FakeMessageSink{},
|
Sink: &routingfakes.FakeMessageSink{},
|
||||||
ProtocolVersion: opts.protocolVersion,
|
ProtocolVersion: opts.protocolVersion,
|
||||||
PLIThrottleConfig: conf.RTC.PLIThrottle,
|
PLIThrottleConfig: conf.RTC.PLIThrottle,
|
||||||
|
Grants: &auth.ClaimGrants{
|
||||||
|
Video: &auth.VideoGrant{},
|
||||||
|
},
|
||||||
}, opts.permissions)
|
}, opts.permissions)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
@@ -21,6 +19,7 @@ import (
|
|||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Injectors from wire.go:
|
// Injectors from wire.go:
|
||||||
|
|||||||
Reference in New Issue
Block a user