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

View File

@ -13,21 +13,22 @@
extern "C" { extern "C" {
EMSCRIPTEN_KEEPALIVE void *td_emscripten_create() { EMSCRIPTEN_KEEPALIVE double td_emscripten_create() {
return td_json_client_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 const char *td_emscripten_execute(const char *query) {
} return td_execute(query);
EMSCRIPTEN_KEEPALIVE void td_emscripten_destroy(void *client) {
td_json_client_destroy(client);
} }
EMSCRIPTEN_KEEPALIVE double td_emscripten_get_timeout() { EMSCRIPTEN_KEEPALIVE double td_emscripten_get_timeout() {
return td::ConcurrentScheduler::emscripten_get_main_timeout(); return td::ConcurrentScheduler::emscripten_get_main_timeout();
} }