async function main({ onActivate, onError, onReading, onDenied }) {
const result = await navigator.permissions.query({
name: 'ambient-light-sensor',
})
if (result.state === 'denied') {
onDenied()
return
}
const ambientLightSensor = new AmbientLightSensor({ frequency: 20 })
ambientLightSensor.addEventListener('activate', onActivate)
ambientLightSensor.addEventListener('error', onError)
ambientLightSensor.addEventListener('reading', () => {
const ISO = 100
const C = 250
const EV = Math.round(Math.log2((ambientLightSensor.illuminance * ISO) / C))
onReading(EV)
})
ambientLightSensor.start()
}
- AmbientLightSensor - Web APIs | MDN
- Ambient Light Sensor
- Sensors for the web - Chrome Developers1
- Ambient Light Sensor | Can I use… Support tables for HTML5, CSS3, etc
Footnotes
-
주변광 센서 인터페이스가 포함된 일반 센서 API를 사용하는 방법을 설명 ↩