Skip to content

Commit 06e81e0

Browse files
committed
Replace published on behalf agents
1 parent 2729917 commit 06e81e0

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

Sources/LiveKit/Agent/Participant+Agent.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import Foundation
1818

19-
let publishOnBehalfAttributeKey = "lk.publish_on_behalf"
20-
2119
public extension Participant {
2220
@objc
2321
var isAgent: Bool {
@@ -27,13 +25,6 @@ public extension Participant {
2725
}
2826
}
2927

30-
/// Avatar workers publish audio and video on behalf of the agent.
31-
/// They should not be used for other purposes or displayed to the user.
32-
@objc
33-
var isAvatarWorker: Bool {
34-
attributes.keys.contains(publishOnBehalfAttributeKey)
35-
}
36-
3728
@objc
3829
var agentState: AgentState {
3930
guard isAgent else { return .unknown }

Sources/LiveKit/Agent/Room+Agent.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,18 @@
1616

1717
import Foundation
1818

19+
let publishOnBehalfAttributeKey = "lk.publish_on_behalf"
20+
1921
public extension Room {
20-
/// All agent participants in the Room, excluding avatar workers
22+
/// All agent participants in the Room
2123
var agentParticipants: [Participant.Identity: RemoteParticipant] {
22-
remoteParticipants.filter { $0.value.isAgent && !$0.value.isAvatarWorker }
24+
// Filter out agents that are replaced by another agent e.g. avatar worker
25+
let onBehalf = Set(remoteParticipants.map(\.value.attributes[publishOnBehalfAttributeKey]).compactMap { $0 })
26+
return remoteParticipants.filter { $0.value.isAgent && !onBehalf.contains($0.key.stringValue) }
2327
}
2428

25-
/// The first agent participant in the Room, excluding avatar workers
26-
var agentParticipant: RemoteParticipant? {
29+
/// The first agent participant in the Room
30+
var agentParticipant: Participant? {
2731
agentParticipants.values.first
2832
}
29-
30-
/// All avatar workers in the Room
31-
var avatarWorkers: [Participant.Identity: RemoteParticipant] {
32-
remoteParticipants.filter { $0.value.isAgent && $0.value.isAvatarWorker }
33-
}
34-
35-
/// The first avatar worker in the Room
36-
var avatarWorker: RemoteParticipant? {
37-
avatarWorkers.values.first
38-
}
3933
}

0 commit comments

Comments
 (0)