-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Exercise 3 - Dedicated worker for QR code scanning
- Loading branch information
1 parent
aa390a9
commit 91d255f
Showing
3 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import QrCode from 'qrcode-reader'; | ||
import { qrCodeStringToObject } from './utils/qrcode'; | ||
|
||
self.onmessage = evt => { | ||
let imageBuffer = evt.data; | ||
|
||
// Decode the QR code | ||
let qr = new QrCode(); | ||
qr.callback = function(error, rawResult) { | ||
if(error) { | ||
self.postMessage({ error }); | ||
return; | ||
} | ||
let result = qrCodeStringToObject(rawResult.result); | ||
self.postMessage({data: result}); | ||
} | ||
qr.decode(imageBuffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters