diff shterm.js @ 58:7a50b4412fea

Move credentials into the drivers. The session id, or whether the session is currently active on the server, are better handled in the drivers than in termemu.js.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 19 Jun 2012 13:40:30 -0700
parents 155f3c104759
children d7eb63cd7a16
line wrap: on
line diff
--- a/shterm.js	Mon Jun 18 16:53:44 2012 -0700
+++ b/shterm.js	Tue Jun 19 13:40:30 2012 -0700
@@ -2,6 +2,7 @@
  * is running a shell via the webtty.js server.
  */
 
+var isalive = false; // Whether the session is currently active.
 var nsend = 0; // The number of the next packet to send.
 var nrecv = 0; // The next packet expected.
 var msgQ = []; // Queue for out-of-order messages.
@@ -147,7 +148,7 @@
 }
 
 function getData() {
-  if (!termemu.alive)
+  if (!isalive)
     return;
   var datareq = new XMLHttpRequest();
   datareq.onreadystatechange = function () {
@@ -157,7 +158,7 @@
         return;
       else if (response.t == "E") {
         if (response.c == 1) {
-          termemu.alive = false;
+          isalive = false;
           debug(1, "Server error: " + response.s);
         }
       }
@@ -182,7 +183,7 @@
       return;
     else if (response.t == "E") {
       if (response.c == 1) {
-        termemu.alive = false;
+        isalive = false;
         debug(1, "Server error: " + response.s);
       }
       return;
@@ -245,7 +246,7 @@
     debug(1, "Ignoring keycode " + keynum);
     return;
   }
-  if (termemu.alive)
+  if (isalive)
     ev.preventDefault();
   var formdata = {"t": "d", "n": nsend++, "d": code};
   var datareq = new XMLHttpRequest();
@@ -333,7 +334,7 @@
 }
 
 function login(h, w) {
-  if (termemu.alive)
+  if (isalive)
     return;
   params = {"login": true, "h": h, "w": w};
   var req = new XMLHttpRequest();
@@ -343,7 +344,7 @@
       if (logindict.login) {
         /* Success */
         termemu.resize(logindict.h, logindict.w);
-        termemu.alive = true;
+        isalive = true;
         nsend = 0;
         nrecv = 0;
 	setTitle("Logged in");
@@ -366,7 +367,7 @@
     if (req.readyState == 4 && req.status == 200) {
       /* Figure out whether or not it worked. */
       /* FIXME the server might respond with output. */
-      termemu.alive = false;
+      isalive = false;
       return;
     }
   };