RLG-Web: improvements to choices and status messaging.
Server-side, have gamemux 'end' events include the name and game, so they can be sent to WebSockets connected to /status. This means a WebSocket client only needs to update its choice list when it gets a begin or end message with its own username. So it only needs to check /pstatus/<name> at those times and can stop polling.
This commit is contained in:
parent
a0be18657b
commit
f7f56fedae
2 changed files with 16 additions and 10 deletions
18
rlgterm.js
18
rlgterm.js
|
|
@ -533,6 +533,10 @@ function wsCurrent() {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (session.lcred) {
|
||||||
|
/* When starting the socket, the choices list might not be initialized. */
|
||||||
|
getchoices();
|
||||||
|
}
|
||||||
if (statsock)
|
if (statsock)
|
||||||
return;
|
return;
|
||||||
statsock = new WebSocket("ws://" + window.location.host + "/status");
|
statsock = new WebSocket("ws://" + window.location.host + "/status");
|
||||||
|
|
@ -544,10 +548,12 @@ function wsCurrent() {
|
||||||
if (e instanceof SyntaxError)
|
if (e instanceof SyntaxError)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.t != "t") {
|
if (msg.t == "t") {
|
||||||
return;
|
tableCurrent(msg.g);
|
||||||
|
}
|
||||||
|
else if ((msg.t == "b" || msg.t == "e") && msg.p == session.lname) {
|
||||||
|
getchoices();
|
||||||
}
|
}
|
||||||
tableCurrent(msg.g);
|
|
||||||
};
|
};
|
||||||
statsock.onclose = function (ev) {
|
statsock.onclose = function (ev) {
|
||||||
statsock = null;
|
statsock = null;
|
||||||
|
|
@ -555,6 +561,9 @@ function wsCurrent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getcurrent(clear) {
|
function getcurrent(clear) {
|
||||||
|
if (WebSocket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (session.id || clear) {
|
if (session.id || clear) {
|
||||||
if (statInterval) {
|
if (statInterval) {
|
||||||
window.clearInterval(statInterval);
|
window.clearInterval(statInterval);
|
||||||
|
|
@ -567,9 +576,6 @@ function getcurrent(clear) {
|
||||||
}
|
}
|
||||||
if (session.lcred)
|
if (session.lcred)
|
||||||
getchoices();
|
getchoices();
|
||||||
if (WebSocket) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.onerror = errHandler;
|
req.onerror = errHandler;
|
||||||
req.onreadystatechange = function () {
|
req.onreadystatechange = function () {
|
||||||
|
|
|
||||||
|
|
@ -173,13 +173,13 @@ function TermSession(game, lkey, dims, handlers) {
|
||||||
};
|
};
|
||||||
// Teardown.
|
// Teardown.
|
||||||
this.term.on("exit", function () {
|
this.term.on("exit", function () {
|
||||||
|
var id = ss.sessid;
|
||||||
fs.unlink(ss.lock);
|
fs.unlink(ss.lock);
|
||||||
ss.record.end();
|
ss.record.end();
|
||||||
ss.emit('exit');
|
ss.emit('exit');
|
||||||
var id = ss.sessid;
|
gamemux.emit('end', id, ss.pname, ss.game.uname);
|
||||||
delete sessions[id];
|
delete sessions[id];
|
||||||
tslog("Game %s ended.", id);
|
tslog("Game %s ended.", id);
|
||||||
gamemux.emit('end', id);
|
|
||||||
});
|
});
|
||||||
this.close = function () {
|
this.close = function () {
|
||||||
if (this.sessid in sessions)
|
if (this.sessid in sessions)
|
||||||
|
|
@ -1229,8 +1229,8 @@ function wsHandler(wsRequest) {
|
||||||
var listH = function (list) {
|
var listH = function (list) {
|
||||||
conn.sendUTF(JSON.stringify(list));
|
conn.sendUTF(JSON.stringify(list));
|
||||||
};
|
};
|
||||||
var endH = function (n) {
|
var endH = function (n, pname, gname) {
|
||||||
conn.sendUTF(JSON.stringify({"t": "e", "n": n}));
|
conn.sendUTF(JSON.stringify({"t": "e", "n": n, "p": pname, "g": gname}));
|
||||||
};
|
};
|
||||||
gamemux.on('begin', beginH);
|
gamemux.on('begin', beginH);
|
||||||
gamemux.on('list', listH);
|
gamemux.on('list', listH);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue