Javascript bindings (#14)

* 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
This commit is contained in:
Georgi Gerganov
2021-01-24 17:25:58 +02:00
committed by GitHub
parent 105e0fd48d
commit 19f353018d
19 changed files with 485 additions and 57 deletions

View File

@@ -1,6 +1,17 @@
if (EMSCRIPTEN)
#
# test-ggwave-js
set(TEST_TARGET test-ggwave-js)
add_test(NAME ${TEST_TARGET}
COMMAND node test-ggwave.js
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
return()
endif()
#
# test-ggwave-c

19
tests/test-ggwave.js Normal file
View File

@@ -0,0 +1,19 @@
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);
}
});

View File

@@ -1,6 +1,7 @@
import sys
import ggwave
# create ggwave instance with default parameters
instance = ggwave.init()
payload = 'hello python'