diff --git a/src/lib/element_qr_scanner backup.svelte b/src/lib/element_qr_scanner backup.svelte new file mode 100644 index 00000000..25f8e88d --- /dev/null +++ b/src/lib/element_qr_scanner backup.svelte @@ -0,0 +1,543 @@ + + + +
+ + + + + + +
+
+ {#if scanning_status == 'not_started' } + + + Scanning stopped + + {:else if scanning_status == 'paused' && show_pause_btn} + + Scanning paused + {:else if scanning_status == 'scanning'} + + {#if show_pause_btn} + + {/if} + + + + + Scanning for QR code... + + + {/if} +
+ +
+
+ + {#if show_qr_manual_text_entry_option} +
+ {#if show_qr_manual_entry} + + + + + +
+ +
+ + {:else} + + {/if} +
+ {/if} + + {#if show_qr_manual_badge_id_entry_option} +
+ {#if show_qr_manual_entry} +
handle_qr_manual_entry} class="flex"> + + + + + + + +
+ {:else} + + {/if} +
+ {/if} + + {#if show_qr_scan_result && qr_scan_result} +
+ Raw Result: + {qr_scan_result} +
+ {/if} + + +
+ + + diff --git a/src/lib/element_qr_scanner.svelte b/src/lib/element_qr_scanner.svelte index 25f8e88d..b2bce7d1 100644 --- a/src/lib/element_qr_scanner.svelte +++ b/src/lib/element_qr_scanner.svelte @@ -5,8 +5,6 @@ import { createEventDispatcher, onDestroy, onMount } from 'svelte'; import {Html5Qrcode, Html5QrcodeScannerState, Html5QrcodeSupportedFormats} from 'html5-qrcode'; // *** Import Aether core variables and functions -import { api } from '$lib/api'; -import { ae_api } from '$lib/ae_stores'; // *** Import Aether core components // import Element_input from './element_input.svelte'; @@ -37,9 +35,6 @@ let qr_entered_badge_id: null|string = null; let show_qr_manual_entry: null|boolean = null; let disable_submit_badge_id_btn: boolean = true; -let user_media_status = 'not_requested'; - - // let max_results: number = 50; const dispatch = createEventDispatcher(); @@ -58,52 +53,36 @@ let qr_scan_cfg = { fps: qr_fps, qrbox: qr_viewfinder_width }; // 275 seems good onMount(() => { console.log('** Element Mounted: ** QR Scanner'); - // NOTE: We only want to trigger the scanning to start after the page has fully loaded. + // NOTE: This can only be done after the page has fully loaded. At least that is what my tests have shown so far. -2022-12-02 + if (start_qr_scanner) { + handle_start_qr_scanning(); + } + navigator.mediaDevices.getUserMedia({video: true}) .then(successCallback, errorCallback); - - // NOTE: This can only be done after the page has fully loaded. - // if (start_qr_scanner) { - // handle_start_qr_scanning(); - // } }); -onDestroy(async () => { +onDestroy(() => { console.log('** Element Destroyed: ** QR Scanner'); qr_scan_result = null; qr_found_text = null; - await handle_stop_qr_scanning(); + handle_stop_qr_scanning(); }); var successCallback = function(error: any) { console.log('Camera access allowed'); - user_media_status = 'allowed'; - - // let subject = 'Camera Access Allowed'; - // let message = error; - // send_init_confirm_email(subject, message); dispatch('qr_camera', { status: 'allowed', }); - - // NOTE: This can only be done after the page has fully loaded. - if (start_qr_scanner) { - handle_start_qr_scanning(); - } }; var errorCallback = function(error: any) { if (error.name == 'NotAllowedError') { console.log('Camera access not allowed!'); - user_media_status = 'denied'; - - // let subject = 'Camera Access Denied'; - // let message = error; - // send_init_confirm_email(subject, message); dispatch('qr_camera', { status: 'denied', @@ -121,24 +100,16 @@ var errorCallback = function(error: any) { // } -async function handle_start_qr_scanning() { +function handle_start_qr_scanning() { console.log('*** handle_start_qr_scanning() ***'); - if (user_media_status == 'denied') { - console.log('Camera access not allowed!'); - return; - } else if (user_media_status == 'not_requested') { - console.log('Camera access not requested yet!'); - return; - } - qr_scan_result = null; qr_found_text = null; if (html5_qr_code) { console.log('html5_qr_code object found. Clearing and creating new Html5Qrcode...'); // html5_qr_code.clear(); - // document.getElementById('qr_scanner_viewfinder').classList.remove('d_none'); + document.getElementById('qr_scanner_viewfinder').classList.remove('d_none'); html5_qr_code = new Html5Qrcode( 'qr_scanner_viewfinder', { formatsToSupport: [ Html5QrcodeSupportedFormats.QR_CODE ] } @@ -150,37 +121,21 @@ async function handle_start_qr_scanning() { ); } - if (html5_qr_code.getState() == Html5QrcodeScannerState.NOT_STARTED) { - // console.log('Scanner is not started'); + // if (html5_qr_code.getState() == Html5QrcodeScannerState.NOT_STARTED) { + // // console.log('Scanner is not started'); + // } else { + // console.log('Scanner is already started'); + // return; + // } - return await html5_qr_code.start({ facingMode: qr_facing_mode }, qr_scan_cfg, handle_qr_scan_success, handle_qr_scan_error) - .then((ignore: any) => { - console.log('Scanning has started'); - scanning_status = 'scanning'; - - // let subject = 'QR Scanning Started'; - // let message = ignore; - // send_init_confirm_email(subject, message); - - return true; - }).catch((err) => { - console.log('There was an error while trying to start the QR scanner'); - scanning_status = 'start_error'; - - let subject = 'QR Scanning Start Error'; - let message = err; - send_init_confirm_email(subject, message); - - return false; - }); - - - } else { - console.log('Scanner is already started'); - return; - } - - + html5_qr_code.start({ facingMode: qr_facing_mode }, qr_scan_cfg, handle_qr_scan_success, handle_qr_scan_error).then((ignore: any) => { + console.log('Scanning has started'); + scanning_status = 'scanning'; + return true; + }).catch((err) => { + console.log('There was an error while trying to start the QR scanner'); + return false; + }); } @@ -206,46 +161,28 @@ function handle_resume_qr_scanning() { } -async function handle_stop_qr_scanning() { - start_qr_scanner = false; - - if (!html5_qr_code) { - console.log('html5_qr_code object found. Nothing to stop?'); - return false; - } - - let state = html5_qr_code.getState(); - console.log('html5_qr_code state:', state); - - if (state == Html5QrcodeScannerState.NOT_STARTED) { +function handle_stop_qr_scanning() { + if (html5_qr_code && html5_qr_code.getState() == Html5QrcodeScannerState.NOT_STARTED) { console.log('Scanner is not started'); return; } - if (state == Html5QrcodeScannerState.PAUSED || state == Html5QrcodeScannerState.SCANNING) { - console.log('Scanner is not started'); - await html5_qr_code.stop() - scanning_status = 'not_started'; - return; - } - - await html5_qr_code.clear(); - return true; + // qr_scan_result = null; + // qr_found_text = null; // html5_qr_code.pause(); - // return html5_qr_code.stop() - // .then((ignore) => { - // console.log('Scanning has stopped'); - // // document.getElementById('qr_scanner_viewfinder').classList.add('d_none'); - // scanning_status = 'not_started'; - // }).then((ignore) => { - // // html5_qr_code = null; - // // html5_qr_code.clear(); - // }).catch((err) => { - // console.log('There was an error while trying to stop the scanning'); - // return false; - // }); + html5_qr_code.stop().then((ignore) => { + console.log('Scanning has stopped'); + document.getElementById('qr_scanner_viewfinder').classList.add('d_none'); + scanning_status = 'not_started'; + }).then((ignore) => { + // html5_qr_code = null; + html5_qr_code.clear(); + }).catch((err) => { + console.log('There was an error while trying to stop the scanning'); + return false; + }); // html5_qr_code = null; } @@ -267,7 +204,29 @@ function handle_qr_scan_success(decoded_text, decoded_result) { }); // handle_pause_qr_scanning(); + handle_stop_qr_scanning(); + + // html5_qr_code.stop().then((ignore) => { + // console.log('Scanning has stopped'); + // scanning_status = 'not_started'; + // document.getElementById('qr_scanner_viewfinder').classList.add('d_none'); + + // qr_scan_result = decoded_text; + // qr_found_text = decoded_text; + + // dispatch('qr_scan_result', { + // result: qr_scan_result, + // entry_method: 'QR', + // }); + + // // qr_scan_result = null; + // // qr_found_text = null; + // return true; + // }).catch((err) => { + // console.log('There was an error while trying to stop the scanning'); + // return false; + // }); } @@ -318,46 +277,6 @@ function handle_qr_manual_entry() { qr_scan_result = null; qr_entered_text = null; } - - - - - -function send_init_confirm_email(subject, message) { - console.log(`*** send_init_confirm_email() *** ${subject}`); - - let to_email = 'scott.idem+skdev@oneskyit.com'; - - // let origin_url = encodeURI(`${data.url.origin}`); - - let full_subject = `${subject} Aether QR Scanner Debugging`; - - let body_html = ` -
Scott, -

This is an automatic debug email from the Aether QR scanner.

-
- -
- -
- Message:
-
-    ${JSON.stringify(message)}
-    
-
- `; - - api.send_email({ - api_cfg: $ae_api, - from_email: 'noreply+ae_qr_debug@oneskyit.com', - from_name: 'AE QR Debug', - to_email: to_email, - subject: full_subject, - body_html: body_html, - }); -} - - diff --git a/src/routes/events_leads/exhibit/[slug]/leads_add_scan backup.svelte b/src/routes/events_leads/exhibit/[slug]/leads_add_scan backup.svelte new file mode 100644 index 00000000..5211c92c --- /dev/null +++ b/src/routes/events_leads/exhibit/[slug]/leads_add_scan backup.svelte @@ -0,0 +1,871 @@ + + + +
+ +{#if $events_loc?.leads.auth_exhibit_kv && $events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id]} + +{#if $events_loc?.leads.auth_exhibit_kv[$events_slct.exhibit_id].key} +
Leads for: + {$events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id].key} +
+{:else} +
Please go to the Main tab and select a license to use.
+{/if} + + + +

+ + {#if $ae_loc.hub.qr.camera_status == 'unknown'} + You will need to allow access to your device's camera when asked. + {:else if $ae_loc.hub.qr.camera_status == 'denied'} + You need to allow access to your device's camera. Currently this seems to be blocked or denied for this site. + Please check your browser's permissions. + {/if} +

+ + + + + + + + + +{#if ($events_loc.leads.show_content__scan_requirements)} + +{:else if (!$events_loc.leads.show_content__scan_requirements)} + +{/if} + + +{#if $events_loc.leads.show_content__scan_requirements} +
+

You will need a device with a camera to scan the QR codes. You will also of course need one or more valid QR codes to scan. + +

+ +
+{:else} + +{/if} + + +{:else} +
Not logged in. Please log in and select a user license.
+{/if} + +
+ + +{#if $events_sess.leads.show_form__search} +
+ +
+{/if} + + + + + + +{#if $events_sess.leads.show_form__scan} +
+
+
+

Scan

+ +
+ +
+
+ +
+ + + + + + +
+ {@html $events_sess.leads.qr_scan_result ?? 'No results yet'} +
+ + + + + + {#if $events_sess.leads.show_confirm__add_lead[$events_slct.badge_id] && $event_badge_obj} +
+
+
+

Add Scanned?

+ +
+ +
+
+ +
+

Are you sure you want to add {$event_badge_obj.full_name} to the leads list?

+

Badge ID: {$event_badge_obj.event_badge_id_random}

+
+ + + +
+
+
+ +
+ {/if} + + +
+ +
+ + +
+ + + +
+ submit: {$events_sess?.leads.submit_status__scan} +
+
+ +
+ +
+ +
+ +
+
+{/if} + + + diff --git a/src/routes/events_leads/exhibit/[slug]/leads_add_scan.svelte b/src/routes/events_leads/exhibit/[slug]/leads_add_scan.svelte index 5211c92c..3bdb9a45 100644 --- a/src/routes/events_leads/exhibit/[slug]/leads_add_scan.svelte +++ b/src/routes/events_leads/exhibit/[slug]/leads_add_scan.svelte @@ -799,26 +799,25 @@ function handle_qr_camera(event) {