🚧 Glyx is pre-release software. APIs may change before v1.0. Get started →
Documentation
APIs & Bindings
camera

camera

Camera device access: enumerate devices, open a live stream, capture stills, and record MP4 video. The <Camera> component renders the live preview through the same GPU image path as <Image>.

Requires the camera capability:

glyx.config.json
{ "capabilities": { "camera": true } }

Quick start

import { Camera, camera } from '@glyx-dev/react'
import { useRef } from 'react'
 
function CameraScreen() {
  const camRef = useRef(null)
 
  return (
    <>
      <Camera ref={camRef} mirror style={{ width: 640, height: 480, borderRadius: 8 }} />
      <Pressable onPress={async () => {
        const path = await camera.capture(camRef.current.handle)
        console.log('saved to', path)
      }}>
        <Text>Take photo</Text>
      </Pressable>
    </>
  )
}

<Camera> props

PropTypeDescription
mirrorbooleanFlip the preview horizontally (selfie view)
styleViewStyleLayout/style — size the preview like any View
refRefExposes the underlying camera handle

API

camera.listDevices()

Returns Promise<{ index: number, name: string }[]> — connected camera devices.

camera.open(deviceIndex?)

Opens the camera at deviceIndex (default 0). Returns Promise<number> — a handle used by the other calls. The capture thread starts immediately.

camera.capture(handle)

Captures the current frame as a JPEG. Returns Promise<string> — the absolute path of the saved .jpg file.

camera.startRecord(handle, outputPath) / camera.stopRecord(handle)

Records the stream to an MP4 at outputPath.

⚠️

Recording encodes via ffmpeg, which must be installed and in PATH (or set FFMPEG_PATH). Preview and still capture work without ffmpeg.

⚠️

Recording only works in a build that statically links the camera Cargo feature (the default for glyx-core). If your app instead loads the camera capability dynamically — via glyx caps build / the capability-DLL path — startRecord silently does nothing and stopRecord rejects with "record_stop failed (not supported via DLL — use --features camera)". Preview, listDevices, open, and capture work either way; only recording is static-build-only.

camera.close(handle)

Stops the capture thread and releases the device.

See also

  • video — video file/URL playback
  • webview — another native child-surface component (OS webview, not the GPU image path)
  • fs — reading the captured files