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:
@@ -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