Add client-side support for watching dgamelaunch games.

This commit is contained in:
John "Elwin" Edwards 2015-01-14 07:44:22 -05:00
parent 7332b95a30
commit 2e0cec33ba
3 changed files with 37 additions and 25 deletions

View file

@ -337,6 +337,7 @@ function tableCurrent(gamelist) {
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 @@ function tableCurrent(gamelist) {
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 @@ function wsCurrent() {
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 textsize(larger) {
}
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) {