changeset 182:3c0e7697bb30

Begin moving TermSession methods into the prototype. This should make a clearer line between general functionality and the initialization of specific instances.
author John "Elwin" Edwards
date Sat, 17 Jan 2015 19:57:40 -0500
parents 926b0780bc44
children db2f5ab112e9
files rlgwebd.js
diffstat 1 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/rlgwebd.js	Sat Jan 17 15:48:41 2015 -0500
+++ b/rlgwebd.js	Sat Jan 17 19:57:40 2015 -0500
@@ -130,25 +130,6 @@
   /* Array for watcher connections. */
   this.watchers = [];
   /* END setup */
-  this.framepush = function(chunk) {
-    /* If this chunk resets the screen, discard what preceded it. */
-    if (isclear(chunk)) {
-      this.framebuf = new Buffer(1024);
-      this.frameoff = 0;
-    }
-    /* Make sure there's space. */
-    while (this.framebuf.length < chunk.length + this.frameoff) {
-      var nbuf = new Buffer(this.framebuf.length * 2);
-      this.framebuf.copy(nbuf, 0, 0, this.frameoff);
-      this.framebuf = nbuf;
-      if (this.framebuf.length > 65536) {
-        tslog("Warning: Game %s frame buffer at %d bytes", this.tag(), 
-                this.framebuf.length);
-      }
-    }
-    chunk.copy(this.framebuf, this.frameoff);
-    this.frameoff += chunk.length;
-  };
   function ttyrec_chunk(datastr) {
     ss.lasttime = new Date();
     var buf = new Buffer(datastr);
@@ -183,9 +164,6 @@
   this.write = function(data) {
     this.term.write(data);
   };
-  this.tag = function() {
-    return this.game.uname + "/" + this.pname;
-  };
   // Teardown.
   this.term.on("exit", function () {
     var tag = ss.tag();
@@ -251,6 +229,30 @@
   };
 }
 TermSession.prototype = new events.EventEmitter();
+TermSession.prototype.tag = function () {
+  if (this.pname === undefined || this.game === undefined)
+    return "";
+  return this.game.uname + "/" + this.pname;
+};
+TermSession.prototype.framepush = function(chunk) {
+  /* If this chunk resets the screen, discard what preceded it. */
+  if (isclear(chunk)) {
+    this.framebuf = new Buffer(1024);
+    this.frameoff = 0;
+  }
+  /* Make sure there's space. */
+  while (this.framebuf.length < chunk.length + this.frameoff) {
+    var nbuf = new Buffer(this.framebuf.length * 2);
+    this.framebuf.copy(nbuf, 0, 0, this.frameoff);
+    this.framebuf = nbuf;
+    if (this.framebuf.length > 65536) {
+      tslog("Warning: Game %s frame buffer at %d bytes", this.tag(), 
+              this.framebuf.length);
+    }
+  }
+  chunk.copy(this.framebuf, this.frameoff);
+  this.frameoff += chunk.length;
+};
 
 function DglSession(filename) {
   var ss = this;