Lifecycle and duplicate prevention
Start, stop, pause and resume are explicit and cheap. Pausing keeps the camera open, so
resuming is instant; stopping releases the track and turns the camera indicator off. This
scanner has AutoStart="false" and ShowControls="false", so nothing happens
until the page's own buttons call the methods.
Start calls StartAsync, Stop StopAsync, Pause
and Resume the methods of the same name, and Forget reported values
ResetDuplicateFilter. Every call is safe at any time: Pause and
Resume do nothing in a status they do not apply to, and a start made while an earlier
one still waits for the permission prompt supersedes it, so only one camera is ever opened.
Duplicate suppression
A camera decodes the same symbol in frame after frame, so DuplicateSuppressionWindow
(two seconds by default) holds a value back after it was reported. Suppression is keyed on the
value and the symbology together, so moving the camera to a different barcode reports
immediately instead of waiting out the window. Holding the same one in view keeps it
suppressed rather than re-firing on a timer.
Set it to zero and the scanner reports every frame that decodes, which is the right setting for measuring throughput.
For a stocktake or a check-in desk: each value is reported once for as long as the camera stays open, up to 4 096 values. Start and Forget reported values begin a new session; Resume, switching cameras and a camera reopened after the page was hidden do not, so nothing is counted twice. With a finite window, Resume reports the symbol in view again.
What a scan does
Background and feedback
Switch to another tab and back: the camera indicator goes out, the status reads Starting while the page is hidden, and the scanner picks up where it left off - paused, if it was paused. It saves the battery, at the cost of a moment's restart. Either way, a camera the phone ends when the page goes into the background is reopened when it returns rather than reported as lost.
Feedback is best effort: browsers only play the tone after the user has
interacted with the page, and Safari does not vibrate. The outline and the screen reader
announcement always come too, so neither is the only sign of a scan.
Scan counters
Status
Status is always one of these. OnStatusChanged reports every change, the badge
above the scanner shows it, and the root element carries it as data-status for styling.
| Status | Camera | Decoding | Reached by |
|---|---|---|---|
| Idle | Closed | No | Creating the scanner; it stays here when AutoStart is off. |
| Starting | Opening | No | StartAsync, while the browser asks for permission and opens the track; also while a camera ended in the background waits for the page to be shown. |
| Scanning | Open | Yes | The camera opened, or Resume. |
| Paused | Open | No | Pause, or a scan under AfterScan="BbAfterScan.Pause". |
| Stopped | Released | No | StopAsync, or a scan under AfterScan="BbAfterScan.Stop". |
| Faulted | Released | No | A failure, reported through OnError; StartAsync tries again. See errors. |
In code
A check-in desk that reads one ticket at a time and ignores every other code:
<BbScanner @ref="_scanner" AfterScan="BbAfterScan.Pause" AcceptResult="@(r => r.Text.StartsWith("TICKET-", StringComparison.Ordinal))" DuplicateSuppressionWindow="Timeout.InfiniteTimeSpan" Feedback="BbScanFeedback.Beep" OnScan="CheckIn" /> <button @onclick="() => _scanner.Resume()">Scan another</button> @code { private BbScanner _scanner = default!; private Task CheckIn(BbBarcodeResult ticket) => Tickets.CheckInAsync(ticket.Text); }
Disposal
The component implements IAsyncDisposable. Navigating away cancels the
frame loop, stops every media track, releases the JavaScript session and returns
the pooled buffers. Nothing keeps the camera alive after the component is gone.