You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following the discussion at #1355 (comment) i went ahead and tried to replace TrackType (imported from the transitive dependency @livekit/protocol which following this comment should be discouraged / not necessary) with Track.Kind or Track.Source and came to realize that this is not viable for us.
Explanation
Our backend implements a service – which maps type-safe as a GraphQL-mutation to the frontend – like this:
exportconstmuteParticipant=async({input: { roomName, identity, type }})=>{try{constparticipant=awaitroomServiceClient.getParticipant(urlName,identity)// select tracks to mute by `TrackType.AUDIO` or `TrackType.VIDEO` ↓consttracks=participant.tracks.filter((track)=>track.type===type)for(consttrackoftracks){awaitroomServiceClient.mutePublishedTrack(urlName,identity,track.sid,true))}catch(e){...}}
Evaluating the possible alternatives to TrackType here:
AFAIK the only alternative to track.type here is track.source – but that is not what we want here, as – compared to TrackType the TrackSource type is less deterministic (i.e. it has TrackSource.UNKNOWN which we wouldn't known how to handle here) and also the source of the track is not relevant to this mutation at all. ⚠️ Also – Track.Source in livekit-client does not map to TrackSource from livekit-server-sdk/protocol at all … it's actually a pitfall, b/c the former is an enum mapping to string values, while the latter is an enum mapping to integers.
We could use Track.sourceToProto(s: Source) here, but that is an internal method and also seems more complex than necessary.
TrackKind doesn't seem exposed at this point at all – but even if it was, it bears the same caveat regarding type mismatch than above – Track.Kind from livekit-client is a string-enum, while TrackKind from livekit-server-sdk is integer-based. Again, it also has Track.Kind.Unknown (TrackKind.UNKNOWN) respectively, which we don't exactly know what to make out of it.
Again, Track.kindToProto(k: Kind) could be used in livekit-client, but i don't believe that's an option that the designers of the SDK would want to encourage.
last option would be to split the service into dedicated muteParticipantAudio({roomName, identity}) and muteParticipantVideo({roomName, identity}) services. While this seems a clear straightforward solution it effectively duplicates everything on top of the service layer: the generated type code, the gql query code, the mutation callbacks, which is why the current solution is preferable.
another option (that is the worst practice imaginable) is to duplicate the type on the front-end – which is actually what we did in LiveKit v1 and were happy to find that LiveKit v2 now has a common base in @livekit/protocol
Summing up, it looks like simply exporting TrackType from livekit-client seems the most straightforward and easiest measure to ensure seamless interop between livekit-client and livekit-server-sdk.
Of course, happy to learn if there's an option i have overlooked here.
However i would understand if the livekit core team would refrain from exposing more types from @livekit/protocol to reduce confusion for the time being.
I'm wondering though: what is the concrete reason that livekit-client duplicates all these types from the protocol package (TrackType vs. Track.Type, TrackSource vs. Track.Source, TrackKind vs. Track.Kind and StreamState vs. Track.StreamState).
IMHO it would be preferable to only rely on the types from @livekit/protocol – would make the package smaller, reduce potential confusion and most importantly promote seamless interop with other SDKs. Maybe something worth considering as a breaking change for livekit SDKs v3?
Describe the bug
Following the discussion at #1355 (comment) i went ahead and tried to replace
TrackType
(imported from the transitive dependency@livekit/protocol
which following this comment should be discouraged / not necessary) withTrack.Kind
orTrack.Source
and came to realize that this is not viable for us.Explanation
Our backend implements a service – which maps type-safe as a GraphQL-mutation to the frontend – like this:
Evaluating the possible alternatives to
TrackType
here:track.type
here istrack.source
– but that is not what we want here, as – compared toTrackType
theTrackSource
type is less deterministic (i.e. it hasTrackSource.UNKNOWN
which we wouldn't known how to handle here) and also the source of the track is not relevant to this mutation at all.Track.Source
in livekit-client does not map toTrackSource
from livekit-server-sdk/protocol at all … it's actually a pitfall, b/c the former is an enum mapping to string values, while the latter is an enum mapping to integers.We could use
Track.sourceToProto(s: Source)
here, but that is an internal method and also seems more complex than necessary.TrackKind
doesn't seem exposed at this point at all – but even if it was, it bears the same caveat regarding type mismatch than above –Track.Kind
from livekit-client is a string-enum, whileTrackKind
from livekit-server-sdk is integer-based. Again, it also hasTrack.Kind.Unknown
(TrackKind.UNKNOWN
) respectively, which we don't exactly know what to make out of it.Again,
Track.kindToProto(k: Kind)
could be used in livekit-client, but i don't believe that's an option that the designers of the SDK would want to encourage.muteParticipantAudio({roomName, identity})
andmuteParticipantVideo({roomName, identity})
services. While this seems a clear straightforward solution it effectively duplicates everything on top of the service layer: the generated type code, the gql query code, the mutation callbacks, which is why the current solution is preferable.@livekit/protocol
Summing up, it looks like simply exporting
TrackType
from livekit-client seems the most straightforward and easiest measure to ensure seamless interop between livekit-client and livekit-server-sdk.Of course, happy to learn if there's an option i have overlooked here.
Reproduction
_
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: