changeset 176:bf518a00190b

Add client-side support for watching dgamelaunch games.
author John "Elwin" Edwards
date Wed, 14 Jan 2015 07:44:22 -0500
parents 4dd87508fc96
children 5372f1f97cf5
files index-rlg.html rlgterm.js rlgwebd.js
diffstat 3 files changed, 37 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/index-rlg.html	Tue Jan 13 20:30:10 2015 -0500
+++ b/index-rlg.html	Wed Jan 14 07:44:22 2015 -0500
@@ -101,7 +101,7 @@
 <div class="modal" id="current">
 <div id="gametable" class="formtable">
  <div class="tcapt">Games in Progress</div>
- <div><div>Player</div><div>Game</div><div>Idle time</div><div>Actions</div></div>
+ <div><div>Player</div><div>Game</div><div>Source</div><div>Idle time</div><div>Actions</div></div>
 </div>
 <div id="nogames">No one is playing right now.</div>
 </div>
--- a/rlgterm.js	Tue Jan 13 20:30:10 2015 -0500
+++ b/rlgterm.js	Wed Jan 14 07:44:22 2015 -0500
@@ -337,6 +337,7 @@
     var cell2 = document.createElement("div");
     var cell3 = document.createElement("div");
     var cell4 = document.createElement("div");
+    var cell5 = document.createElement("div");
     cell1.appendChild(document.createTextNode(gamelist[i].p));
     var uname = gamelist[i].g;
     if (uname in games)
@@ -344,16 +345,23 @@
     else {
       continue;
     }
-    cell3.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
+    var srcstr = "VR";
+    if (gamelist[i].c == "rlg")
+      srcstr = "Web";
+    else if (gamelist[i].c == "dgl")
+      srcstr = "SSH";
+    cell3.appendChild(document.createTextNode(srcstr));
+    cell4.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
     var button = document.createElement("span");
     button.appendChild(document.createTextNode("Watch"));
     button.onclick = makeWatcher(uname + "/" + gamelist[i].p);
     button.className = "ibutton";
-    cell4.appendChild(button);
+    cell5.appendChild(button);
     row.appendChild(cell1);
     row.appendChild(cell2);
     row.appendChild(cell3);
     row.appendChild(cell4);
+    row.appendChild(cell5);
     gamediv.appendChild(row);
   }
 }
@@ -413,6 +421,7 @@
       var justbegun = {};
       justbegun.g = msg.g;
       justbegun.p = msg.p;
+      justbegun.c = msg.c;
       justbegun.i = 0;
       currentList.push(justbegun);
       tableCurrent(currentList);
@@ -873,19 +882,20 @@
 }
 
 function idlestr(ms) {
+  /* Minute accuracy is good enough. */
   if (typeof(ms) != "number")
     return "?";
-  var seconds = Math.round(ms / 1000);
-  var ss = String(seconds % 60);
-  if (ss.length < 2)
-    ss = "0" + ss;
-  var mm = String(Math.floor((seconds % 3600) / 60));
-  if (mm.length < 2)
-    mm = "0" + mm;
-  var hh = String(Math.floor(seconds / 3600));
-  if (hh.length < 2)
-    hh = "0" + hh;
-  return hh + ":" + mm + ":" + ss;
+  var minutes = Math.round(ms / 60000);
+  if (minutes < 60)
+    return String(minutes) + " min";
+  var hours = Math.floor(minutes / 60);
+  if (hours < 24)
+    return String(hours) + " hr " + String(minutes % 60) + " min";
+  var days = Math.floor(days / 24);
+  if (days == 1)
+    return "1 day " + String(hours % 24) + " hr";
+  else
+    return String(days) + " days " + String(hours % 24) + " hr";
 }
 
 function bell(on) {
--- a/rlgwebd.js	Tue Jan 13 20:30:10 2015 -0500
+++ b/rlgwebd.js	Wed Jan 14 07:44:22 2015 -0500
@@ -109,7 +109,7 @@
   tslog("%s playing %s (pid %d)", this.pname, this.game.uname, this.term.pid);
   this.failed = false;
   sessions[this.game.uname + "/" + this.pname] = this;
-  gamemux.emit('begin', this.game.uname, this.pname);
+  gamemux.emit('begin', this.game.uname, this.pname, 'rlg');
   /* Set up the lockfile and ttyrec */
   this.lasttime = new Date();
   var ts = timestamp(this.lasttime);
@@ -345,6 +345,7 @@
         ss.fd = fd;
         ss.emit('open', true);
         tslog("DGL %s: open", ss.tag());
+        gamemux.emit('begin', ss.gname, ss.pname, 'dgl');
         ss.readchunk();
         ss.recwatcher = fs.watch(ss.ttyrec, function (ev, finame) {
           if (ev == "change")
@@ -368,6 +369,7 @@
     }
     fs.close(this.fd);
     this.emit("close");
+    gamemux.emit('end', this.gname, this.pname);
     tslog("DGL %s: closed", ss.tag());
   };
   this.watchers = [];
@@ -820,22 +822,21 @@
   var now = new Date();
   var statusinfo = {"s": allowlogin, "g": []};
   for (var tag in sessions) {
-    var gamedesc = {};
+    var gamedesc = {"c": "rlg"};
     gamedesc["p"] = sessions[tag].pname;
     gamedesc["g"] = sessions[tag].game.uname;
     gamedesc["i"] = now - sessions[tag].lasttime;
     gamedesc["w"] = sessions[tag].watchers.length;
     statusinfo["g"].push(gamedesc);
   }
-  statusinfo["dgl"] = [];
   for (var tag in dglgames) {
-    var dglinfo = {};
+    var dglinfo = {"c": "dgl"};
     var slash = tag.search('/');
     dglinfo["g"] = tag.slice(0, slash);
     dglinfo["p"] = tag.slice(slash + 1);
     dglinfo["i"] = now - dglgames[tag].lasttime;
     dglinfo["w"] = dglgames[tag].watchers.length;
-    statusinfo["dgl"].push(dglinfo);
+    statusinfo["g"].push(dglinfo);
   }
   callback(statusinfo);
 }
@@ -1084,8 +1085,9 @@
         conn.sendUTF(JSON.stringify(info));
       });
     }
-    var beginH = function (gname, pname) {
-      conn.sendUTF(JSON.stringify({"t": "b", "p": pname, "g": gname}));
+    var beginH = function (gname, pname, client) {
+      conn.sendUTF(JSON.stringify({"t": "b", "c": client, "p": pname, 
+                   "g": gname}));
     };
     var listH = function (list) {
       conn.sendUTF(JSON.stringify(list));
@@ -1112,11 +1114,11 @@
  * complete list. */
 function pushStatus() {
   var now = new Date();
-  var statusinfo = {"t": "p", "s": allowlogin, "g": [], "dgl": []};
+  var statusinfo = {"t": "p", "s": allowlogin, "g": []};
   for (var tag in sessions) {
     var delta = now - sessions[tag].lasttime;
     if (delta < 60000) {
-      var gamedesc = {};
+      var gamedesc = {"c": "rlg"};
       gamedesc["p"] = sessions[tag].pname;
       gamedesc["g"] = sessions[tag].game.uname;
       gamedesc["i"] = delta;
@@ -1127,13 +1129,13 @@
   for (var tag in dglgames) {
     var delta = now - dglgames[tag].lasttime;
     if (delta < 60000) {
-      var dglinfo = {};
+      var dglinfo = {"c": "dgl"};
       var slash = tag.search('/');
       dglinfo["g"] = tag.slice(0, slash);
       dglinfo["p"] = tag.slice(slash + 1);
       dglinfo["i"] = delta;
       dglinfo["w"] = dglgames[tag].watchers.length;
-      statusinfo["dgl"].push(dglinfo);
+      statusinfo["g"].push(dglinfo);
     }
   }
   gamemux.emit('list', statusinfo);