webtty: begin experimenting with JSON protocol.

This commit is contained in:
John "Elwin" Edwards 2012-05-09 16:36:11 -07:00
parent 02cc454ad1
commit 71d43603a9
2 changed files with 6 additions and 5 deletions

View file

@ -302,13 +302,13 @@ function login(h, w) {
req.onreadystatechange = function () { req.onreadystatechange = function () {
if (req.readyState == 4 && req.status == 200) { if (req.readyState == 4 && req.status == 200) {
var datalines = req.responseText.split("\n"); var datalines = req.responseText.split("\n");
if (datalines[0] == 'l1') { var logindict = JSON.parse(req.responseText);
if (logindict.login) {
/* Success */ /* Success */
// FIXME extract the size from the response instead of hardcoding termemu.resize(logindict.h, logindict.w);
termemu.resize(25, 80);
termemu.alive = true; termemu.alive = true;
setTitle("Logged in"); setTitle("Logged in");
debug(1, "Logged in with id " + datalines[1]); debug(1, "Logged in with id " + logindict.id);
getData(); getData();
return; return;
} }

View file

@ -182,7 +182,8 @@ function login(req, res, formdata) {
var nsession = new TermSession(sessid, h, w); var nsession = new TermSession(sessid, h, w);
resheaders["Set-Cookie"] = "ID=" + sessid; resheaders["Set-Cookie"] = "ID=" + sessid;
res.writeHead(200, resheaders); res.writeHead(200, resheaders);
res.write("l1\n" + sessid + "\n" + String(h) + "x" + String(w) + "\n"); var logindict = {"login": true, "id": sessid, "w": w, "h": h};
res.write(JSON.stringify(logindict));
res.end(); res.end();
console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid); console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid);
return; return;