Handle stopping screensharing from native UI

This commit is contained in:
Fedor Indutny 2024-10-02 09:29:59 -07:00 committed by GitHub
parent 85cf445924
commit fc7eba772c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 8 deletions

View file

@ -104,7 +104,10 @@ import { addCallHistory, reloadCallHistory } from './callHistory';
import { saveDraftRecordingIfNeeded } from './composer';
import type { CallHistoryDetails } from '../../types/CallDisposition';
import type { StartCallData } from '../../components/ConfirmLeaveCallModal';
import { getCallLinksByRoomId } from '../selectors/calling';
import {
getCallLinksByRoomId,
getPresentingSource,
} from '../selectors/calling';
import { storageServiceUploadJob } from '../../services/storage';
import { CallLinkDeleteManager } from '../../jobs/CallLinkDeleteManager';
import { callLinkRefreshJobQueue } from '../../jobs/callLinkRefreshJobQueue';
@ -1332,15 +1335,9 @@ function getPresentingSources(): ThunkAction<
});
},
onMediaStream(mediaStream) {
let presentingSource: PresentedSource | undefined;
const { activeCallState } = getState().calling;
if (activeCallState?.state === 'Active') {
({ presentingSource } = activeCallState);
}
dispatch(
_setPresenting(
presentingSource || {
getPresentingSource(getState()) || {
id: 'media-stream',
name: '',
},
@ -1947,6 +1944,22 @@ function _setPresenting(
callLinkRootKey: rootKey,
});
if (mediaStream != null) {
// If the screen sharing stream is terminated early - stop screen sharing
mediaStream.getVideoTracks()[0]?.addEventListener(
'ended',
() => {
const currentSource = getPresentingSource(getState());
// Verify that the source didn't change while we were waiting.
if (currentSource === sourceToPresent) {
dispatch(cancelPresenting());
}
},
{ once: true }
);
}
dispatch({
type: SET_PRESENTING,
payload: sourceToPresent,

View file

@ -14,6 +14,7 @@ import type {
ActiveCallStateType,
} from '../ducks/calling';
import { getIncomingCall as getIncomingCallHelper } from '../ducks/callingHelpers';
import type { PresentedSource } from '../../types/Calling';
import { CallMode } from '../../types/CallDisposition';
import type { CallLinkType } from '../../types/CallLink';
import { getUserACI } from './user';
@ -166,3 +167,9 @@ export const areAnyCallsActiveOrRinging = createSelector(
getIncomingCall,
(activeCall, incomingCall): boolean => Boolean(activeCall || incomingCall)
);
export const getPresentingSource = createSelector(
getActiveCallState,
(activeCallState): PresentedSource | undefined =>
activeCallState?.presentingSource
);