davidliu
Committed by GitHub

Support setting attributes from local participant (#470)

... ... @@ -718,6 +718,19 @@ internal constructor(
this.engine.client.sendUpdateLocalMetadata(metadata, name)
}
/**
* Set or update participant attributes. It will make updates only to keys that
* are present in [attributes], and will not override others.
*
* To delete a value, set the value to an empty string.
*
* Note: this requires `canUpdateOwnMetadata` permission.
* @param attributes attributes to update
*/
fun updateAttributes(attributes: Map<String, String>) {
this.engine.client.sendUpdateLocalMetadata(metadata, name, attributes)
}
internal fun onRemoteMuteChanged(trackSid: String, muted: Boolean) {
val pub = trackPublications[trackSid]
pub?.muted = muted
... ...
... ... @@ -62,6 +62,7 @@ object TestData {
.setHidden(true)
.setRecorder(false)
.build()
putAttributes("attribute", "value")
build()
}
... ... @@ -79,6 +80,7 @@ object TestData {
}
addTracks(REMOTE_AUDIO_TRACK)
addTracks(REMOTE_VIDEO_TRACK)
putAttributes("attribute", "value")
build()
}
... ... @@ -225,6 +227,7 @@ object TestData {
val participantMetadataChanged = LOCAL_PARTICIPANT.toBuilder()
.setMetadata("changed_metadata")
.setName("changed_name")
.putAttributes("attribute", "changed_value")
.build()
addParticipants(participantMetadataChanged)
... ...
... ... @@ -152,6 +152,23 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
}
@Test
fun updateAttributes() = runTest {
connect()
wsFactory.ws.clearRequests()
val newAttributes = mapOf("attribute" to "changedValue")
room.localParticipant.updateAttributes(newAttributes)
val requestString = wsFactory.ws.sentRequests.first().toPBByteString()
val sentRequest = LivekitRtc.SignalRequest.newBuilder()
.mergeFrom(requestString)
.build()
assertTrue(sentRequest.hasUpdateMetadata())
assertEquals(newAttributes, sentRequest.updateMetadata.attributesMap)
}
@Test
fun participantMetadataChanged() = runTest {
connect()
... ... @@ -183,6 +200,7 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
listOf(
ParticipantEvent.MetadataChanged::class.java,
ParticipantEvent.NameChanged::class.java,
ParticipantEvent.AttributesChanged::class.java,
),
participantEvents,
)
... ...