[feature] Allow changing arbitrary options during room lifetime (disconnectOnPageLeave
implemented)
#1358
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.
This is a proposal (or an RFC if you want) implementing a Proxy on the
Room.options
property. This enables to switch options on or off that otherwise can only be configured once on instantiation. Potential applications could be to haveadaptiveStream
ordynacast
switches in the example applications, but basically any option can be made configurable at runtime with it.As a proof-of-concept and first application, this PR implements updating
disconnectOnPageLeave
after the Room has been created, because that was my XY-Problem that led to this: I wanted to hook up abeforeunload
handler so a user confirmation is shown should they navigate away during a LiveKit session that is being recorded. The problem i discovered was that the room was being disconnected anyway after the user chose to stay on the page in the confirm dialog. Digging into the library i realized i had to initialize the Room withdisconnectOnPageLeave: false
– however i felt i don't want to lose this very sensible default behavior. So i implemented this Proxy, which enables to simplyroom.options.disconnectOnPageLeave = false
when recording starts and my custombeforeunload
handler is registered, and vice versa doroom.options.disconnectOnPageLeave = true
when recording stops.