mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
snapshot: downloading wordlist seems to work
This commit is contained in:
parent
2ab2f5642e
commit
5e9863adaf
3 changed files with 103 additions and 38 deletions
|
@ -75,7 +75,7 @@ main.html: ${INPUTS} Makefile shell_minimal.html
|
||||||
--preload-file assets_dir --shell-file shell_minimal.html \
|
--preload-file assets_dir --shell-file shell_minimal.html \
|
||||||
-s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' \
|
-s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' \
|
||||||
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" \
|
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" \
|
||||||
-s EXPORTED_FUNCTIONS='["_main", "_gotMQTTMsg", "_cbckVoid", "_cbckString", "_MQTTConnectedChanged", "_onNewGame"]' \
|
-s EXPORTED_FUNCTIONS='["_main", "_cbckBinary", "_cbckVoid", "_cbckString", "_MQTTConnectedChanged", "_onNewGame", "_gotDictBinary"]' \
|
||||||
-s WASM=1 \
|
-s WASM=1 \
|
||||||
${INPUTS} -o $@
|
${INPUTS} -o $@
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,12 @@ static void loadName( GameState* gs );
|
||||||
static void saveName( GameState* gs );
|
static void saveName( GameState* gs );
|
||||||
static bool isVisible( GameState* gs );
|
static bool isVisible( GameState* gs );
|
||||||
|
|
||||||
|
typedef void (*BinProc)(void* closure, const uint8_t* data, int len );
|
||||||
|
|
||||||
|
EM_JS(void, call_get_dict, (void* closure), {
|
||||||
|
getDict(closure);
|
||||||
|
});
|
||||||
|
|
||||||
EM_JS(void, show_name, (const char* name), {
|
EM_JS(void, show_name, (const char* name), {
|
||||||
let jsname = UTF8ToString(name);
|
let jsname = UTF8ToString(name);
|
||||||
document.getElementById('gamename').textContent = jsname;
|
document.getElementById('gamename').textContent = jsname;
|
||||||
|
@ -163,13 +169,14 @@ EM_JS(void, call_get_string, (const char* msg, const char* dflt,
|
||||||
nbGetString( jsMgs, jsDflt, proc, closure );
|
nbGetString( jsMgs, jsDflt, proc, closure );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
EM_JS(void, call_haveDevID, (void* closure, const char* devid,
|
EM_JS(void, call_setup, (void* closure, const char* devid,
|
||||||
const char* gitrev, int now,
|
const char* gitrev, int now,
|
||||||
StringProc conflictProc,
|
StringProc conflictProc,
|
||||||
StringProc focussedProc ), {
|
StringProc focussedProc,
|
||||||
|
BinProc msgProc), {
|
||||||
let jsgr = UTF8ToString(gitrev);
|
let jsgr = UTF8ToString(gitrev);
|
||||||
onHaveDevID(closure, UTF8ToString(devid), jsgr, now,
|
jssetup(closure, UTF8ToString(devid), jsgr, now,
|
||||||
conflictProc, focussedProc);
|
conflictProc, focussedProc, msgProc);
|
||||||
});
|
});
|
||||||
|
|
||||||
EM_JS(bool, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), {
|
EM_JS(bool, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), {
|
||||||
|
@ -740,6 +747,13 @@ playLoadingDict( Globals* globals )
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
onMqttMsg(void* closure, const uint8_t* data, int len )
|
||||||
|
{
|
||||||
|
CAST_GLOB(Globals*, globals, closure);
|
||||||
|
dvc_parseMQTTPacket( globals->dutil, NULL, data, len );
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initDeviceGlobals( Globals* globals )
|
initDeviceGlobals( Globals* globals )
|
||||||
{
|
{
|
||||||
|
@ -772,7 +786,9 @@ initDeviceGlobals( Globals* globals )
|
||||||
XP_SNPRINTF( buf, VSIZE(buf), MQTTDevID_FMT, devID );
|
XP_SNPRINTF( buf, VSIZE(buf), MQTTDevID_FMT, devID );
|
||||||
XP_LOGFF( "got mqtt devID: %s", buf );
|
XP_LOGFF( "got mqtt devID: %s", buf );
|
||||||
int now = dutil_getCurSeconds( globals->dutil, NULL );
|
int now = dutil_getCurSeconds( globals->dutil, NULL );
|
||||||
call_haveDevID( globals, buf, GITREV, now, onConflict, onFocussed );
|
call_setup( globals, buf, GITREV, now, onConflict, onFocussed, onMqttMsg );
|
||||||
|
|
||||||
|
call_get_dict( globals );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1585,10 +1601,9 @@ MQTTConnectedChanged( void* closure, bool connected )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gotMQTTMsg( void* closure, int len, const uint8_t* msg )
|
cbckBinary( BinProc proc, void* closure, int len, const uint8_t* msg )
|
||||||
{
|
{
|
||||||
Globals* globals = (Globals*)closure;
|
(*proc)(closure, msg, len );
|
||||||
dvc_parseMQTTPacket( globals->dutil, NULL, msg, len );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1620,6 +1635,16 @@ cbckString( StringProc proc, void* closure, const char* str )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gotDictBinary( void* closure, const char* xwd, const char* lang,
|
||||||
|
const char* lc, int len, uint8_t* data )
|
||||||
|
{
|
||||||
|
XP_LOGFF( "xwd: %s; lang: %s, lc: %s, len: %d", xwd, lang, lc, len );
|
||||||
|
for ( int ii = 0; ii < 10; ++ii ) {
|
||||||
|
XP_LOGFF( "byte[%d]: 0x%X", ii, data[ii] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main( int argc, const char** argv )
|
main( int argc, const char** argv )
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,29 +45,67 @@ function registerOnce(devid, gitrev, now) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function getDict(closure, proc, lang) {
|
function getDict(closure) {
|
||||||
// console.log('getDict()');
|
// set these later
|
||||||
// fetch('/xw4/info.py/listDicts?lc=fr', {
|
let gots = {};
|
||||||
// method: 'post',
|
|
||||||
// headers: {
|
|
||||||
// 'Content-Type': 'application/json',
|
|
||||||
// },
|
|
||||||
// }).then(response => {
|
|
||||||
// console.log(response);
|
|
||||||
// if (response.ok) {
|
|
||||||
// return response.json();
|
|
||||||
// } else {
|
|
||||||
// console.log('bad respose; status: ' + respose.status);
|
|
||||||
// console.log('text: ' + response.statusText);
|
|
||||||
// console.log(response.type);
|
|
||||||
// }
|
|
||||||
// }).then(data => {
|
|
||||||
// console.log('data: ' + JSON.stringify(data));
|
|
||||||
// });
|
|
||||||
// console.log('getDict() done');
|
|
||||||
// }
|
|
||||||
|
|
||||||
function onHaveDevID(closure, devid, gitrev, now, noTabProc, focusProc) {
|
let langs = 'fr'; // navigator.language;
|
||||||
|
if (langs) {
|
||||||
|
langs = [langs.split('-')[0]];
|
||||||
|
}
|
||||||
|
console.log('langs: ' + langs + '; langs[0]: ' + langs[0]);
|
||||||
|
if (langs[0] != 'en' ) {
|
||||||
|
langs.push('en');
|
||||||
|
}
|
||||||
|
let args = '?lc=' + langs.join('|');
|
||||||
|
console.log('args: ' + args);
|
||||||
|
fetch('/xw4/info.py/listDicts' + args, {
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
}).then(response => {
|
||||||
|
console.log(response);
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json();
|
||||||
|
} else {
|
||||||
|
console.log('bad respose; status: ' + respose.status);
|
||||||
|
console.log('text: ' + response.statusText);
|
||||||
|
console.log(response.type);
|
||||||
|
}
|
||||||
|
}).then(data => {
|
||||||
|
// let langs = data.langs;
|
||||||
|
// console.log('data: ' + JSON.stringify(data));
|
||||||
|
for ( lang of data.langs ) {
|
||||||
|
console.log('lang: ' + JSON.stringify(lang));
|
||||||
|
// wget --no-check-certificate 'http://pi4.lan/android/French/ODS7_2to15.xwd'
|
||||||
|
let dict = lang.dicts[0];
|
||||||
|
gots.xwd = dict.xwd;
|
||||||
|
gots.langName = lang.lang;
|
||||||
|
gots.lc = lang.lc;
|
||||||
|
let path = '/' + ['android', gots.langName, gots.xwd].join('/');
|
||||||
|
return fetch(path);
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
// console.log('got here!!!' + response);
|
||||||
|
return response.arrayBuffer();
|
||||||
|
}).then(data=> {
|
||||||
|
let len = data.byteLength;
|
||||||
|
let dataPtr = Module._malloc(len);
|
||||||
|
// Copy data to Emscripten heap
|
||||||
|
var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, len);
|
||||||
|
dataHeap.set( new Uint8Array(data) );
|
||||||
|
// console.log('made array?: ' + dataHeap);
|
||||||
|
Module.ccall('gotDictBinary', null,
|
||||||
|
['number', 'string', 'string', 'string', 'number', 'array'],
|
||||||
|
[closure, gots.xwd, gots.langName, gots.lc, len, dataHeap]);
|
||||||
|
Module._free(dataPtr);
|
||||||
|
});
|
||||||
|
console.log('getDict() done');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called from main() asap after things are initialized etc.
|
||||||
|
function jssetup(closure, devid, gitrev, now, noTabProc, focusProc, msgProc) {
|
||||||
// Set a unique tag so we know if somebody comes along later
|
// Set a unique tag so we know if somebody comes along later
|
||||||
let tabID = Math.random();
|
let tabID = Math.random();
|
||||||
localStorage.setItem('tabID', tabID);
|
localStorage.setItem('tabID', tabID);
|
||||||
|
@ -88,10 +126,12 @@ function onHaveDevID(closure, devid, gitrev, now, noTabProc, focusProc) {
|
||||||
registerOnce(devid, gitrev, now);
|
registerOnce(devid, gitrev, now);
|
||||||
|
|
||||||
state.closure = closure;
|
state.closure = closure;
|
||||||
|
state.msgProc = msgProc;
|
||||||
document.getElementById("mqtt_span").textContent=devid;
|
document.getElementById("mqtt_span").textContent=devid;
|
||||||
|
|
||||||
function tellConnected(isConn) {
|
function tellConnected(isConn) {
|
||||||
Module.ccall('MQTTConnectedChanged', null, ['number', 'boolean'], [state.closure, isConn]);
|
Module.ccall('MQTTConnectedChanged', null, ['number', 'boolean'],
|
||||||
|
[state.closure, isConn]);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.client = new Paho.MQTT.Client("eehouse.org", 8883, '/wss', devid);
|
state.client = new Paho.MQTT.Client("eehouse.org", 8883, '/wss', devid);
|
||||||
|
@ -106,10 +146,10 @@ function onHaveDevID(closure, devid, gitrev, now, noTabProc, focusProc) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
state.client.onMessageArrived = function onMessageArrived(message) {
|
state.client.onMessageArrived = function onMessageArrived(message) {
|
||||||
var payload = message.payloadBytes;
|
let payload = message.payloadBytes;
|
||||||
var length = payload.length;
|
let length = payload.length;
|
||||||
Module.ccall('gotMQTTMsg', null, ['number', 'number', 'array'],
|
Module.ccall('cbckBinary', null, ['number', 'number', 'number', 'array'],
|
||||||
[state.closure, length, payload]);
|
[state.msgProc, state.closure, length, payload]);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
|
|
Loading…
Reference in a new issue