+
+
+
Camera scan
+
Optional on supported browsers. If the QR contains a full check-in URL, the token is extracted automatically.
+
+
+
+ @if (cameraState() === 'active') {
+
+ } @else {
+
+ }
+
+
+ @if (cameraState() === 'active') {
+
+
+
+
+ }
+
+ @if (cameraMessage()) {
+ {{ cameraMessage() }}
+ }
+
+
- @if (state() === 'preview_success' && previewData()) {
+ @if (previewData() && shouldShowPreview()) {
Admission preview
- Show
- {{ previewData()!.show_title }}
+ - Venue
- {{ previewData()!.venue_name }}
- Starts at
- {{ previewData()!.starts_at | date: 'EEEE d MMMM, HH:mm' }}
- Party size
- {{ previewData()!.party_size }}
- Reservation
- #{{ previewData()!.reservation_id }}
-
}
- @if (state() === 'confirm_success') {
- Check-in confirmed successfully.
+ @if (state() === 'confirm_success' && confirmData()) {
+
+ Check-in confirmed at {{ confirmData()!.checked_in_at | date: 'HH:mm' }}.
+
}
@if (state() === 'invalid_token') {
@@ -148,6 +215,48 @@ type UiState =
box-shadow: var(--azionelab-shadow);
}
+ .scanner-panel {
+ display: grid;
+ gap: 14px;
+ margin-bottom: 18px;
+ padding-bottom: 18px;
+ border-bottom: 1px solid var(--azionelab-border);
+ }
+
+ .scanner-copy h2 {
+ margin: 0 0 6px;
+ font-size: 1.15rem;
+ }
+
+ .scanner-copy p,
+ .camera-message {
+ margin: 0;
+ color: var(--azionelab-muted);
+ line-height: 1.5;
+ }
+
+ .camera-message {
+ font-size: 0.95rem;
+ }
+
+ .camera-frame {
+ overflow: hidden;
+ border-radius: 8px;
+ border: 1px solid var(--azionelab-border);
+ background: #151515;
+ }
+
+ .camera-frame video {
+ display: block;
+ width: 100%;
+ aspect-ratio: 4 / 3;
+ object-fit: cover;
+ }
+
+ .scanner-canvas {
+ display: none;
+ }
+
.full-width {
width: 100%;
}
@@ -159,7 +268,12 @@ type UiState =
flex-wrap: wrap;
}
- button[mat-flat-button] {
+ .scanner-actions {
+ justify-content: flex-start;
+ }
+
+ button[mat-flat-button],
+ button[mat-stroked-button] {
min-width: 150px;
display: inline-flex;
align-items: center;
@@ -213,6 +327,20 @@ export class CheckInPlaceholderPageComponent {
private readonly destroyRef = inject(DestroyRef);
private readonly formBuilder = inject(FormBuilder);
private readonly showsApi = inject(ShowsApiService);
+ private readonly barcodeDetectorCtor = (globalThis as { BarcodeDetector?: BarcodeDetectorConstructor }).BarcodeDetector;
+ private readonly scannerSupported =
+ !!this.barcodeDetectorCtor &&
+ typeof navigator !== 'undefined' &&
+ !!navigator.mediaDevices &&
+ typeof navigator.mediaDevices.getUserMedia === 'function';
+
+ private detector: BarcodeDetectorInstance | null = null;
+ private scannerStream: MediaStream | null = null;
+ private scanFrameId: number | null = null;
+ private scanInFlight = false;
+
+ @ViewChild('scannerVideo') private scannerVideo?: ElementRef;
+ @ViewChild('scannerCanvas') private scannerCanvas?: ElementRef;
protected readonly tokenForm = this.formBuilder.nonNullable.group({
token: ['', [Validators.required]],
@@ -220,6 +348,17 @@ export class CheckInPlaceholderPageComponent {
protected readonly state = signal('idle');
protected readonly previewData = signal(null);
+ protected readonly confirmData = signal(null);
+ protected readonly cameraState = signal(this.scannerSupported ? 'ready' : 'unsupported');
+ protected readonly cameraMessage = signal(
+ this.scannerSupported
+ ? 'Open the camera to scan a QR code, or keep using manual token entry.'
+ : 'Camera scanning is not available in this browser. Manual token entry still works.',
+ );
+
+ constructor() {
+ this.destroyRef.onDestroy(() => this.stopScanner());
+ }
protected preview(): void {
if (this.tokenForm.invalid) {
@@ -235,6 +374,7 @@ export class CheckInPlaceholderPageComponent {
this.state.set('preview_loading');
this.previewData.set(null);
+ this.confirmData.set(null);
this.showsApi.previewCheckIn(token)
.pipe(takeUntilDestroyed(this.destroyRef))
@@ -259,17 +399,174 @@ export class CheckInPlaceholderPageComponent {
this.showsApi.confirmCheckIn(token)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
- next: () => {
+ next: (response) => {
+ this.confirmData.set(response);
this.state.set('confirm_success');
},
error: (error: HttpErrorResponse) => this.setErrorState(error),
});
}
+ protected async startScanner(): Promise {
+ if (!this.scannerSupported || !this.barcodeDetectorCtor) {
+ this.cameraState.set('unsupported');
+ this.cameraMessage.set('Camera scanning is not available in this browser. Manual token entry still works.');
+ return;
+ }
+
+ this.stopScanner();
+ this.cameraState.set('starting');
+ this.cameraMessage.set('Starting camera...');
+
+ try {
+ this.scannerStream = await navigator.mediaDevices.getUserMedia({
+ video: { facingMode: { ideal: 'environment' } },
+ audio: false,
+ });
+
+ this.detector = new this.barcodeDetectorCtor({ formats: ['qr_code'] });
+ this.cameraState.set('active');
+ this.cameraMessage.set('Point the camera at the visitor QR code.');
+ this.scheduleScan();
+ } catch (error) {
+ this.stopScanner();
+
+ if (error instanceof DOMException && (error.name === 'NotAllowedError' || error.name === 'SecurityError')) {
+ this.cameraState.set('denied');
+ this.cameraMessage.set('Camera access was denied. You can continue with manual token entry.');
+ return;
+ }
+
+ this.cameraState.set('error');
+ this.cameraMessage.set('Could not start the camera. You can continue with manual token entry.');
+ }
+ }
+
+ protected stopScanner(): void {
+ if (this.scanFrameId !== null) {
+ cancelAnimationFrame(this.scanFrameId);
+ this.scanFrameId = null;
+ }
+
+ if (this.scannerStream) {
+ for (const track of this.scannerStream.getTracks()) {
+ track.stop();
+ }
+ this.scannerStream = null;
+ }
+
+ if (this.scannerVideo?.nativeElement) {
+ this.scannerVideo.nativeElement.pause();
+ this.scannerVideo.nativeElement.srcObject = null;
+ }
+
+ this.detector = null;
+ this.scanInFlight = false;
+
+ if (this.scannerSupported && this.cameraState() === 'active') {
+ this.cameraState.set('ready');
+ this.cameraMessage.set('Camera stopped. You can scan again or continue with manual token entry.');
+ }
+ }
+
protected isBusy(): boolean {
return this.state() === 'preview_loading' || this.state() === 'confirm_loading';
}
+ protected shouldShowPreview(): boolean {
+ return (
+ this.state() === 'preview_success'
+ || this.state() === 'confirm_loading'
+ || this.state() === 'confirm_success'
+ );
+ }
+
+ private scheduleScan(): void {
+ this.scanFrameId = requestAnimationFrame(() => {
+ void this.scanFrame();
+ });
+ }
+
+ private async scanFrame(): Promise {
+ if (this.cameraState() !== 'active' || !this.detector) {
+ return;
+ }
+
+ const video = this.scannerVideo?.nativeElement;
+ const canvas = this.scannerCanvas?.nativeElement;
+ if (!video || !canvas || this.scanInFlight) {
+ this.scheduleScan();
+ return;
+ }
+
+ if (!this.scannerStream && !video.srcObject) {
+ this.scheduleScan();
+ return;
+ }
+
+ if (video.srcObject !== this.scannerStream) {
+ video.srcObject = this.scannerStream;
+ await video.play();
+ }
+
+ if (video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || video.videoWidth === 0) {
+ this.scheduleScan();
+ return;
+ }
+
+ const context = canvas.getContext('2d');
+ if (!context) {
+ this.cameraState.set('error');
+ this.cameraMessage.set('Camera scan is not available right now. Please enter the token manually.');
+ this.stopScanner();
+ return;
+ }
+
+ canvas.width = video.videoWidth;
+ canvas.height = video.videoHeight;
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
+
+ this.scanInFlight = true;
+
+ try {
+ const barcodes = await this.detector.detect(canvas);
+ const rawValue = barcodes[0]?.rawValue ?? '';
+ const token = this.extractToken(rawValue);
+
+ if (token) {
+ this.tokenForm.controls.token.setValue(token);
+ this.tokenForm.controls.token.markAsTouched();
+ this.cameraMessage.set('QR captured. Validating token...');
+ this.stopScanner();
+ this.preview();
+ return;
+ }
+ } catch {
+ this.cameraState.set('error');
+ this.cameraMessage.set('Camera scan failed. Please enter the token manually.');
+ this.stopScanner();
+ return;
+ } finally {
+ this.scanInFlight = false;
+ }
+
+ this.scheduleScan();
+ }
+
+ private extractToken(rawValue: string): string {
+ const trimmedValue = rawValue.trim();
+ if (!trimmedValue) {
+ return '';
+ }
+
+ try {
+ const parsedUrl = new URL(trimmedValue);
+ return parsedUrl.searchParams.get('token')?.trim() ?? trimmedValue;
+ } catch {
+ return trimmedValue;
+ }
+ }
+
private setErrorState(error: HttpErrorResponse): void {
if (error.status === 401 || error.status === 403) {
this.state.set('unauthorized');
diff --git a/frontend/src/app/services/shows-api.service.ts b/frontend/src/app/services/shows-api.service.ts
index b34d08c..b369313 100644
--- a/frontend/src/app/services/shows-api.service.ts
+++ b/frontend/src/app/services/shows-api.service.ts
@@ -57,6 +57,7 @@ export type CheckInPreviewResponse = {
reservation_id: number;
performance_id: number;
show_title: string;
+ venue_name: string;
starts_at: string;
party_size: number;
};