Switch to the new session API for screen-sharing (#25802)

This commit is contained in:
Šimon Brandner 2023-07-14 22:05:23 +02:00 committed by GitHub
parent a84349f969
commit 93e6ee11ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View file

@ -32,7 +32,8 @@ type ElectronChannel =
| "setBadgeCount" | "setBadgeCount"
| "update-downloaded" | "update-downloaded"
| "userDownloadCompleted" | "userDownloadCompleted"
| "userDownloadAction"; | "userDownloadAction"
| "openDesktopCapturerSourcePicker";
declare global { declare global {
interface Window { interface Window {

View file

@ -43,6 +43,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore"; import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore";
import { UPDATE_EVENT } from "matrix-react-sdk/src/stores/AsyncStore"; import { UPDATE_EVENT } from "matrix-react-sdk/src/stores/AsyncStore";
import { avatarUrlForRoom, getInitialLetter } from "matrix-react-sdk/src/Avatar"; import { avatarUrlForRoom, getInitialLetter } from "matrix-react-sdk/src/Avatar";
import DesktopCapturerSourcePicker from "matrix-react-sdk/src/components/views/elements/DesktopCapturerSourcePicker";
import VectorBasePlatform from "./VectorBasePlatform"; import VectorBasePlatform from "./VectorBasePlatform";
import { SeshatIndexManager } from "./SeshatIndexManager"; import { SeshatIndexManager } from "./SeshatIndexManager";
@ -163,6 +164,14 @@ export default class ElectronPlatform extends VectorBasePlatform {
}); });
}); });
window.electron.on("openDesktopCapturerSourcePicker", () => {
const { finished } = Modal.createDialog(DesktopCapturerSourcePicker);
finished.then(([source]) => {
if (!source) return;
this.ipc.call("callDisplayMediaCallback", source);
});
});
this.ipc.call("startSSOFlow", this.ssoID); this.ipc.call("startSSOFlow", this.ssoID);
BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate); BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate);

View file

@ -21,6 +21,9 @@ import { Action } from "matrix-react-sdk/src/dispatcher/actions";
import dispatcher from "matrix-react-sdk/src/dispatcher/dispatcher"; import dispatcher from "matrix-react-sdk/src/dispatcher/dispatcher";
import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake"; import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake";
import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore"; import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore";
import Modal from "matrix-react-sdk/src/Modal";
import DesktopCapturerSourcePicker from "matrix-react-sdk/src/components/views/elements/DesktopCapturerSourcePicker";
import { mocked } from "jest-mock";
import ElectronPlatform from "../../../../src/vector/platform/ElectronPlatform"; import ElectronPlatform from "../../../../src/vector/platform/ElectronPlatform";
@ -76,6 +79,35 @@ describe("ElectronPlatform", () => {
expect(dispatchFireSpy).toHaveBeenCalledWith(Action.ViewUserSettings); expect(dispatchFireSpy).toHaveBeenCalledWith(Action.ViewUserSettings);
}); });
it("creates a modal on openDesktopCapturerSourcePicker", async () => {
const plat = new ElectronPlatform();
Modal.createDialog = jest.fn();
// @ts-ignore mock
mocked(Modal.createDialog).mockReturnValue({
finished: new Promise((r) => r(["source"])),
});
let res: () => void;
const waitForIPCSend = new Promise<void>((r) => {
res = r;
});
// @ts-ignore mock
jest.spyOn(plat.ipc, "call").mockImplementation(() => {
res();
});
const [event, handler] = getElectronEventHandlerCall("openDesktopCapturerSourcePicker")!;
handler();
await waitForIPCSend;
expect(event).toBeTruthy();
expect(Modal.createDialog).toHaveBeenCalledWith(DesktopCapturerSourcePicker);
// @ts-ignore mock
expect(plat.ipc.call).toHaveBeenCalledWith("callDisplayMediaCallback", "source");
});
describe("updates", () => { describe("updates", () => {
it("dispatches on check updates action", () => { it("dispatches on check updates action", () => {
new ElectronPlatform(); new ElectronPlatform();