| name | extension-qr-code |
| description | QR code scanner using the camera. |
| version | 0.1.4 |
| compatibility | {"npm":{"@caffeineai/qr-code":"~0.1.1","@caffeineai/camera":"~0.1.1"}} |
| caffeineai-subscription | ["none"] |
QR Code Scanner
QR code scanner extension for Caffeine AI.
Overview
This skill adds QR code scanning using the device camera. Built on top of the camera component with jsQR for decoding.
Frontend
For QR code scanner support:
There is a prefabricated React hook imported from @caffeinelabs/qr-code that cannot be modified.
import { RefObject } from 'react';
import { CameraConfig, CameraError } from '@caffeineai/camera';
export interface QRResult {
data: string;
timestamp: number;
}
export interface QRScannerConfig extends CameraConfig {
scanInterval?: number;
maxResults?: number;
jsQRUrl?: string;
}
export interface UseQRScannerReturn {
qrResults: QRResult[];
isScanning: boolean;
jsQRLoaded: boolean;
isActive: boolean;
isSupported: boolean | null;
error: CameraError | null;
isLoading: boolean;
currentFacingMode: 'user' | 'environment';
startScanning: () => Promise<boolean>;
stopScanning: () => Promise<void>;
switchCamera: () => Promise<boolean>;
clearResults: () => void;
reset: () => void;
retry: () => Promise<boolean>;
videoRef: RefObject<HTMLVideoElement>;
canvasRef: RefObject<HTMLCanvasElement>;
isReady: boolean;
canStartScanning: boolean;
}
export declare function useQRScanner(config?: QRScannerConfig): UseQRScannerReturn;
Usage example:
import { useQRScanner } from '@caffeineai/qr-code';
function QRScannerComponent() {
const {
qrResults,
isScanning,
isActive,
isSupported,
error,
isLoading,
canStartScanning,
startScanning,
stopScanning,
switchCamera,
clearResults,
videoRef,
canvasRef
} = useQRScanner({
facingMode: 'environment',
scanInterval: 100,
maxResults: 5
});
if (isSupported === false) {
return <div>Camera not supported</div>;
}
return (
<div>
<video
ref={videoRef}
style={{ width: '100%', height: 'auto' }}
playsInline
muted
/>
<canvas ref={canvasRef} style={{ display: 'none' }} />
{error && <div>Error: {error.message}</div>}
Start Scanning
Stop Scanning
{/* Only show switch camera on mobile */}
{/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && (
Switch Camera
)}
Results {qrResults.length > 0 && Clear}
{qrResults.map(result => (
{new Date(result.timestamp).toLocaleTimeString()}
{result.data}
))}
);
}
Properly display QR scanner error messages in the app.