feat: add desktopCapturer.getMediaSourceIdForWebContents() to get stream source id from web contents (#22701)

* feat: add desktopCapturer.getMediaSourceIdForWebContents() to get stream source id from web contents

* Cleanup from #22701 PR comments
This commit is contained in:
Jeremy Judeaux 2020-05-27 04:34:24 +08:00 committed by GitHub
parent dc72f74020
commit 204f001c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 178 additions and 2 deletions

View file

@ -138,6 +138,29 @@ ifdescribe(features.isDesktopCapturerEnabled() && !process.arch.includes('arm')
expect(mediaSourceId).to.equal(foundSource!.id);
});
describe('getMediaSourceIdForWebContents', () => {
const getMediaSourceIdForWebContents: typeof desktopCapturer.getMediaSourceIdForWebContents = (webContentsId: number) => {
return w.webContents.executeJavaScript(`
require('electron').desktopCapturer.getMediaSourceIdForWebContents(${JSON.stringify(webContentsId)}).then(r => JSON.parse(JSON.stringify(r)))
`);
};
it('should return a stream id for web contents', async () => {
const result = await getMediaSourceIdForWebContents(w.webContents.id);
expect(result).to.be.a('string').that.is.not.empty();
});
it('throws an error for invalid options', async () => {
const promise = getMediaSourceIdForWebContents('not-an-id' as unknown as number);
await expect(promise).to.be.eventually.rejectedWith(Error, 'TypeError: Error processing argument');
});
it('throws an error for invalid web contents id', async () => {
const promise = getMediaSourceIdForWebContents(-200);
await expect(promise).to.be.eventually.rejectedWith(Error, 'Failed to find WebContents');
});
});
// TODO(deepak1556): currently fails on all ci, enable it after upgrade.
it.skip('moveAbove should move the window at the requested place', async () => {
// DesktopCapturer.getSources() is guaranteed to return in the correct