diff rlgwebd.js @ 112:4f2b89e6fde2

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.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 16 Jul 2012 08:23:51 -0700
parents f56fdfeed01a
children 43340faa061c
line wrap: on
line diff
--- a/rlgwebd.js	Sun Jul 15 22:33:44 2012 -0700
+++ b/rlgwebd.js	Mon Jul 16 08:23:51 2012 -0700
@@ -173,13 +173,13 @@
   };
   // Teardown.
   this.term.on("exit", function () {
+    var id = ss.sessid;
     fs.unlink(ss.lock);
     ss.record.end();
     ss.emit('exit');
-    var id = ss.sessid;
+    gamemux.emit('end', id, ss.pname, ss.game.uname);
     delete sessions[id];
     tslog("Game %s ended.", id);
-    gamemux.emit('end', id);
   });
   this.close = function () {
     if (this.sessid in sessions)
@@ -1229,8 +1229,8 @@
     var listH = function (list) {
       conn.sendUTF(JSON.stringify(list));
     };
-    var endH = function (n) {
-      conn.sendUTF(JSON.stringify({"t": "e", "n": n}));
+    var endH = function (n, pname, gname) {
+      conn.sendUTF(JSON.stringify({"t": "e", "n": n, "p": pname, "g": gname}));
     };
     gamemux.on('begin', beginH);
     gamemux.on('list', listH);