WICG / WICG/PEPC

Attribute-based Constraints For <usermedia>

Open
#88 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Bikeshed
Stars
72
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Summary

For <usermedia> implementations a concise, attribute-based syntax might be better suited for some use cases. The goal is to better surface user intent at the HTML layer, while preserving the existing script-based constraints as an escape hatch.


Motivation

PEPC optimizes for clear, declarative user intent. Requiring embedded JSON scripts for camera/microphone controls:

  • Obscures intent in otherwise semantic HTML
  • Reduces readability and diffability
  • Adds CSP and tooling friction

Most real-world use cases only need coarse, predictable constraints that map to attributes.

Also, the following may not be the most readable semantics.

<usermedia>
<script type="permissionconstraints">
  {
    "video": {
      "width": { "min": 640, "ideal": 1920, "max": 1920 },
      "height": { "min": 400, "ideal": 1080 },
      "aspectRatio": 1.777777778,
      "frameRate": { "max": 30 }
    }
  }
</script>
</usermedia>

Proposed syntax
Minimal usage
<usermedia audio></usermedia>
<usermedia video></usermedia>
<usermedia audio video></usermedia>

Equivalent to:

{ audio: true }
{ video: true }
{ audio: true, video: true }

Constraint refinement via prefixed attributes
<usermedia
  video
  video-width="1920"
  video-height="1080"
  video-framerate-max="30">
</usermedia>

Maps to:

{
  video: {
    width: { ideal: 1920 },
    height: { ideal: 1080 },
    frameRate: { max: 30 }
  }
}
<usermedia
  audio
  audio-channel-count="2"
  audio-sample-size="16">
</usermedia>

Rules:

  • audio / video attributes express requested capabilities
  • audio-* and video-* attributes refine constraints
  • Prefixed attributes without the base capability are invalid

Autostart (unchanged)
<usermedia audio video autostart></usermedia>

Escape hatch for advanced constraints

For less common or advanced cases, allow a single JSON attribute:

<usermedia constraints='{ "video": { "aspectRatio": 1.777 } }'></usermedia>

If present, constraints overrides all derived attributes.


Parsing model (high level)
  1. If constraints attribute is present, parse and use it

  2. Otherwise:

    • Initialize audio and/or video based on presence of attributes
  3. Apply audio-* and video-* refinements

  4. If neither audio nor video is present, the element is invalid


Why this fits PEPC
  • Attributes express intent, scripts express behavior
  • HTML-first, declarative, and inspectable
  • Better tooling, accessibility, and CSP characteristics

This is a layering improvement, not a replacement.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the proposed attribute syntax and the parsing model in this issue first. Compare the attribute-based form with the existing script-based constraints, then determine the remaining design decisions and how completion would be validated; no implementation files or tests are identified in the payload.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.