mirror of
https://github.com/livekit/livekit.git
synced 2026-05-25 01:35:39 +00:00
Allow agents to override sender identities on ChatMessage (#3022)
* Allow agents to override sender identities on ChatMessage * temporarily replace protocol * check for empty identity * string compare instead of identity compare * update protocol * Fix typo * whitespace
This commit is contained in:
@@ -19,7 +19,7 @@ require (
|
||||
github.com/jxskiss/base62 v1.1.0
|
||||
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
|
||||
github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598
|
||||
github.com/livekit/protocol v1.21.1-0.20240919052504-1874ac067983
|
||||
github.com/livekit/protocol v1.22.0
|
||||
github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a
|
||||
github.com/mackerelio/go-osstat v0.2.5
|
||||
github.com/magefile/mage v1.15.0
|
||||
|
||||
@@ -171,6 +171,8 @@ github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598 h1:yLlk
|
||||
github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE=
|
||||
github.com/livekit/protocol v1.21.1-0.20240919052504-1874ac067983 h1:zIxjMDJlt4YXqRWkNZEp5y7gIMjACDve3m3bD4s4lug=
|
||||
github.com/livekit/protocol v1.21.1-0.20240919052504-1874ac067983/go.mod h1:AFuwk3+uIWFeO5ohKjx5w606Djl940+wktaZ441VoCI=
|
||||
github.com/livekit/protocol v1.22.0 h1:JPqRdnEDJs1pTx7Fp+hHR1e+Yq8nL260X+N43rNLpAo=
|
||||
github.com/livekit/protocol v1.22.0/go.mod h1:AFuwk3+uIWFeO5ohKjx5w606Djl940+wktaZ441VoCI=
|
||||
github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a h1:EQAHmcYEGlc6V517cQ3Iy0+jHgP6+tM/B4l2vGuLpQo=
|
||||
github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0=
|
||||
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
|
||||
|
||||
+12
-11
@@ -1641,14 +1641,9 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
|
||||
// trust the channel that it came in as the source of truth
|
||||
dp.Kind = kind
|
||||
|
||||
if p.Hidden() {
|
||||
dp.ParticipantIdentity = ""
|
||||
} else {
|
||||
dp.ParticipantIdentity = string(p.params.Identity)
|
||||
}
|
||||
|
||||
shouldForwardData := true
|
||||
shouldForwardMetrics := false
|
||||
overrideSenderIdentity := true
|
||||
isPublisher := true
|
||||
// only forward on user payloads
|
||||
switch payload := dp.Value.(type) {
|
||||
@@ -1661,11 +1656,6 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
|
||||
u.ParticipantSid = string(p.params.SID)
|
||||
u.ParticipantIdentity = string(p.params.Identity)
|
||||
}
|
||||
if dp.ParticipantIdentity != "" {
|
||||
u.ParticipantIdentity = dp.ParticipantIdentity
|
||||
} else {
|
||||
dp.ParticipantIdentity = u.ParticipantIdentity
|
||||
}
|
||||
if len(dp.DestinationIdentities) != 0 {
|
||||
u.DestinationIdentities = dp.DestinationIdentities
|
||||
} else {
|
||||
@@ -1677,6 +1667,10 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
|
||||
shouldForwardData = false
|
||||
}
|
||||
case *livekit.DataPacket_ChatMessage:
|
||||
if p.IsAgent() && dp.ParticipantIdentity != "" && string(p.params.Identity) != dp.ParticipantIdentity {
|
||||
overrideSenderIdentity = false
|
||||
payload.ChatMessage.Generated = true
|
||||
}
|
||||
shouldForwardData = true
|
||||
case *livekit.DataPacket_Metrics:
|
||||
shouldForwardData = false
|
||||
@@ -1693,6 +1687,13 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
|
||||
default:
|
||||
p.pubLogger.Warnw("received unsupported data packet", nil, "payload", payload)
|
||||
}
|
||||
|
||||
if p.Hidden() {
|
||||
dp.ParticipantIdentity = ""
|
||||
} else if overrideSenderIdentity {
|
||||
dp.ParticipantIdentity = string(p.params.Identity)
|
||||
}
|
||||
|
||||
if shouldForwardData {
|
||||
if onDataPacket := p.getOnDataPacket(); onDataPacket != nil {
|
||||
onDataPacket(p, kind, dp)
|
||||
|
||||
Reference in New Issue
Block a user