日本語

The microphone and the camera

App::allow names the devices, such as the microphone, that the pages may use through getUserMedia.

Allowing a device

impl<U> App<U> {
    pub const fn allow(self, device: Device) -> Self;
}

pub enum Device {
    Microphone,
    Camera,
    Screen,
}

A page asks for the microphone or the camera with navigator.mediaDevices.getUserMedia, as a voice or video call does. The web view grants a page only the devices App::allow names, without asking the person, and refuses the others with NotAllowedError. The application decides in Rust which devices its pages get, and no page can ask for more:

use hypersig_desktop::{App, Device};

// A voice and video call's pages get the microphone and the camera.
const APP: App = App::new("dev.example.call")
    .allow(Device::Microphone)
    .allow(Device::Camera);

The system still asks the person once whether the application may use the device. The page of examples/meter loads a custom element that shows how loud the microphone hears the room, and CI checks on Windows and Linux that it is granted the microphone and refused the camera.

On each system

  • On macOS, WKWebView offers no navigator.mediaDevices unless the bundle's Info.plist has NSMicrophoneUsageDescription for the microphone and NSCameraUsageDescription for the camera, each a sentence the system shows when it asks the person. A run outside a bundle, such as cargo run, has neither. examples/meter adds the key from its Info.plist with cargo-packager's macos.info-plist-path, as Packaging shows.
  • On macOS, a page in a bundle with these keys was seen to get navigator.mediaDevices. No page has yet been seen to get the microphone itself, because the system's question could not be answered where this was tried. CI's macOS runner has no device, so it does not run the meter.
  • On Windows, WebView2 keeps a grant in the web view's data, so a later version that no longer names the device is still granted it until that data is removed.
  • Device::Screen answers getDisplayMedia, as sharing the screen in a call does. Only WebKitGTK, on Linux, asks the application about it, and it shares the screen only from a click of the person's, not from a script's click(). CI checks there that a click on the meter's button shares the mock screen. WebView2, on Windows, answers getDisplayMedia on its own, whether or not the application names the screen; called from a script, it neither shared nor refused within 10 seconds. WKWebView, on macOS, answers it on its own too: a click shows the system's picker of what to share, and closing the picker refuses with NotAllowedError. Like the microphone, it needs NSMicrophoneUsageDescription or NSCameraUsageDescription in the bundle, since without either WKWebView offers no navigator.mediaDevices.
  • On Linux, WebKitGTK turns its media streams on only for an application that allows a device.
  • Hardened runtime entitlements for a signed macOS package are not set yet; issue #226 covers signing.