Skip to content

Commit

Permalink
fix(service-providers): share screen buffer may be null (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Nov 28, 2022
1 parent 76315db commit 1885870
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ export class AgoraRTCElectronShareScreen extends IServiceShareScreen {
this.client.getScreenWindowsInfo(res),
);

const convertScreenInfo = (info: DisplayInfo | WindowInfo): IServiceShareScreenInfo => {
const convertScreenInfo = (
info: DisplayInfo | WindowInfo,
): IServiceShareScreenInfo | null => {
// There's a bug in agora SDK, the image may be missing on mirrored screen
if (!info.image) {
return null;
}
if ("displayId" in info) {
return {
type: "display",
Expand All @@ -143,7 +149,10 @@ export class AgoraRTCElectronShareScreen extends IServiceShareScreen {
}
};

return [...displayList.map(convertScreenInfo), ...windowList.map(convertScreenInfo)];
return compact([
...displayList.map(convertScreenInfo),
...windowList.map(convertScreenInfo),
]);
}

public override setScreenInfo(info: IServiceShareScreenInfo | null): void {
Expand Down Expand Up @@ -232,3 +241,9 @@ export class AgoraRTCElectronShareScreen extends IServiceShareScreen {
this._pTogglingShareScreen = undefined;
}
}

type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T;

function compact<T>(arr: T[]): Array<Truthy<T>> {
return arr.filter(Boolean) as Array<Truthy<T>>;
}

0 comments on commit 1885870

Please sign in to comment.