From dee181592fa4ce662b495d98ca80c0e6d1576d52 Mon Sep 17 00:00:00 2001 From: Axel Eriksson <60875212+axeleriksson147@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:49:46 +0100 Subject: [PATCH] Cleanup showScreenSharingIndicator method (#2062) --- src/common/api-interface.ts | 4 +++- src/renderer/ssf-api.ts | 23 +++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index 4ab7b57b..ebd117b5 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -313,10 +313,12 @@ export enum NotificationActions { * Screen sharing Indicator */ export interface IScreenSharingIndicatorOptions { + // id of the display that is being shared displayId: string; + requestId: number; + streamId: string; - stream?: MediaStream; } export interface IVersionInfo { diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index ee4c6ab0..a75de2e8 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -512,12 +512,9 @@ export class SSFApi { } /** - * Shows a banner that informs user that the screen is being shared. + * Shows a banner that informs the user that the screen is being shared. * - * @param options object with following fields: - * - stream https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/MediaStream object. - * The indicator automatically destroys itself when stream becomes inactive (see MediaStream.active). - * - displayId id of the display that is being shared or that contains the shared app + * @param options * @param callback callback function that will be called to handle events. * Callback receives event object { type: string }. Types: * - 'error' - error occured. Event object contains 'reason' field. @@ -527,31 +524,25 @@ export class SSFApi { options: IScreenSharingIndicatorOptions, callback, ): void { - const { displayId, stream } = options; + const { displayId, streamId } = options; - if (!stream || !stream.active || stream.getVideoTracks().length !== 1) { - callback({ type: 'error', reason: 'bad stream' }); + if (streamId && typeof streamId !== 'string') { + callback({ type: 'error', reason: 'bad streamId' }); return; } + if (displayId && typeof displayId !== 'string') { callback({ type: 'error', reason: 'bad displayId' }); return; } - const destroy = () => { - throttledCloseScreenShareIndicator(stream.id); - stream.removeEventListener('inactive', destroy); - }; - - stream.addEventListener('inactive', destroy); - if (typeof callback === 'function') { local.screenSharingIndicatorCallback = callback; ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.openScreenSharingIndicator, displayId, id: ++nextIndicatorId, - streamId: stream.id, + streamId, }); } }