# stackmat.js - use the Stackmat timer on the Web



## tim (Jan 5, 2013)

Hey!

Since I make great use of mark2 for Cubemania, I'd like to give something back to the community:
I spent my entire Saturday hacking on a small library which provides access to the Stackmat timer from within JavaScript (no Flash or Java required!). This is done by using the HTML5 Web Audio API.

*Supported browsers*:
* Chrome (version > 21)

*A quick demo*: http://jsfiddle.net/q97Zc/

*Github link*: https://github.com/timhabermaas/stackmat.js

Be aware: It's still pre-alpha — in fact it doesn't even have a version number, yet. So, it's probably totally broken.

I'm not too happy with the public API. Maybe polling for updates instead of firing callbacks is more convenient? I'd like to hear some feedback! 

Big thanks to: 
- Florian W. for his documentation on the Stackmat protocol: http://hackvalue.de/hv_atmel_stackmat
- Walter for PPT. I peeked more than once into his stackmat code.
- Vino for his idea of using the Audio API in combination with a Stackmat timer.
- Thomas Müller for lending me his Stackmat timer.


----------



## joey (Jan 5, 2013)

Callbacks are nicer.


----------



## jfly (Jan 6, 2013)

This is awesome, Tim! Last I looked into this, I don't think any webbrowser actually supported the web audio api.

Would you be interested in adding a flash fallback for web browsers that don't support the audio api? I've already written the flash code here https://github.com/jfly/tnoodle/tree/master/stackmat-flash, and it's currently being used by tnoodle.


----------



## tim (Jan 9, 2013)

Yep, I'm interested. I'll give it a shot next week since I'm quite busy right now.

In the meantime: What's this line for? Avoiding the browser's cache?


----------



## jfly (Jan 10, 2013)

Yeah, whoops. That probably shouldn't have gotten committed.

I think polling is more appropriate than callbacks for someone rendering the time. A properly written program will have its own rendering thread (using requestAnimationFrame if they're really on top of things).

It would be nice to be able to register callbacks for events like "timer started", "timer stopped", "timer reset", "hands changed", however.


----------



## CoderGuru (Jan 3, 2022)

tim said:


> Yep, I'm interested. I'll give it a shot next week since I'm quite busy right now.
> 
> In the meantime: What's this line for? Avoiding the browser's cache?



Could a working example be created? I've been trying to configure this, including trying the example and both don't work. Help would be appreciated.


----------



## CoderGuru (Jan 4, 2022)

I have tried to integrate it as shown in the fiddle, but the fiddle is also presenting an error. I think part of it may be deprecated.


----------

