Skip to content

Commit

Permalink
fix: instantiate tab video tracks from BrowserCaptureMediaStreamTrack (
Browse files Browse the repository at this point in the history
…electron#39074)

return BrowserCaptureMediaStreamTrack instead of MediaStreamTrack
  • Loading branch information
brhenrique committed Aug 23, 2023
1 parent e1d6379 commit 2481f94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions shell/browser/electron_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void ElectronBrowserContext::DisplayMediaDeviceChosen(
blink::MediaStreamDevice video_device(request.video_type, id, name);
video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
nullptr, url::Origin::Create(request.security_origin),
content::DesktopMediaID::Parse(request.requested_video_device_id));
content::DesktopMediaID::Parse(video_device.id));
devices.video_device = video_device;
} else if (result_dict.Get("video", &rfh)) {
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
Expand All @@ -592,7 +592,7 @@ void ElectronBrowserContext::DisplayMediaDeviceChosen(
base::UTF16ToUTF8(web_contents->GetTitle()));
video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
web_contents, url::Origin::Create(request.security_origin),
content::DesktopMediaID::Parse(request.requested_video_device_id));
content::DesktopMediaID::Parse(video_device.id));
devices.video_device = video_device;
} else {
gin_helper::ErrorThrower(args->isolate())
Expand Down
23 changes: 23 additions & 0 deletions spec/api-media-handler-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,29 @@ describe('setDisplayMediaRequestHandler', () => {
expect(ok).to.be.true(message);
});

it('returns a MediaStream with BrowserCaptureMediaStreamTrack when the current tab is selected', async () => {
const ses = session.fromPartition('' + Math.random());
let requestHandlerCalled = false;
ses.setDisplayMediaRequestHandler((request, callback) => {
requestHandlerCalled = true;
callback({ video: w.webContents.mainFrame });
});
const w = new BrowserWindow({ show: false, webPreferences: { session: ses } });
await w.loadURL(serverUrl);
const { ok, message } = await w.webContents.executeJavaScript(`
navigator.mediaDevices.getDisplayMedia({
preferCurrentTab: true,
video: true,
audio: false,
}).then(stream => {
const [videoTrack] = stream.getVideoTracks();
return { ok: videoTrack instanceof BrowserCaptureMediaStreamTrack, message: null };
}, e => ({ok: false, message: e.message}))
`, true);
expect(requestHandlerCalled).to.be.true();
expect(ok).to.be.true(message);
});

ifit(!(process.platform === 'darwin' && process.arch === 'x64'))('can supply a screen response to preferCurrentTab', async () => {
const ses = session.fromPartition('' + Math.random());
let requestHandlerCalled = false;
Expand Down

0 comments on commit 2481f94

Please sign in to comment.