Skip to content

Commit 18d88c3

Browse files
authored
🤖 Merge PR DefinitelyTyped#73413 [chrome] update desktopCapture namespace by @erwanjugand
1 parent 378d63d commit 18d88c3

2 files changed

Lines changed: 55 additions & 12 deletions

File tree

‎types/chrome/index.d.ts‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,31 +2617,39 @@ declare namespace chrome {
26172617
* Permissions: "desktopCapture"
26182618
*/
26192619
export namespace desktopCapture {
2620-
/** Contains properties that describe the stream. */
2620+
/** Enum used to define set of desktop media sources used in {@link chooseDesktopMedia}. */
2621+
export enum DesktopCaptureSourceType {
2622+
SCREEN = "screen",
2623+
WINDOW = "window",
2624+
TAB = "tab",
2625+
AUDIO = "audio",
2626+
}
2627+
2628+
/**
2629+
* Contains properties that describe the stream.
2630+
* @since Chrome 57
2631+
*/
26212632
export interface StreamOptions {
26222633
/** True if "audio" is included in parameter sources, and the end user does not uncheck the "Share audio" checkbox. Otherwise false, and in this case, one should not ask for audio stream through getUserMedia call. */
26232634
canRequestAudioTrack: boolean;
26242635
}
26252636
/**
26262637
* Shows desktop media picker UI with the specified set of sources.
2627-
* @param sources Set of sources that should be shown to the user.
2628-
* Parameter streamId: An opaque string that can be passed to getUserMedia() API to generate media stream that corresponds to the source selected by the user. If user didn't select any source (i.e. canceled the prompt) then the callback is called with an empty streamId. The created streamId can be used only once and expires after a few seconds when it is not used.
2638+
* @param sources Set of sources that should be shown to the user. The sources order in the set decides the tab order in the picker.
2639+
* @param targetTab Optional tab for which the stream is created. If not specified then the resulting stream can be used only by the calling extension. The stream can only be used by frames in the given tab whose security origin matches `tab.url`. The tab's origin must be a secure origin, e.g. HTTPS.
2640+
* @param callback streamId: An opaque string that can be passed to `getUserMedia()` API to generate media stream that corresponds to the source selected by the user. If user didn't select any source (i.e. canceled the prompt) then the callback is called with an empty `streamId`. The created `streamId` can be used only once and expires after a few seconds when it is not used.
2641+
* @return An id that can be passed to cancelChooseDesktopMedia() in case the prompt need to be canceled.
26292642
*/
26302643
export function chooseDesktopMedia(
2631-
sources: string[],
2644+
sources: `${DesktopCaptureSourceType}`[],
26322645
callback: (streamId: string, options: StreamOptions) => void,
26332646
): number;
2634-
/**
2635-
* Shows desktop media picker UI with the specified set of sources.
2636-
* @param sources Set of sources that should be shown to the user.
2637-
* @param targetTab Optional tab for which the stream is created. If not specified then the resulting stream can be used only by the calling extension. The stream can only be used by frames in the given tab whose security origin matches tab.url.
2638-
* Parameter streamId: An opaque string that can be passed to getUserMedia() API to generate media stream that corresponds to the source selected by the user. If user didn't select any source (i.e. canceled the prompt) then the callback is called with an empty streamId. The created streamId can be used only once and expires after a few seconds when it is not used.
2639-
*/
26402647
export function chooseDesktopMedia(
2641-
sources: string[],
2642-
targetTab: chrome.tabs.Tab,
2648+
sources: `${DesktopCaptureSourceType}`[],
2649+
targetTab: tabs.Tab | undefined,
26432650
callback: (streamId: string, options: StreamOptions) => void,
26442651
): number;
2652+
26452653
/**
26462654
* Hides desktop media picker dialog shown by chooseDesktopMedia().
26472655
* @param desktopMediaRequestId Id returned by chooseDesktopMedia()

‎types/chrome/test/index.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6513,3 +6513,38 @@ function testReadingList() {
65136513
function testDom() {
65146514
chrome.dom.openOrClosedShadowRoot(document.body); // $ExpectType ShadowRoot | null
65156515
}
6516+
6517+
// https://developer.chrome.com/docs/extensions/reference/api/desktopCapture
6518+
function testDesktopCapture() {
6519+
chrome.desktopCapture.DesktopCaptureSourceType.AUDIO === "audio";
6520+
chrome.desktopCapture.DesktopCaptureSourceType.SCREEN === "screen";
6521+
chrome.desktopCapture.DesktopCaptureSourceType.TAB === "tab";
6522+
chrome.desktopCapture.DesktopCaptureSourceType.WINDOW === "window";
6523+
6524+
chrome.desktopCapture.cancelChooseDesktopMedia(0); // $ExpectType void
6525+
6526+
const sources: `${chrome.desktopCapture.DesktopCaptureSourceType}`[] = [
6527+
"screen",
6528+
chrome.desktopCapture.DesktopCaptureSourceType.WINDOW,
6529+
];
6530+
6531+
const tab: chrome.tabs.Tab = {
6532+
index: 0,
6533+
pinned: false,
6534+
highlighted: false,
6535+
windowId: 0,
6536+
active: false,
6537+
frozen: false,
6538+
incognito: false,
6539+
selected: false,
6540+
discarded: false,
6541+
autoDiscardable: false,
6542+
groupId: 0,
6543+
};
6544+
6545+
chrome.desktopCapture.chooseDesktopMedia(sources, () => {}); // $ExpectType number
6546+
chrome.desktopCapture.chooseDesktopMedia(sources, tab, (streamId, options) => {
6547+
streamId; // $ExpectType string
6548+
options; // $ExpectType StreamOptions
6549+
});
6550+
}

0 commit comments

Comments
 (0)