mirror of
https://github.com/livekit/livekit.git
synced 2026-08-06 23:39:43 +00:00
Add ParticipantActive telemetry method (#411)
* Add ParticipantActive telemetry method Signed-off-by: shishir gowda <shishir@livekit.io> * fix test Signed-off-by: shishir gowda <shishir@livekit.io> * Update go mod 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.12
|
||||
github.com/livekit/protocol v0.11.13-0.20220207221412-40df25091bcb
|
||||
github.com/magefile/mage v1.11.0
|
||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
|
||||
@@ -132,8 +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.12 h1:34ehSXSDUvHAhIw/LKz6TZaSesXnTMBstbdfiIoeah0=
|
||||
github.com/livekit/protocol v0.11.12/go.mod h1:YoHW9YbWbPnuVsgwBB4hAINKT+V68jmfh9zXBSSn6Wg=
|
||||
github.com/livekit/protocol v0.11.13-0.20220207221412-40df25091bcb h1:oAx83edonLEOfsZardevXlHqzut6dEBIH9fOU/ZxDfU=
|
||||
github.com/livekit/protocol v0.11.13-0.20220207221412-40df25091bcb/go.mod h1:YoHW9YbWbPnuVsgwBB4hAINKT+V68jmfh9zXBSSn6Wg=
|
||||
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=
|
||||
|
||||
@@ -26,6 +26,7 @@ type TelemetryService interface {
|
||||
TrackPublishedUpdate(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
|
||||
RecordingStarted(ctx context.Context, ri *livekit.RecordingInfo)
|
||||
RecordingEnded(ctx context.Context, ri *livekit.RecordingInfo)
|
||||
ParticipantActive(ctx context.Context, participantID livekit.ParticipantID, clientMeta *livekit.AnalyticsClientMeta)
|
||||
}
|
||||
|
||||
type doWorkFunc func()
|
||||
@@ -135,3 +136,9 @@ func (t *telemetryService) TrackPublishedUpdate(ctx context.Context, participant
|
||||
t.internalService.TrackPublishedUpdate(ctx, participantID, track)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) ParticipantActive(ctx context.Context, participantID livekit.ParticipantID, clientMeta *livekit.AnalyticsClientMeta) {
|
||||
t.jobQueue <- func() {
|
||||
t.internalService.ParticipantActive(ctx, participantID, clientMeta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,3 +219,16 @@ func (t *telemetryServiceInternal) notifyEvent(ctx context.Context, event *livek
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryServiceInternal) ParticipantActive(ctx context.Context, participantID livekit.ParticipantID, clientMeta *livekit.AnalyticsClientMeta) {
|
||||
roomID, roomName := t.getRoomDetails(participantID)
|
||||
|
||||
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_PARTICIPANT_ACTIVE,
|
||||
Timestamp: timestamppb.Now(),
|
||||
RoomId: string(roomID),
|
||||
ParticipantId: string(participantID),
|
||||
Room: &livekit.Room{Name: string(roomName)},
|
||||
ClientMeta: clientMeta,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -109,3 +109,50 @@ func Test_OnTrackUpdate_EventIsSent(t *testing.T) {
|
||||
require.Equal(t, height, event.Track.Height)
|
||||
|
||||
}
|
||||
|
||||
func Test_OnParticipantActive_EventIsSent(t *testing.T) {
|
||||
fixture := createFixture()
|
||||
|
||||
// prepare participant to change status
|
||||
room := &livekit.Room{Sid: "RoomSid", Name: "RoomName"}
|
||||
partSID := "part1"
|
||||
|
||||
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)
|
||||
|
||||
// test
|
||||
// do
|
||||
clientMetaConnect := &livekit.AnalyticsClientMeta{
|
||||
ClientConnectTime: 420,
|
||||
}
|
||||
fixture.sut.ParticipantActive(context.Background(), livekit.ParticipantID(partSID), clientMetaConnect)
|
||||
|
||||
require.Equal(t, 2, fixture.analytics.SendEventCallCount())
|
||||
_, eventActive := fixture.analytics.SendEventArgsForCall(1)
|
||||
require.Equal(t, livekit.AnalyticsEventType_PARTICIPANT_ACTIVE, eventActive.Type)
|
||||
require.Equal(t, partSID, eventActive.ParticipantId)
|
||||
require.Equal(t, room.Sid, eventActive.RoomId)
|
||||
require.Equal(t, room, event.Room)
|
||||
|
||||
require.Equal(t, clientMetaConnect.ClientConnectTime, eventActive.ClientMeta.ClientConnectTime)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user