-
Notifications
You must be signed in to change notification settings - Fork 230
Add RTCEngineSupersededBy event
#1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
size-limit report 📦
|
|
|
||
| if (this.localParticipant) { | ||
| this.localParticipant.setupEngine(this.engine); | ||
| } | ||
| if (this.e2eeManager) { | ||
| this.e2eeManager.setupEngine(this.engine); | ||
| } | ||
| oldEngine?.emit(EngineEvent.SupersededBy, this.engine); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, n function calls were required. Now, only one publish does the same thing!
|
|
||
| const EngineEventEmitter = EventEmitter as new () => TypedEventEmitter<EngineEventCallbacks>; | ||
|
|
||
| /** @internal */ | ||
| export default class RTCEngine extends (EventEmitter as new () => TypedEventEmitter<EngineEventCallbacks>) { | ||
| export default class RTCEngine extends EngineEventEmitter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly this is a little weird - EngineEventCallbacks now contains a reference to RTCEngine, so putting this expression directly within the extends creates a reference cycle that typescript doesn't seem to like. Breaking it up like this seems to solve that problem, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Problem / Concern
RTCEnginegets fully town down and recreated initially when an initial connection is created and also whenever a reconnection occurs. This means that any class that has a reference toenginemust be informed of this new change so that it can keep its reference toenginecurrent.The current means this is being done is by calling a
setupEnginemethod on all dependents - right now,LocalParticipantandE2EEManager, plus soonOutgoingDataStreamManager. This is relatively coupled though because the room needs to call that method on each of these classes!Potential solution
The existing approach works, but is inelegant. To attempt to solve this in a slightly more elegant way, I've added a new
SupersededByevent to theRTCEnginewhich is fired on the old engine whenever a new engine is generated, which allows anybody who has the engine to always have the latest copy.