Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: EventTarget
Source: JSObjects/CaptureController.cs
MDN Reference: CaptureController on MDN
The CaptureController interface provides methods that can be used to further manipulate a capture session separate from its initiation via MediaDevices.getDisplayMedia(). https://developer.mozilla.org/en-US/docs/Web/API/CaptureController
| Signature | Description |
|---|---|
CaptureController(SpawnJSObjectReference _ref) |
Deserialization constructor |
CaptureController() |
The CaptureController constructor creates a new CaptureController object instance. |
| Method | Return Type | Description |
|---|---|---|
SetFocusBehavior(EnumString<CaptureStartFocusBehavior> focusBehavior) |
void |
The CaptureController interface's setFocusBehavior() method controls whether the captured tab or window will be focused when an associated MediaDevices.getDisplayMedia() Promise fulfills, or whether the focus will remain with the tab containing the capturing app. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<CaptureController>(...)or constructornew CaptureController(...)
// Create a new CaptureController instance
const controller = new CaptureController();
// Prompt the user to share a tab, window, or screen.
const stream = await navigator.mediaDevices.getDisplayMedia({ controller });
// Query the displaySurface value of the captured video track
const [track] = stream.getVideoTracks();
const displaySurface = track.getSettings().displaySurface;
if (displaySurface === "browser") {
// Focus the captured tab.
controller.setFocusBehavior("focus-captured-surface");
} else if (displaySurface === "window") {
// Do not move focus to the captured window.
// Keep the capturing page focused.
controller.setFocusBehavior("no-focus-change");
}