views:

1694

answers:

3

I need a distinct sound to play when a error occurs. The error is the result of a problem with one of perhaps two hundred barcodes that are being inputted in rapid fire. The event queue seems to handle keyboard input (which the barcode scanner emulates) first, and playing of my sound second. So if the barcodes are scanned quickly, the error sound stays in the queue, being bumped by the next scan.

Can I manipulate the priority of the queue?

+1  A: 

Javascript is not multi-threaded, so option 2 won't work. And I suspect that the event queue you speak of is the OS's event queue, which isn't likely to accessible from a browser, if at all.

Beyond that, I'm having a little trouble understanding your problem. What is firing the error sound? Is it a keyup, etc event or is it a server side validation that returns an error code or something else?

sblundy
I'm creating an embed object in the DOM with src=error.wav, hidden=true, and autostart=true. The sound plays, but only after the queue clears.
dacracot
There are arrays which are searched client side for error determination.
dacracot
A: 

What if you try to delay the scans (using setTimeout()), allowing the sounds to start and finish between them?

Kon
I'm afraid that if I delay the scan, I will miss the data. Since it is the user that pulls the trigger on the scan, I can not necessarily slow them down.
dacracot
Huh, I guess I don't understand how your scanner is interacting with the browser...that would be useful to know. You can still capture user input (from a keyboard, let's say) and allow other things to happen if you coordinate it correctly, regardless of how fast the user is.
Jason Bunting
The barcode scanner emulates a keyboard.
dacracot
Okay, what JavaScript event fires when something is scanned and what does an event handler for that look like? Or how does it emulate it? Answers would help us help you.
Jason Bunting
A: 

What I can guess from your problem is User stops scanning when he hears Error sound. If that is true, why wait for user to stop scan.

You can perform any of the following.

As soon as error occurs stop entering data. you can set 'keypress' to return false. also you can set a buffer on keypress event which first store input data and then return false. This way you will data after error has occurred.

BigBoss