mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
pass dbg and host info via register
This commit is contained in:
parent
d03b1e5d7a
commit
99baf4bf3b
2 changed files with 27 additions and 12 deletions
|
@ -196,14 +196,14 @@ EM_JS(void, call_get_string, (const char* msg, const char* dflt,
|
|||
nbGetString( jsMgs, jsDflt, proc, closure );
|
||||
} );
|
||||
|
||||
EM_JS(void, call_setup, (void* closure, const char* devid,
|
||||
EM_JS(void, call_setup, (void* closure, bool dbg, const char* devid,
|
||||
const char* gitrev, int now,
|
||||
StringProc conflictProc,
|
||||
StringProc focussedProc,
|
||||
BinProc msgProc), {
|
||||
let jsgr = UTF8ToString(gitrev);
|
||||
jssetup(closure, UTF8ToString(devid), jsgr, now,
|
||||
conflictProc, focussedProc, msgProc);
|
||||
jssetup(closure, dbg, UTF8ToString(devid), jsgr, now,
|
||||
conflictProc, focussedProc, msgProc);
|
||||
});
|
||||
|
||||
EM_JS(bool, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), {
|
||||
|
@ -941,7 +941,14 @@ initDeviceGlobals( Globals* globals )
|
|||
XP_SNPRINTF( buf, VSIZE(buf), MQTTDevID_FMT, devID );
|
||||
XP_LOGFF( "got mqtt devID: %s", buf );
|
||||
int now = dutil_getCurSeconds( globals->dutil, NULL );
|
||||
call_setup( globals, buf, GITREV, now, onConflict, onFocussed, onMqttMsg );
|
||||
bool dbg =
|
||||
#ifdef DEBUG
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
;
|
||||
call_setup( globals, dbg, buf, GITREV, now, onConflict, onFocussed, onMqttMsg );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -8,22 +8,26 @@ function ccallString(proc, closure, str) {
|
|||
[proc, closure, str]);
|
||||
}
|
||||
|
||||
function registerOnce(devid, gitrev, now) {
|
||||
function registerOnce(devid, gitrev, now, dbg) {
|
||||
let nextTimeKey = 'next_reg';
|
||||
let gitKey = 'last_write';
|
||||
let nextTime = parseInt(localStorage.getItem(nextTimeKey));
|
||||
let prevGit = localStorage.getItem(gitKey);
|
||||
if ( prevGit == gitrev && now < nextTime ) {
|
||||
// console.log('registerOnce(): next in ' + (nextTime - now) + ' secs');
|
||||
if ( dbg ) {
|
||||
console.log('registerOnce(): next in ' + (nextTime - now) + ' secs');
|
||||
}
|
||||
} else {
|
||||
let vrntName = window.location.host;
|
||||
vrntName += window.location.pathname.split('/').slice(0, -1).join('/');
|
||||
let args = { devid: devid,
|
||||
gitrev: gitrev,
|
||||
loc: navigator.language,
|
||||
os: navigator.appName,
|
||||
vers: '0.0',
|
||||
dbg: true,
|
||||
dbg: dbg,
|
||||
myNow: now,
|
||||
vrntName: 'wasm',
|
||||
vrntName: vrntName,
|
||||
};
|
||||
let body = JSON.stringify(args);
|
||||
|
||||
|
@ -33,7 +37,8 @@ function registerOnce(devid, gitrev, now) {
|
|||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
}).then(handleFetchErrors)
|
||||
.then(res => {
|
||||
return res.json();
|
||||
}).then(data => {
|
||||
// console.log('data: ' + JSON.stringify(data));
|
||||
|
@ -41,6 +46,8 @@ function registerOnce(devid, gitrev, now) {
|
|||
localStorage.setItem(nextTimeKey, data.atNext);
|
||||
localStorage.setItem(gitKey, gitrev);
|
||||
}
|
||||
}).catch(ex => {
|
||||
console.error('registerOnce(): fetch()=>' + ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +115,7 @@ function getDict(langs, proc, closure) {
|
|||
}
|
||||
|
||||
// Called from main() asap after things are initialized etc.
|
||||
function jssetup(closure, devid, gitrev, now, noTabProc, focusProc, msgProc) {
|
||||
function jssetup(closure, dbg, devid, gitrev, now, noTabProc, focusProc, msgProc) {
|
||||
// Set a unique tag so we know if somebody comes along later
|
||||
let tabID = Math.random();
|
||||
localStorage.setItem('tabID', tabID);
|
||||
|
@ -126,10 +133,11 @@ function jssetup(closure, devid, gitrev, now, noTabProc, focusProc, msgProc) {
|
|||
ccallString(focusProc, state.closure, '');
|
||||
};
|
||||
|
||||
registerOnce(devid, gitrev, now);
|
||||
|
||||
state.closure = closure;
|
||||
state.msgProc = msgProc;
|
||||
|
||||
registerOnce(devid, gitrev, now, dbg);
|
||||
|
||||
document.getElementById("mqtt_span").textContent=devid;
|
||||
|
||||
function tellConnected(isConn) {
|
||||
|
|
Loading…
Add table
Reference in a new issue