comparison 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
comparison
equal deleted inserted replaced
111:f56fdfeed01a 112:4f2b89e6fde2
171 this.write = function(data) { 171 this.write = function(data) {
172 this.term.write(data); 172 this.term.write(data);
173 }; 173 };
174 // Teardown. 174 // Teardown.
175 this.term.on("exit", function () { 175 this.term.on("exit", function () {
176 var id = ss.sessid;
176 fs.unlink(ss.lock); 177 fs.unlink(ss.lock);
177 ss.record.end(); 178 ss.record.end();
178 ss.emit('exit'); 179 ss.emit('exit');
179 var id = ss.sessid; 180 gamemux.emit('end', id, ss.pname, ss.game.uname);
180 delete sessions[id]; 181 delete sessions[id];
181 tslog("Game %s ended.", id); 182 tslog("Game %s ended.", id);
182 gamemux.emit('end', id);
183 }); 183 });
184 this.close = function () { 184 this.close = function () {
185 if (this.sessid in sessions) 185 if (this.sessid in sessions)
186 this.term.kill('SIGHUP'); 186 this.term.kill('SIGHUP');
187 }; 187 };
1227 conn.sendUTF(JSON.stringify({"t": "b", "n": n, "p": name, "g": game})); 1227 conn.sendUTF(JSON.stringify({"t": "b", "n": n, "p": name, "g": game}));
1228 }; 1228 };
1229 var listH = function (list) { 1229 var listH = function (list) {
1230 conn.sendUTF(JSON.stringify(list)); 1230 conn.sendUTF(JSON.stringify(list));
1231 }; 1231 };
1232 var endH = function (n) { 1232 var endH = function (n, pname, gname) {
1233 conn.sendUTF(JSON.stringify({"t": "e", "n": n})); 1233 conn.sendUTF(JSON.stringify({"t": "e", "n": n, "p": pname, "g": gname}));
1234 }; 1234 };
1235 gamemux.on('begin', beginH); 1235 gamemux.on('begin', beginH);
1236 gamemux.on('list', listH); 1236 gamemux.on('list', listH);
1237 gamemux.on('end', endH); 1237 gamemux.on('end', endH);
1238 conn.on('message', tell); 1238 conn.on('message', tell);