davidliu
Committed by GitHub

set permission by identity (#91)

* update protocol repo

* Permission by identity
@@ -650,22 +650,34 @@ data class AudioTrackPublishOptions( @@ -650,22 +650,34 @@ data class AudioTrackPublishOptions(
650 650
651 data class ParticipantTrackPermission( 651 data class ParticipantTrackPermission(
652 /** 652 /**
  653 + * The participant identity this permission applies to.
  654 + * You can either provide this or `participantSid`
  655 + */
  656 + val participantIdentity: String? = null,
  657 + /**
653 * The participant id this permission applies to. 658 * The participant id this permission applies to.
654 */ 659 */
655 - val participantSid: String, 660 + val participantSid: String? = null,
656 /** 661 /**
657 * If set to true, the target participant can subscribe to all tracks from the local participant. 662 * If set to true, the target participant can subscribe to all tracks from the local participant.
658 * 663 *
659 * Takes precedence over [allowedTrackSids]. 664 * Takes precedence over [allowedTrackSids].
660 */ 665 */
661 - val allTracksAllowed: Boolean, 666 + val allTracksAllowed: Boolean = false,
662 /** 667 /**
663 * The list of track ids that the target participant can subscribe to. 668 * The list of track ids that the target participant can subscribe to.
664 */ 669 */
665 val allowedTrackSids: List<String> = emptyList() 670 val allowedTrackSids: List<String> = emptyList()
666 ) { 671 ) {
  672 + init {
  673 + if (participantIdentity == null && participantSid == null) {
  674 + throw IllegalArgumentException("Either identity or sid must be provided.")
  675 + }
  676 + }
  677 +
667 fun toProto(): LivekitRtc.TrackPermission { 678 fun toProto(): LivekitRtc.TrackPermission {
668 return LivekitRtc.TrackPermission.newBuilder() 679 return LivekitRtc.TrackPermission.newBuilder()
  680 + .setParticipantIdentity(participantIdentity)
669 .setParticipantSid(participantSid) 681 .setParticipantSid(participantSid)
670 .setAllTracks(allTracksAllowed) 682 .setAllTracks(allTracksAllowed)
671 .addAllTrackSids(allowedTrackSids) 683 .addAllTrackSids(allowedTrackSids)
  1 +package io.livekit.android.room.participant
  2 +
  3 +import org.junit.Test
  4 +
  5 +class ParticipantTrackPermissionTest {
  6 + @Test(expected = IllegalArgumentException::class)
  7 + fun requireSidOrIdentity() {
  8 + ParticipantTrackPermission(
  9 + participantIdentity = null,
  10 + participantSid = null
  11 + )
  12 + }
  13 +
  14 + @Test
  15 + fun sidConstructionDoesntThrow() {
  16 + ParticipantTrackPermission(
  17 + participantSid = "sid"
  18 + )
  19 + }
  20 +
  21 + @Test
  22 + fun identyConstructionDoesntThrow() {
  23 + ParticipantTrackPermission(
  24 + participantIdentity = "identity"
  25 + )
  26 + }
  27 +}
1 -Subproject commit e3f22408016f5ef825b6a03e4d36a5f977a05745 1 +Subproject commit 51a8116f88b2c88ee1492c6a4d512b4611400918