diff rlgterm.js @ 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 a9371002aecc
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);
     }
   };