Skip to content

Releases: sumitsahoo/detect-primary-camera

v1.0.1

04 Mar 11:15

Choose a tag to compare

🎉 Detect Primary Camera v1.0.1 — Initial Release

A zero-dependency library to robustly detect the primary rear camera on mobile devices using the WebRTC enumerateDevices API.

Features

  1. Smart Camera Scoring — Ranks all available video devices using a scoring algorithm that considers label keywords, device index, and capabilities to find the best rear camera.
  2. Modern Device Support — Explicitly penalizes ultra-wide, telephoto, and macro lenses that are poor choices for barcode scanning, exam proctoring, and general use.
  3. Cross-Platform — Handles iOS ("Back Camera") and Android ("camera 0") naming quirks seamlessly.
  4. Framework Agnostic — Works in Vanilla JS/TS with a dedicated usePrimaryCamera React hook available via detect-primary-camera/react.
  5. LocalStorage CachinggetAndSetBestRearCamera() persists the discovered device ID, speeding up subsequent loads.
  6. SSR Safe — Gracefully handles server-side rendering environments.