client-sdk-js icon indicating copy to clipboard operation
client-sdk-js copied to clipboard

Add participant track subscribe method

Open lukasIO opened this issue 2 years ago • 3 comments

A follow up on #423 This is mainly an idea on how to approach the fact that currently we rely on TrackPublications to be present in order to perform selective subscriptions and simplify this for users. With a method on the remote participant we could automatically subscribe to certain tracks once their publications arrive.

room.on(RoomEvent.ParticipantConnected, (participant) => {
  // users wouldn't have to wait for the publications to arrive to signal their desire to subscribe to certain tracks
  // method takes in optional sources, if none are provided it will subscribe/unsubscribe from all sources
  participant.subscribeToTracks();
}

The method in this PR uses Track.Source to do that, which probably doesn't cover all cases, but seems like the most convenient way for most users.

lukasIO avatar Sep 09 '22 11:09 lukasIO

🦋 Changeset detected

Latest commit: b103c7e0359ec92cebdd11159771f5c532e721f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Sep 09 '22 11:09 changeset-bot[bot]

This is a great line of thinking to manage some of these state annoyances within the SDK.. Just thinking about this for a bit.. would we go all the way and handle the participant connection state as well here?

i.e.

room.setSubscribed('identity', [Track.Source.Camera, Track.Source.Microphone])

and to unsubscribe

room.setSubscribed('identity', [])

davidzhao avatar Sep 12 '22 06:09 davidzhao

Interesting thought! I think it's a great way to further simplify state handling, but actually only in case identity is already known ahead of participant connections (I'm not sure how often this is the case).

I guess with a room level method we would want to create a dummy participant object already on the room if a call to setSubscribed on the room happens before a participant actually joins? That would allow us to merge them once the Participant actually connects and would avoid handling that state both on the room and on the participant level.

lukasIO avatar Sep 12 '22 09:09 lukasIO