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
*/
export interface IScreenSharingIndicatorOptions {
// id of the display that is being shared
displayId: string;
requestId: number;
streamId: string;
stream?: MediaStream;
}
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:
* - 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,
});
}
}