Proposal: Allow multiple (and conditional) stream readers per topic #1427
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For built-in text/byte streams that we'd like to use in agents we are having trouble keeping things simple while also adding flexibility to layer nice abstractions on top on the client side. The tension mostly comes down to the client-side constraint that you can have only one handler per topic. This means that if we want to add an abstraction that uses the
lk.transcription
topic, it needs to be all or nothing. and leads to confusion in SDKs where the abstraction is available and the topic should not be used manually or else things will go wrong, and others where the abstraction is unavailable and the topic must be used manually.I propose that we make it possible to register multiple handlers per topic. Not because people should commonly do this, but because it allows flexibility without running into hard error conditions.
In order to make this work reliably, if you register a handler you must consume the stream you are given. This is of course tricky so we will also allow a filter method: you can use this to decide based on the header packet whether or not you will handle the stream.
In this way its easy to add a handler that is for
lk.transcription
but only for participant X or track Y. And we can further extend this by adding convenience e.g.participant.registerTranscriptionHandler(...)
that applies the correct topic and filters for you. and we could abstract further by having default handling of transcription streams for each participant that are then broadcast a different way.This spike adds basic support and modifies the demo to prove that it works, although I'll probably back out the demo changes before merging (if we merge).
As an alternative we could also keep the filter methods but require that not more than one handler pass the filter per incoming stream. if more than one topic+filter applies to a stream, we'd give it only to the first one (order undefined?) and log an error. But I think that's not preferable.
Feedback very welcome.