RLG-Web: Complete the WebSocket watcher.
Watching via WebSockets now takes into account terminal size, player name, etc.
This commit is contained in:
parent
aee00a29d5
commit
f4c4f5e0f1
2 changed files with 13 additions and 2 deletions
11
rlgterm.js
11
rlgterm.js
|
|
@ -704,12 +704,19 @@ function wsWatch(gamenumber) {
|
||||||
ws.onopen = function (event) {
|
ws.onopen = function (event) {
|
||||||
session.id = true;
|
session.id = true;
|
||||||
session.sock = ws;
|
session.sock = ws;
|
||||||
message("You are now watching game #" + gamenumber + ".");
|
|
||||||
setmode("watch");
|
setmode("watch");
|
||||||
};
|
};
|
||||||
ws.onmessage = function (event) {
|
ws.onmessage = function (event) {
|
||||||
var msgObject = JSON.parse(event.data);
|
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);
|
writeData(msgObject.d);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -390,6 +390,10 @@ function wsWatcher(conn, session) {
|
||||||
session.removeListener('exit', exitH);
|
session.removeListener('exit', exitH);
|
||||||
tslog("A WebSocket watcher has left game %d", session.sessid);
|
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",
|
conn.sendUTF(JSON.stringify({"t": "d",
|
||||||
"d": session.framebuf.toString("hex", 0, session.frameoff)}));
|
"d": session.framebuf.toString("hex", 0, session.frameoff)}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue