Cleanup showScreenSharingIndicator method (#2062)

This commit is contained in:
Axel Eriksson 2024-01-05 12:49:46 +01:00 committed by GitHub
parent ff182adfa1
commit dee181592f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 17 deletions

View File

@ -313,10 +313,12 @@ export enum NotificationActions {
* Screen sharing Indicator * Screen sharing Indicator
*/ */
export interface IScreenSharingIndicatorOptions { export interface IScreenSharingIndicatorOptions {
// id of the display that is being shared
displayId: string; displayId: string;
requestId: number; requestId: number;
streamId: string; streamId: string;
stream?: MediaStream;
} }
export interface IVersionInfo { export interface IVersionInfo {

View File

@ -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: * @param options
* - 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 callback callback function that will be called to handle events. * @param callback callback function that will be called to handle events.
* Callback receives event object { type: string }. Types: * Callback receives event object { type: string }. Types:
* - 'error' - error occured. Event object contains 'reason' field. * - 'error' - error occured. Event object contains 'reason' field.
@ -527,31 +524,25 @@ export class SSFApi {
options: IScreenSharingIndicatorOptions, options: IScreenSharingIndicatorOptions,
callback, callback,
): void { ): void {
const { displayId, stream } = options; const { displayId, streamId } = options;
if (!stream || !stream.active || stream.getVideoTracks().length !== 1) { if (streamId && typeof streamId !== 'string') {
callback({ type: 'error', reason: 'bad stream' }); callback({ type: 'error', reason: 'bad streamId' });
return; return;
} }
if (displayId && typeof displayId !== 'string') { if (displayId && typeof displayId !== 'string') {
callback({ type: 'error', reason: 'bad displayId' }); callback({ type: 'error', reason: 'bad displayId' });
return; return;
} }
const destroy = () => {
throttledCloseScreenShareIndicator(stream.id);
stream.removeEventListener('inactive', destroy);
};
stream.addEventListener('inactive', destroy);
if (typeof callback === 'function') { if (typeof callback === 'function') {
local.screenSharingIndicatorCallback = callback; local.screenSharingIndicatorCallback = callback;
ipcRenderer.send(apiName.symphonyApi, { ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openScreenSharingIndicator, cmd: apiCmds.openScreenSharingIndicator,
displayId, displayId,
id: ++nextIndicatorId, id: ++nextIndicatorId,
streamId: stream.id, streamId,
}); });
} }
} }