mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-02-06 00:36:13 +08:00
* Initial version ready - bindings are in `bindings/emscripten.cpp` - minimal Javascript example is in `examples/ggwave-js` * add npm package + add test-ggwave.js * js : rename export name to "ggwave_factory" * update to v0.1.5 * Update README.md * npm : add npm-publish target
20 lines
596 B
JavaScript
20 lines
596 B
JavaScript
var factory = require('../bindings/javascript/ggwave.js')
|
|
|
|
factory().then(function(ggwave) {
|
|
// create ggwave instance with default parameters
|
|
var parameters = ggwave.getDefaultParameters();
|
|
var instance = ggwave.init(parameters);
|
|
|
|
var payload = 'hello js';
|
|
|
|
// generate audio waveform for string "hello js"
|
|
var waveform = ggwave.encode(instance, payload, ggwave.TxProtocolId.GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, 10);
|
|
|
|
// decode the audio waveform back to text
|
|
var res = ggwave.decode(instance, waveform);
|
|
|
|
if (res != payload) {
|
|
process.exit(1);
|
|
}
|
|
});
|