Begin moving TermSession methods into the prototype.

This should make a clearer line between general functionality and the
initialization of specific instances.
This commit is contained in:
John "Elwin" Edwards 2015-01-17 19:57:40 -05:00
parent 071f4c5fbf
commit 4034ab16ef

View file

@ -130,25 +130,6 @@ function TermSession(gname, pname, wsReq) {
/* 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 @@ function TermSession(gname, pname, wsReq) {
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 @@ function TermSession(gname, pname, wsReq) {
};
}
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;