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:
parent
dc72f74020
commit
204f001c5d
9 changed files with 178 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue