add track publisher info in track subscribed event (#473)
* add track publisher info in track subscribed event Signed-off-by: shishir gowda <shishir@livekit.io> * update protocol ver Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
@@ -14,7 +14,7 @@ require (
|
||||
github.com/google/wire v0.5.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/hashicorp/golang-lru v0.5.4
|
||||
github.com/livekit/protocol v0.11.14-0.20220225092016-4b44edff9ed7
|
||||
github.com/livekit/protocol v0.11.14-0.20220228184153-f3ffabe24080
|
||||
github.com/magefile/mage v1.11.0
|
||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
|
||||
@@ -132,10 +132,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
|
||||
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
|
||||
github.com/livekit/protocol v0.11.14-0.20220223230744-2d72f8bc52aa h1:3eJ92nyh9krLpbkz2TB4Dtc4oDLO86sznNxQR2sb614=
|
||||
github.com/livekit/protocol v0.11.14-0.20220223230744-2d72f8bc52aa/go.mod h1:3pHsWUtQmWaH8mG0cXrQWpbf3Vo+kj0U+In77CEXu90=
|
||||
github.com/livekit/protocol v0.11.14-0.20220225092016-4b44edff9ed7 h1:SrUiL7cKfSMGGQBgzZlNGL+wcKXEO//C7j6CQ3zjxHA=
|
||||
github.com/livekit/protocol v0.11.14-0.20220225092016-4b44edff9ed7/go.mod h1:3pHsWUtQmWaH8mG0cXrQWpbf3Vo+kj0U+In77CEXu90=
|
||||
github.com/livekit/protocol v0.11.14-0.20220228184153-f3ffabe24080 h1:h/S/EQYCsuQFWlyWsoXmdLvaCDlneFKbIc1UVyLcTnM=
|
||||
github.com/livekit/protocol v0.11.14-0.20220228184153-f3ffabe24080/go.mod h1:3pHsWUtQmWaH8mG0cXrQWpbf3Vo+kj0U+In77CEXu90=
|
||||
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
|
||||
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
|
||||
@@ -259,8 +259,8 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code
|
||||
|
||||
// initialize to default layer
|
||||
t.notifySubscriberMaxQuality(subscriberID, livekit.VideoQuality_HIGH)
|
||||
|
||||
t.params.Telemetry.TrackSubscribed(context.Background(), subscriberID, t.params.MediaTrack.ToProto())
|
||||
t.params.Telemetry.TrackSubscribed(context.Background(), subscriberID, t.params.MediaTrack.ToProto(),
|
||||
&livekit.ParticipantInfo{Sid: string(t.params.MediaTrack.PublisherID()), Identity: string(t.params.MediaTrack.PublisherIdentity())})
|
||||
return downTrack, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -99,12 +99,13 @@ type FakeTelemetryService struct {
|
||||
arg3 livekit.TrackID
|
||||
arg4 *livekit.AnalyticsStat
|
||||
}
|
||||
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)
|
||||
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)
|
||||
trackSubscribedMutex sync.RWMutex
|
||||
trackSubscribedArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
arg2 livekit.ParticipantID
|
||||
arg3 *livekit.TrackInfo
|
||||
arg4 *livekit.ParticipantInfo
|
||||
}
|
||||
TrackUnpublishedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, uint32)
|
||||
trackUnpublishedMutex sync.RWMutex
|
||||
@@ -565,18 +566,19 @@ func (fake *FakeTelemetryService) TrackStatsArgsForCall(i int) (livekit.StreamTy
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo) {
|
||||
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo) {
|
||||
fake.trackSubscribedMutex.Lock()
|
||||
fake.trackSubscribedArgsForCall = append(fake.trackSubscribedArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
arg2 livekit.ParticipantID
|
||||
arg3 *livekit.TrackInfo
|
||||
}{arg1, arg2, arg3})
|
||||
arg4 *livekit.ParticipantInfo
|
||||
}{arg1, arg2, arg3, arg4})
|
||||
stub := fake.TrackSubscribedStub
|
||||
fake.recordInvocation("TrackSubscribed", []interface{}{arg1, arg2, arg3})
|
||||
fake.recordInvocation("TrackSubscribed", []interface{}{arg1, arg2, arg3, arg4})
|
||||
fake.trackSubscribedMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.TrackSubscribedStub(arg1, arg2, arg3)
|
||||
fake.TrackSubscribedStub(arg1, arg2, arg3, arg4)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,17 +588,17 @@ func (fake *FakeTelemetryService) TrackSubscribedCallCount() int {
|
||||
return len(fake.trackSubscribedArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) TrackSubscribedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)) {
|
||||
func (fake *FakeTelemetryService) TrackSubscribedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)) {
|
||||
fake.trackSubscribedMutex.Lock()
|
||||
defer fake.trackSubscribedMutex.Unlock()
|
||||
fake.TrackSubscribedStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) TrackSubscribedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo) {
|
||||
func (fake *FakeTelemetryService) TrackSubscribedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo) {
|
||||
fake.trackSubscribedMutex.RLock()
|
||||
defer fake.trackSubscribedMutex.RUnlock()
|
||||
argsForCall := fake.trackSubscribedArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) TrackUnpublished(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 uint32) {
|
||||
|
||||
@@ -22,7 +22,7 @@ type TelemetryService interface {
|
||||
ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo)
|
||||
TrackPublished(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
|
||||
TrackUnpublished(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, ssrc uint32)
|
||||
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
|
||||
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo)
|
||||
TrackUnsubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
|
||||
TrackPublishedUpdate(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
|
||||
TrackMaxSubscribedVideoQuality(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, maxQuality livekit.VideoQuality)
|
||||
@@ -111,9 +111,9 @@ func (t *telemetryService) TrackUnpublished(ctx context.Context, participantID l
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo) {
|
||||
func (t *telemetryService) TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo) {
|
||||
t.jobQueue <- func() {
|
||||
t.internalService.TrackSubscribed(ctx, participantID, track)
|
||||
t.internalService.TrackSubscribed(ctx, participantID, track, publisher)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ func (t *telemetryServiceInternal) TrackUnpublished(ctx context.Context, partici
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryServiceInternal) TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo) {
|
||||
func (t *telemetryServiceInternal) TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo,
|
||||
publisher *livekit.ParticipantInfo) {
|
||||
prometheus.AddSubscribedTrack(track.Type.String())
|
||||
|
||||
roomID, roomName := t.getRoomDetails(participantID)
|
||||
@@ -167,6 +168,7 @@ func (t *telemetryServiceInternal) TrackSubscribed(ctx context.Context, particip
|
||||
ParticipantId: string(participantID),
|
||||
Track: track,
|
||||
Room: &livekit.Room{Name: string(roomName)},
|
||||
Publisher: publisher,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -156,3 +156,52 @@ func Test_OnParticipantActive_EventIsSent(t *testing.T) {
|
||||
|
||||
require.Equal(t, clientMetaConnect.ClientConnectTime, eventActive.ClientMeta.ClientConnectTime)
|
||||
}
|
||||
|
||||
func Test_OnTrackSubscribed_EventIsSent(t *testing.T) {
|
||||
fixture := createFixture()
|
||||
|
||||
// prepare participant to change status
|
||||
room := &livekit.Room{Sid: "RoomSid", Name: "RoomName"}
|
||||
partSID := "part1"
|
||||
publisherInfo := &livekit.ParticipantInfo{Sid: "pub1", Identity: "publisher"}
|
||||
trackInfo := &livekit.TrackInfo{Sid: "tr1", Type: livekit.TrackType_VIDEO}
|
||||
|
||||
clientInfo := &livekit.ClientInfo{
|
||||
Sdk: 2,
|
||||
Version: "v1",
|
||||
Os: "mac",
|
||||
OsVersion: "v1",
|
||||
DeviceModel: "DM1",
|
||||
Browser: "chrome",
|
||||
BrowserVersion: "97.0.1",
|
||||
}
|
||||
clientMeta := &livekit.AnalyticsClientMeta{
|
||||
Region: "dark-side",
|
||||
Node: "moon",
|
||||
ClientAddr: "127.0.0.1",
|
||||
}
|
||||
participantInfo := &livekit.ParticipantInfo{Sid: partSID}
|
||||
|
||||
// do
|
||||
fixture.sut.ParticipantJoined(context.Background(), room, participantInfo, clientInfo, clientMeta)
|
||||
|
||||
// test
|
||||
require.Equal(t, 1, fixture.analytics.SendEventCallCount())
|
||||
_, event := fixture.analytics.SendEventArgsForCall(0)
|
||||
require.Equal(t, room, event.Room)
|
||||
|
||||
// test
|
||||
// do
|
||||
|
||||
fixture.sut.TrackSubscribed(context.Background(), livekit.ParticipantID(partSID), trackInfo, publisherInfo)
|
||||
|
||||
require.Equal(t, 2, fixture.analytics.SendEventCallCount())
|
||||
_, eventTrackSubscribed := fixture.analytics.SendEventArgsForCall(1)
|
||||
require.Equal(t, livekit.AnalyticsEventType_TRACK_SUBSCRIBED, eventTrackSubscribed.Type)
|
||||
require.Equal(t, partSID, eventTrackSubscribed.ParticipantId)
|
||||
require.Equal(t, trackInfo.Sid, eventTrackSubscribed.Track.Sid)
|
||||
require.Equal(t, trackInfo.Type, eventTrackSubscribed.Track.Type)
|
||||
require.Equal(t, publisherInfo.Sid, eventTrackSubscribed.Publisher.Sid)
|
||||
require.Equal(t, publisherInfo.Identity, eventTrackSubscribed.Publisher.Identity)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user