Use new JSON interface in Emscripten.

GitOrigin-RevId: 5294d98c5f615256ea41887c04f863d1adaf4de1
This commit is contained in:
levlam 2020-10-08 02:52:34 +03:00
parent 8460bb7cd5
commit 6d1d227609
2 changed files with 15 additions and 17 deletions

View File

@ -620,16 +620,13 @@ class TdClient {
log.info('got TdModule');
this.td_functions = {
td_create: this.TdModule.cwrap('td_emscripten_create', 'number', []),
td_destroy: this.TdModule.cwrap('td_emscripten_destroy', null, ['number']),
td_send: this.TdModule.cwrap('td_emscripten_send', null, ['number', 'string']),
td_execute: this.TdModule.cwrap('td_emscripten_execute', 'string', [
'number',
'string'
]),
td_receive: this.TdModule.cwrap('td_emscripten_receive', 'string', ['number']),
td_receive: this.TdModule.cwrap('td_emscripten_receive', 'string', []),
td_set_verbosity: verbosity => {
this.td_functions.td_execute(
0,
JSON.stringify({
'@type': 'setLogVerbosityLevel',
new_verbosity_level: verbosity
@ -849,7 +846,7 @@ class TdClient {
execute(query) {
try {
const res = this.td_functions.td_execute(0, JSON.stringify(query));
const res = this.td_functions.td_execute(JSON.stringify(query));
const response = JSON.parse(res);
this.callback(response);
} catch (error) {
@ -863,7 +860,7 @@ class TdClient {
}
try {
while (true) {
const msg = this.td_functions.td_receive(this.client);
const msg = this.td_functions.td_receive();
if (!msg) {
break;
}

View File

@ -13,21 +13,22 @@
extern "C" {
EMSCRIPTEN_KEEPALIVE void *td_emscripten_create() {
return td_json_client_create();
EMSCRIPTEN_KEEPALIVE double td_emscripten_create() {
return td_create_client();
}
EMSCRIPTEN_KEEPALIVE void td_emscripten_send(void *client, const char *query) {
td_json_client_send(client, query);
EMSCRIPTEN_KEEPALIVE void td_emscripten_send(double client_id, const char *query) {
td_send(static_cast<int>(client_id), query);
}
EMSCRIPTEN_KEEPALIVE const char *td_emscripten_receive(void *client) {
return td_json_client_receive(client, 0);
EMSCRIPTEN_KEEPALIVE const char *td_emscripten_receive() {
return td_receive(0);
}
EMSCRIPTEN_KEEPALIVE const char *td_emscripten_execute(void *client, const char *query) {
return td_json_client_execute(client, query);
}
EMSCRIPTEN_KEEPALIVE void td_emscripten_destroy(void *client) {
td_json_client_destroy(client);
EMSCRIPTEN_KEEPALIVE const char *td_emscripten_execute(const char *query) {
return td_execute(query);
}
EMSCRIPTEN_KEEPALIVE double td_emscripten_get_timeout() {
return td::ConcurrentScheduler::emscripten_get_main_timeout();
}