mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +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 );
|
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,
|
const char* gitrev, int now,
|
||||||
StringProc conflictProc,
|
StringProc conflictProc,
|
||||||
StringProc focussedProc,
|
StringProc focussedProc,
|
||||||
BinProc msgProc), {
|
BinProc msgProc), {
|
||||||
let jsgr = UTF8ToString(gitrev);
|
let jsgr = UTF8ToString(gitrev);
|
||||||
jssetup(closure, UTF8ToString(devid), jsgr, now,
|
jssetup(closure, dbg, UTF8ToString(devid), jsgr, now,
|
||||||
conflictProc, focussedProc, msgProc);
|
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), {
|
||||||
|
@ -941,7 +941,14 @@ 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_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
|
static void
|
||||||
|
|
|
@ -8,22 +8,26 @@ function ccallString(proc, closure, str) {
|
||||||
[proc, closure, str]);
|
[proc, closure, str]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerOnce(devid, gitrev, now) {
|
function registerOnce(devid, gitrev, now, dbg) {
|
||||||
let nextTimeKey = 'next_reg';
|
let nextTimeKey = 'next_reg';
|
||||||
let gitKey = 'last_write';
|
let gitKey = 'last_write';
|
||||||
let nextTime = parseInt(localStorage.getItem(nextTimeKey));
|
let nextTime = parseInt(localStorage.getItem(nextTimeKey));
|
||||||
let prevGit = localStorage.getItem(gitKey);
|
let prevGit = localStorage.getItem(gitKey);
|
||||||
if ( prevGit == gitrev && now < nextTime ) {
|
if ( prevGit == gitrev && now < nextTime ) {
|
||||||
// console.log('registerOnce(): next in ' + (nextTime - now) + ' secs');
|
if ( dbg ) {
|
||||||
|
console.log('registerOnce(): next in ' + (nextTime - now) + ' secs');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let vrntName = window.location.host;
|
||||||
|
vrntName += window.location.pathname.split('/').slice(0, -1).join('/');
|
||||||
let args = { devid: devid,
|
let args = { devid: devid,
|
||||||
gitrev: gitrev,
|
gitrev: gitrev,
|
||||||
loc: navigator.language,
|
loc: navigator.language,
|
||||||
os: navigator.appName,
|
os: navigator.appName,
|
||||||
vers: '0.0',
|
vers: '0.0',
|
||||||
dbg: true,
|
dbg: dbg,
|
||||||
myNow: now,
|
myNow: now,
|
||||||
vrntName: 'wasm',
|
vrntName: vrntName,
|
||||||
};
|
};
|
||||||
let body = JSON.stringify(args);
|
let body = JSON.stringify(args);
|
||||||
|
|
||||||
|
@ -33,7 +37,8 @@ function registerOnce(devid, gitrev, now) {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
}).then(res => {
|
}).then(handleFetchErrors)
|
||||||
|
.then(res => {
|
||||||
return res.json();
|
return res.json();
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
// console.log('data: ' + JSON.stringify(data));
|
// console.log('data: ' + JSON.stringify(data));
|
||||||
|
@ -41,6 +46,8 @@ function registerOnce(devid, gitrev, now) {
|
||||||
localStorage.setItem(nextTimeKey, data.atNext);
|
localStorage.setItem(nextTimeKey, data.atNext);
|
||||||
localStorage.setItem(gitKey, gitrev);
|
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.
|
// 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
|
// 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);
|
||||||
|
@ -126,10 +133,11 @@ function jssetup(closure, devid, gitrev, now, noTabProc, focusProc, msgProc) {
|
||||||
ccallString(focusProc, state.closure, '');
|
ccallString(focusProc, state.closure, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
registerOnce(devid, gitrev, now);
|
|
||||||
|
|
||||||
state.closure = closure;
|
state.closure = closure;
|
||||||
state.msgProc = msgProc;
|
state.msgProc = msgProc;
|
||||||
|
|
||||||
|
registerOnce(devid, gitrev, now, dbg);
|
||||||
|
|
||||||
document.getElementById("mqtt_span").textContent=devid;
|
document.getElementById("mqtt_span").textContent=devid;
|
||||||
|
|
||||||
function tellConnected(isConn) {
|
function tellConnected(isConn) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue