MCPcopy
hub / github.com/livekit/livekit / getOrCreateWorker

Method getOrCreateWorker

pkg/telemetry/telemetryservice.go:273–314  ·  view source on GitHub ↗
(
	ctx context.Context,
	roomID livekit.RoomID,
	roomName livekit.RoomName,
	participantID livekit.ParticipantID,
	participantIdentity livekit.ParticipantIdentity,
	guard *ReferenceGuard,
)

Source from the content-addressed store, hash-verified

271}
272
273func (t *telemetryService) getOrCreateWorker(
274 ctx context.Context,
275 roomID livekit.RoomID,
276 roomName livekit.RoomName,
277 participantID livekit.ParticipantID,
278 participantIdentity livekit.ParticipantIdentity,
279 guard *ReferenceGuard,
280) (*StatsWorker, bool) {
281 t.workersMu.Lock()
282 defer t.workersMu.Unlock()
283
284 key := statsWorkerKey{roomID, participantID}
285 worker, ok := t.workers[key]
286 if ok && !worker.Closed(guard) {
287 return worker, true
288 }
289
290 existingIsConnected := false
291 if ok {
292 existingIsConnected = worker.IsConnected()
293 }
294
295 worker = newStatsWorker(
296 ctx,
297 t,
298 roomID,
299 roomName,
300 participantID,
301 participantIdentity,
302 guard,
303 )
304 if existingIsConnected {
305 worker.SetConnected()
306 }
307
308 t.workers[key] = worker
309
310 worker.next = t.workerList
311 t.workerList = worker
312
313 return worker, false
314}
315
316func (t *telemetryService) LocalRoomState(ctx context.Context, info *livekit.AnalyticsNodeRooms) {
317 t.enqueue(func() {

Callers 3

ParticipantJoinedMethod · 0.95
ParticipantActiveMethod · 0.95
ParticipantResumedMethod · 0.95

Calls 4

newStatsWorkerFunction · 0.85
IsConnectedMethod · 0.80
ClosedMethod · 0.45
SetConnectedMethod · 0.45

Tested by

no test coverage detected