This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
Clean up on Pixel Streaming session disconnect #141
Merged
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.
Summary
The Pixel Streaming library should clean up after it has finished a session. This helps integrating the lib within a single-page-app like a React app, where you might have the user navigate from a Pixel Streaming view to other views without a page refresh.
The current code leaves e.g. dangling event handlers connected to
videoParent
anddocument
element, which it should clean up when not required any more. One of the symptoms of these dangling event handlers is a lot of console logging after disconnected whenever mouse or keyboard events are emitted:This PR performs the following clean up tasks when the library has closed the session:
clearTimeout
, notclearInterval
to clear AFK timeout since it's not an intervalclearInterval
accidentally clears also timeouts if called with a timeout id because of underlying implementation details, but this is not something guaranteed for all browsers)exitPointerLock()
call to pointer lock mouse handler teardownpixelStreaming.disconnect()
more robust by addingundefined
checksdisconnect()
was called before connection was established. Got hit by this when implementing a test React app if navigating quickly out of the Pixel Streaming view before the connection was fully upTest Plan
AFK timetout
Unregister event handlers on disconnecting
Opened a Pixel Streaming session in
uiless.html
Listed the event handlers connected to
videoParentElement
anddocument
, and saw a bunch of event handlersUsed the API to auto-disconnect after 10 seconds
After disconnected listed the event handlers again and verified that all had been cleared
Moved mouse around and pressed keyboard keys. Verified that there were no more console messages printed by the event handlers
Retested the above by disconnecting from UE side, not through API. Verified that the event handlers were cleared also on UE side disconnect
Used
player.html
to verify that disconnecting & reconnecting multiple times re-established the event handlers every time the connection was established. Verified that user input worked as expected after multiple reconnectionsPointer lock