Mercurial > hg > rlgwebd
changeset 101:e59d68082664
RLG-Web: Complete the WebSocket watcher.
Watching via WebSockets now takes into account terminal size, player
name, etc.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Fri, 13 Jul 2012 08:39:39 -0700 |
parents | 3dbfdaf62623 |
children | f34a286c51bd |
files | rlgterm.js rlgwebd.js |
diffstat | 2 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/rlgterm.js Thu Jul 12 22:16:15 2012 -0700 +++ b/rlgterm.js Fri Jul 13 08:39:39 2012 -0700 @@ -704,12 +704,19 @@ ws.onopen = function (event) { session.id = true; session.sock = ws; - message("You are now watching game #" + gamenumber + "."); setmode("watch"); }; ws.onmessage = function (event) { var msgObject = JSON.parse(event.data); - if (msgObject.t == 'd') { + if (msgObject.t == 'w') { + termemu.resize(msgObject.h, msgObject.w); + termemu.reset(); + termemu.toAltBuf(); + var pname = msgObject.p; + var gname = games[msgObject.g].name; + message("You are now watching " + pname + " play " + gname + "."); + } + else if (msgObject.t == 'd') { writeData(msgObject.d); } };
--- a/rlgwebd.js Thu Jul 12 22:16:15 2012 -0700 +++ b/rlgwebd.js Fri Jul 13 08:39:39 2012 -0700 @@ -390,6 +390,10 @@ session.removeListener('exit', exitH); tslog("A WebSocket watcher has left game %d", session.sessid); }); + conn.sendUTF(JSON.stringify({ + "t": "w", "w": session.w, "h": session.h, + "p": session.pname, "g": session.game.uname + })); conn.sendUTF(JSON.stringify({"t": "d", "d": session.framebuf.toString("hex", 0, session.frameoff)})); }