Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpqr-play-beep-on-scan.js: Added snippet to play beep sound on successful QR Code scan. #1013

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions gp-qr-code/gpqr-play-beep-on-scan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Gravity Perks // GP QR Code // Automatically Play Beep Sound on Successful Scan
* https://gravitywiz.com/documentation/gravity-forms-qr-code/
*
* When using the QR scanner, automatically play beep after a successful scan.
*
* Instruction Video: https://www.loom.com/share/7f413231517b423eba3ccc1bf3055b40
*
* We recommend installing this snippet with our free Custom Javascript plugin:
* https://gravitywiz.com/gravity-forms-code-chest/
*/
function playBeep() {
var context = new( window.AudioContext || window.webkitAudioContext )();
var oscillator = context.createOscillator();
var gainNode = context.createGain();

oscillator.type = "square"; // Square wave for a more scanner-like sound.
oscillator.frequency.setValueAtTime( 800, context.currentTime ); // Frequency in Hz.
gainNode.gain.setValueAtTime( 0.5, context.currentTime ); // Adjust volume.

oscillator.connect( gainNode );
gainNode.connect( context.destination );

oscillator.start();

// Beep duration in milliseconds.
setTimeout( () => {
oscillator.stop();
}, 100 );
}

gform.addAction( 'gpqr_on_scan_success', function( decodedText, decodedResult, gpqr ) {
playBeep();
} );
Loading