Do not send ParticipantJoined webhook if connection was resumed (#1795)
* Do not send ParticipantJoined webhook if connection was resumed * isResume -> isMigration
This commit is contained in:
+9
-4
@@ -280,10 +280,15 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
|||||||
// start the workers once connectivity is established
|
// start the workers once connectivity is established
|
||||||
p.Start()
|
p.Start()
|
||||||
|
|
||||||
r.telemetry.ParticipantActive(context.Background(), r.ToProto(), p.ToProto(), &livekit.AnalyticsClientMeta{
|
r.telemetry.ParticipantActive(context.Background(),
|
||||||
ClientConnectTime: uint32(time.Since(p.ConnectedAt()).Milliseconds()),
|
r.ToProto(),
|
||||||
ConnectionType: string(p.GetICEConnectionType()),
|
p.ToProto(),
|
||||||
})
|
&livekit.AnalyticsClientMeta{
|
||||||
|
ClientConnectTime: uint32(time.Since(p.ConnectedAt()).Milliseconds()),
|
||||||
|
ConnectionType: string(p.GetICEConnectionType()),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
)
|
||||||
} else if state == livekit.ParticipantInfo_DISCONNECTED {
|
} else if state == livekit.ParticipantInfo_DISCONNECTED {
|
||||||
// remove participant from room
|
// remove participant from room
|
||||||
go r.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonStateDisconnected)
|
go r.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonStateDisconnected)
|
||||||
|
|||||||
@@ -91,14 +91,17 @@ func (t *telemetryService) ParticipantActive(
|
|||||||
room *livekit.Room,
|
room *livekit.Room,
|
||||||
participant *livekit.ParticipantInfo,
|
participant *livekit.ParticipantInfo,
|
||||||
clientMeta *livekit.AnalyticsClientMeta,
|
clientMeta *livekit.AnalyticsClientMeta,
|
||||||
|
isMigration bool,
|
||||||
) {
|
) {
|
||||||
t.enqueue(func() {
|
t.enqueue(func() {
|
||||||
// consider participant joined only when they became active
|
if !isMigration {
|
||||||
t.NotifyEvent(ctx, &livekit.WebhookEvent{
|
// consider participant joined only when they became active
|
||||||
Event: webhook.EventParticipantJoined,
|
t.NotifyEvent(ctx, &livekit.WebhookEvent{
|
||||||
Room: room,
|
Event: webhook.EventParticipantJoined,
|
||||||
Participant: participant,
|
Room: room,
|
||||||
})
|
Participant: participant,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid))
|
worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid))
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func Test_OnParticipantLeft_EventIsSent(t *testing.T) {
|
|||||||
participantInfo := &livekit.ParticipantInfo{Sid: partSID}
|
participantInfo := &livekit.ParticipantInfo{Sid: partSID}
|
||||||
|
|
||||||
// do
|
// do
|
||||||
fixture.sut.ParticipantActive(context.Background(), room, participantInfo, &livekit.AnalyticsClientMeta{})
|
fixture.sut.ParticipantActive(context.Background(), room, participantInfo, &livekit.AnalyticsClientMeta{}, false)
|
||||||
fixture.sut.ParticipantLeft(context.Background(), room, participantInfo, true)
|
fixture.sut.ParticipantLeft(context.Background(), room, participantInfo, true)
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ func Test_OnParticipantActive_EventIsSent(t *testing.T) {
|
|||||||
ClientConnectTime: 420,
|
ClientConnectTime: 420,
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture.sut.ParticipantActive(context.Background(), room, participantInfo, clientMetaConnect)
|
fixture.sut.ParticipantActive(context.Background(), room, participantInfo, clientMetaConnect, false)
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
require.Equal(t, 2, fixture.analytics.SendEventCallCount())
|
require.Equal(t, 2, fixture.analytics.SendEventCallCount())
|
||||||
|
|||||||
@@ -62,13 +62,14 @@ type FakeTelemetryService struct {
|
|||||||
arg1 context.Context
|
arg1 context.Context
|
||||||
arg2 *livekit.WebhookEvent
|
arg2 *livekit.WebhookEvent
|
||||||
}
|
}
|
||||||
ParticipantActiveStub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta)
|
ParticipantActiveStub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta, bool)
|
||||||
participantActiveMutex sync.RWMutex
|
participantActiveMutex sync.RWMutex
|
||||||
participantActiveArgsForCall []struct {
|
participantActiveArgsForCall []struct {
|
||||||
arg1 context.Context
|
arg1 context.Context
|
||||||
arg2 *livekit.Room
|
arg2 *livekit.Room
|
||||||
arg3 *livekit.ParticipantInfo
|
arg3 *livekit.ParticipantInfo
|
||||||
arg4 *livekit.AnalyticsClientMeta
|
arg4 *livekit.AnalyticsClientMeta
|
||||||
|
arg5 bool
|
||||||
}
|
}
|
||||||
ParticipantJoinedStub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.ClientInfo, *livekit.AnalyticsClientMeta, bool)
|
ParticipantJoinedStub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.ClientInfo, *livekit.AnalyticsClientMeta, bool)
|
||||||
participantJoinedMutex sync.RWMutex
|
participantJoinedMutex sync.RWMutex
|
||||||
@@ -526,19 +527,20 @@ func (fake *FakeTelemetryService) NotifyEventArgsForCall(i int) (context.Context
|
|||||||
return argsForCall.arg1, argsForCall.arg2
|
return argsForCall.arg1, argsForCall.arg2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeTelemetryService) ParticipantActive(arg1 context.Context, arg2 *livekit.Room, arg3 *livekit.ParticipantInfo, arg4 *livekit.AnalyticsClientMeta) {
|
func (fake *FakeTelemetryService) ParticipantActive(arg1 context.Context, arg2 *livekit.Room, arg3 *livekit.ParticipantInfo, arg4 *livekit.AnalyticsClientMeta, arg5 bool) {
|
||||||
fake.participantActiveMutex.Lock()
|
fake.participantActiveMutex.Lock()
|
||||||
fake.participantActiveArgsForCall = append(fake.participantActiveArgsForCall, struct {
|
fake.participantActiveArgsForCall = append(fake.participantActiveArgsForCall, struct {
|
||||||
arg1 context.Context
|
arg1 context.Context
|
||||||
arg2 *livekit.Room
|
arg2 *livekit.Room
|
||||||
arg3 *livekit.ParticipantInfo
|
arg3 *livekit.ParticipantInfo
|
||||||
arg4 *livekit.AnalyticsClientMeta
|
arg4 *livekit.AnalyticsClientMeta
|
||||||
}{arg1, arg2, arg3, arg4})
|
arg5 bool
|
||||||
|
}{arg1, arg2, arg3, arg4, arg5})
|
||||||
stub := fake.ParticipantActiveStub
|
stub := fake.ParticipantActiveStub
|
||||||
fake.recordInvocation("ParticipantActive", []interface{}{arg1, arg2, arg3, arg4})
|
fake.recordInvocation("ParticipantActive", []interface{}{arg1, arg2, arg3, arg4, arg5})
|
||||||
fake.participantActiveMutex.Unlock()
|
fake.participantActiveMutex.Unlock()
|
||||||
if stub != nil {
|
if stub != nil {
|
||||||
fake.ParticipantActiveStub(arg1, arg2, arg3, arg4)
|
fake.ParticipantActiveStub(arg1, arg2, arg3, arg4, arg5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,17 +550,17 @@ func (fake *FakeTelemetryService) ParticipantActiveCallCount() int {
|
|||||||
return len(fake.participantActiveArgsForCall)
|
return len(fake.participantActiveArgsForCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeTelemetryService) ParticipantActiveCalls(stub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta)) {
|
func (fake *FakeTelemetryService) ParticipantActiveCalls(stub func(context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta, bool)) {
|
||||||
fake.participantActiveMutex.Lock()
|
fake.participantActiveMutex.Lock()
|
||||||
defer fake.participantActiveMutex.Unlock()
|
defer fake.participantActiveMutex.Unlock()
|
||||||
fake.ParticipantActiveStub = stub
|
fake.ParticipantActiveStub = stub
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeTelemetryService) ParticipantActiveArgsForCall(i int) (context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta) {
|
func (fake *FakeTelemetryService) ParticipantActiveArgsForCall(i int) (context.Context, *livekit.Room, *livekit.ParticipantInfo, *livekit.AnalyticsClientMeta, bool) {
|
||||||
fake.participantActiveMutex.RLock()
|
fake.participantActiveMutex.RLock()
|
||||||
defer fake.participantActiveMutex.RUnlock()
|
defer fake.participantActiveMutex.RUnlock()
|
||||||
argsForCall := fake.participantActiveArgsForCall[i]
|
argsForCall := fake.participantActiveArgsForCall[i]
|
||||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeTelemetryService) ParticipantJoined(arg1 context.Context, arg2 *livekit.Room, arg3 *livekit.ParticipantInfo, arg4 *livekit.ClientInfo, arg5 *livekit.AnalyticsClientMeta, arg6 bool) {
|
func (fake *FakeTelemetryService) ParticipantJoined(arg1 context.Context, arg2 *livekit.Room, arg3 *livekit.ParticipantInfo, arg4 *livekit.ClientInfo, arg5 *livekit.AnalyticsClientMeta, arg6 bool) {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ type TelemetryService interface {
|
|||||||
// ParticipantJoined - a participant establishes signal connection to a room
|
// ParticipantJoined - a participant establishes signal connection to a room
|
||||||
ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, clientInfo *livekit.ClientInfo, clientMeta *livekit.AnalyticsClientMeta, shouldSendEvent bool)
|
ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, clientInfo *livekit.ClientInfo, clientMeta *livekit.AnalyticsClientMeta, shouldSendEvent bool)
|
||||||
// ParticipantActive - a participant establishes media connection
|
// ParticipantActive - a participant establishes media connection
|
||||||
ParticipantActive(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, clientMeta *livekit.AnalyticsClientMeta)
|
ParticipantActive(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, clientMeta *livekit.AnalyticsClientMeta, isMigration bool)
|
||||||
// ParticipantResumed - there has been an ICE restart or connection resume attempt
|
// ParticipantResumed - there has been an ICE restart or connection resume attempt, and we've received their signal connection
|
||||||
ParticipantResumed(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, nodeID livekit.NodeID, reason livekit.ReconnectReason)
|
ParticipantResumed(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, nodeID livekit.NodeID, reason livekit.ReconnectReason)
|
||||||
// ParticipantLeft - the participant leaves the room, only sent if ParticipantActive has been called before
|
// ParticipantLeft - the participant leaves the room, only sent if ParticipantActive has been called before
|
||||||
ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, shouldSendEvent bool)
|
ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, shouldSendEvent bool)
|
||||||
|
|||||||
Reference in New Issue
Block a user