Implementing Session Reset and Stream Disconnection
If you're looking to enable a session reset functionality in your custom client, our latest SDK release (version 4.10.2) introduces this capability. Below is a step-by-step guide on how to implement session reset that will allow for efficient session management and improved user experience when handling multiple streams.
Step 1: SDK Version Requirement
Ensure you are using SDK version 4.10.2 or higher. You can test this functionality in the latest web template client or in your own custom client by following Steps 2-4 below. Please refer to the instructions here to update your existing web client to the latest SDK.
Step 2: Implement the onClose Function
In your App.tsx
file, add an onClose
function to handle the session reset. This function closes the current session, resets hooks, and manages the loading state.
onClose={async () => {
if (launchRequest) {
await launchRequest.close(platform);
// Reset the hooks
resetLaunchRequest();
resetStreamer();
// Reset loading state
setLoading(false);
}
}}
Pass this onClose
function to your streaming view, where it will be invoked when the session needs to end.
Step 3: Add a Close Button to EmbeddedView
In the EmbeddedView
component, add a close button to trigger the onClose
function. Place it in the top right corner and hide it conditionally based on session state or device compatibility.
<Button
onClick={props.onClose}
style={{ position: 'absolute', top: 10, right: 10 }}
className={isIPhone || handle.active || props.StreamerStatus !== StreamerStatus.Connected ? 'hidden' : ''}>
<Icon name="window close outline" />
</Button>
This button will be available only when appropriate, based on "StreamerStatus."
Step 4: Reset to Launch View on Session Completion
In the App.tsx
, monitor the stream status, and reset to initial launch view when the session ends StreamerStatus.Completed
.
if (streamerStatus === StreamerStatus.Completed) {
return <LaunchView Launch={launch} />;
}
Important Notes
- Note that launching a new session will not work on the sessions that require fixed
environmentId
or on collaboration sessions. - Every time a session is reset the launch request will work on the new unique
environmentId
.