changeset 10:d051aad3e95f

webtty: begin experimenting with JSON protocol.
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 09 May 2012 16:36:11 -0700
parents 826a7ced69f8
children 481dcee353c9
files shterm.js webtty.js
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/shterm.js	Wed May 09 13:38:05 2012 -0700
+++ b/shterm.js	Wed May 09 16:36:11 2012 -0700
@@ -302,13 +302,13 @@
   req.onreadystatechange = function () {
     if (req.readyState == 4 && req.status == 200) {
       var datalines = req.responseText.split("\n");
-      if (datalines[0] == 'l1') {
+      var logindict = JSON.parse(req.responseText);
+      if (logindict.login) {
         /* Success */
-        // FIXME extract the size from the response instead of hardcoding
-        termemu.resize(25, 80);
+        termemu.resize(logindict.h, logindict.w);
         termemu.alive = true;
 	setTitle("Logged in");
-        debug(1, "Logged in with id " + datalines[1]);
+        debug(1, "Logged in with id " + logindict.id);
         getData();
         return;
       }
--- a/webtty.js	Wed May 09 13:38:05 2012 -0700
+++ b/webtty.js	Wed May 09 16:36:11 2012 -0700
@@ -182,7 +182,8 @@
   var nsession = new TermSession(sessid, h, w);
   resheaders["Set-Cookie"] = "ID=" + sessid;
   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();
   console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid);
   return;