Skip to content
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

Fix uncaught error when canceling screen sharing after joining a meeting #15466

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions react/features/base/tracks/actions.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,14 @@ async function _toggleScreenSharing(
try {
tracks = await createLocalTracksF(options) as any[];
} catch (error) {
dispatch(handleScreenSharingError(error, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
if (error.name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check?

Copy link
Author

@rahulrana701 rahulrana701 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check?

this check was soly introduced to check the error related to user-cancelled errors.
Perhaps this could be improved with error.name ="gum.screensharing_user_canceled". I hope this would make more sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as we are getting the error we are returning. I think it does the job well , what do u think about that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check the logic on the calling side. As in, the caller of this function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check the logic on the calling side. As in, the caller of this function.
After going through the codebase , I find that ShareScreenWarningDialog component is responsible for handling the logic when the user chooses to stop sharing a screen or audio. The toggleScreensharing action is dispatched when the user submits the dialog. However , The dialog differentiates between audio-only and normal screen sharing modes using the _isAudioScreenShareWarning prop . If _isAudioScreenShareWarning is true, it handles the stop of audio screen sharing. Otherwise, it handles normal screen sharing.
If toggleScreensharing encounters an error due to user cancellation, it might not properly handle it, leading to unhandled promise rejections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! Then I reckon we need to fix it there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saghul I think the best practice is to handle this error in the toggleScreenSharing function itself rather than in the component because , The toggleScreenSharing function is responsible for managing the entire logic related to starting, stopping, and handling the state of screen sharing, including audio-only sharing and by handling the error inside this function, we centralize the error management for screen sharing. This means that any error or cancellation related to screen sharing is processed in a single location rather than in various places across the component hierarchy

console.log(error.message);
return;
}

dispatch(handleScreenSharingError(error, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
throw error;
rahulrana701 marked this conversation as resolved.
Show resolved Hide resolved

throw error;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { Component } from 'react';
import { WithTranslation } from 'react-i18next';
import { connect } from 'react-redux';

import { IStore } from '../../../app/types';
import { translate } from '../../../base/i18n/functions';
import { toggleScreensharing } from '../../../base/tracks/actions';
import Dialog from '../../../base/ui/components/web/Dialog';
import { handleScreenSharingError } from '../../../base/tracks/actions.web';


export interface IProps extends WithTranslation {

Expand Down Expand Up @@ -42,12 +43,13 @@ class ShareScreenWarningDialog extends Component<IProps> {
* @returns {boolean}
*/
_onStopSharing() {
// Depending on the context from which this dialog is opened we'll either be toggling off an audio only
// share session or a normal screen sharing one, this is indicated by the _isAudioScreenShareWarning prop.
this.props.dispatch(toggleScreensharing(undefined,
!this.props._isAudioScreenShareWarning));
this.props.dispatch(
toggleScreensharing(undefined, !this.props._isAudioScreenShareWarning)
);


return true;

return true; // Ensure the dialog closes as expected.
}

/**
Expand Down