--- title: "Camera events" description: "React when a setting changes on the camera or a new photo or clip lands on the card, with Camera.on and Camera.off." url: https://darkgrade.com/docs/slate/guides/events last_updated: 2026-12-04 docs_index: https://darkgrade.com/docs/llms.txt --- # Camera events > React when a setting changes on the camera or a new photo or clip lands on the card, with Camera.on and Camera.off. > ## Documentation Index > Fetch the complete documentation index at: https://darkgrade.com/docs/llms.txt > Use this file to discover all available pages before exploring further. Keep your UI in step with the camera without polling: Darkgrade Slate calls you when a setting changes, for example when someone turns a dial on the body, and when a new photo or clip lands on the card. ```typescript import { Camera } from '@darkgrade/slate' const camera = new Camera() await camera.connect() camera.on('settingsChanged', async () => { const { controls } = await camera.getCapabilities() console.log(controls.iso?.value, controls.shutterSpeed?.value) }) camera.on('mediaAdded', async () => { const [newest] = await camera.listMedia() // newest first console.log('New file', newest?.name) }) ``` ## The two events | Event | Fires when | | - | - | | `settingsChanged` | A setting changed on the camera. Then read [`getCapabilities()`](https://darkgrade.com/docs/functionality/connection.md#what-the-camera-can-do). | | `mediaAdded` | A new photo or clip is on the card. Then read [`listMedia()`](https://darkgrade.com/docs/functionality/media.md#list-photos-and-clips). | Handlers take no arguments. An event says that something changed, not what: read the camera for the new state. ## Subscribe and unsubscribe ```typescript const refresh = () => console.log('settings changed') camera.on('settingsChanged', refresh) camera.off('settingsChanged', refresh) // stop this handler camera.off('settingsChanged') // stop every handler of the event ``` You can call [`on`](https://darkgrade.com/docs/slate/getting_started/camera.md#on) before `connect()`: the handlers start when the camera connects. ## Save each photo to a folder as you shoot (for Lightroom Auto Import or Capture One) To see each photo in your editor moments after you take it, copy every new file off the card into a folder the editor watches: a watched folder, which Capture One calls a hot folder. `mediaAdded` says a file landed, [`listMedia()`](https://darkgrade.com/docs/slate/getting_started/camera.md#listmedia) names it and [`downloadMedia()`](https://darkgrade.com/docs/slate/getting_started/camera.md#downloadmedia) copies it: ```typescript import fs from 'node:fs' import path from 'node:path' import { Camera } from '@darkgrade/slate' const folder = '/Users/me/Pictures/Tethered' fs.mkdirSync(folder, { recursive: true }) const camera = new Camera() await camera.connect() // Files already on the card are not copied. const seen = new Set((await camera.listMedia()).map(item => item.id)) async function saveNew() { for (const item of await camera.listMedia()) { if (seen.has(item.id)) continue const bytes = await camera.downloadMedia(item.id) // Write under another name, then rename, so the // editor never opens half a file. const partial = path.join(folder, `.${item.name}.part`) fs.writeFileSync(partial, bytes) fs.renameSync(partial, path.join(folder, item.name)) seen.add(item.id) } } // One run at a time: a camera can send several events // for one photo. let work = Promise.resolve() camera.on('mediaAdded', () => { work = work.then(saveNew).catch(console.error) }) ``` The camera must be saving to its card: the event is about files on the card. Clips are copied too; skip them with `item.kind`. A file whose name is already in the folder is replaced. Then point the editor at the folder. In Lightroom Classic, [Auto Import](https://helpx.adobe.com/lightroom-classic/help/import-photos-automatically.html) takes it as its watched folder; Adobe says the folder must be empty when you choose it, and that Lightroom moves each photo out of it into a destination folder. In Capture One, [Hot Folder](https://support.captureone.com/hc/en-us/articles/360002562437-Attaching-an-unsupported-camera-Hot-Folder) monitors a folder for image files. ## Cases that bite - **`disconnect()` drops every handler.** Subscribe again after you reconnect. - **One change can fire several events.** The handler runs once for each event the camera sends, and a camera may send more than one for a single change. Debounce a handler that reads the camera or redraws a UI. - **Nothing catches a handler's errors.** A handler returns nothing, so a rejected promise from an `async` handler is unhandled. Wrap the body in `try`/`catch`. - **Nikon events are polled.** A Nikon queues its events until they are read. While at least one handler is subscribed, Slate reads the queue every 500 ms, so an event can arrive up to half a second late. > [!NOTE] > > From a shell, `darkgrade camera watch` streams the same two events: see [Watch for events](https://darkgrade.com/docs/cli/output.md#watch-for-events). ## The camera's own events `settingsChanged` and `mediaAdded` mean the same thing on every brand. Each camera also sends its own PTP events (capture complete, storage changes, vendor events), with parameters. To receive one, subscribe on the protocol session: see [Listen to raw events](https://darkgrade.com/docs/slate/guides/protocol.md#listen-to-raw-events). That entry is unsupported and its names can change between releases.