Skip to content

Commit 57a8e61

Browse files
authored
gpqr-play-beep-on-scan.js: Added snippet to play beep sound on successful QR Code scan.
1 parent 42469f3 commit 57a8e61

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Gravity Perks // GP QR Code // Automatically Play Beep Sound on Successful Scan
3+
* https://gravitywiz.com/documentation/gravity-forms-qr-code/
4+
*
5+
* When using the QR scanner, automatically play beep after a successful scan.
6+
*
7+
* Instruction Video: https://www.loom.com/share/7f413231517b423eba3ccc1bf3055b40
8+
*
9+
* We recommend installing this snippet with our free Custom Javascript plugin:
10+
* https://gravitywiz.com/gravity-forms-code-chest/
11+
*/
12+
function playBeep() {
13+
var context = new( window.AudioContext || window.webkitAudioContext )();
14+
var oscillator = context.createOscillator();
15+
var gainNode = context.createGain();
16+
17+
oscillator.type = "square"; // Square wave for a more scanner-like sound.
18+
oscillator.frequency.setValueAtTime( 800, context.currentTime ); // Frequency in Hz.
19+
gainNode.gain.setValueAtTime( 0.5, context.currentTime ); // Adjust volume.
20+
21+
oscillator.connect( gainNode );
22+
gainNode.connect( context.destination );
23+
24+
oscillator.start();
25+
26+
// Beep duration in milliseconds.
27+
setTimeout( () => {
28+
oscillator.stop();
29+
}, 100 );
30+
}
31+
32+
gform.addAction( 'gpqr_on_scan_success', function( decodedText, decodedResult, gpqr ) {
33+
playBeep();
34+
} );

0 commit comments

Comments
 (0)