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:
parent
071f4c5fbf
commit
4034ab16ef
1 changed files with 24 additions and 22 deletions
46
rlgwebd.js
46
rlgwebd.js
|
|
@ -130,25 +130,6 @@ function TermSession(gname, pname, wsReq) {
|
||||||
/* Array for watcher connections. */
|
/* Array for watcher connections. */
|
||||||
this.watchers = [];
|
this.watchers = [];
|
||||||
/* END setup */
|
/* 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) {
|
function ttyrec_chunk(datastr) {
|
||||||
ss.lasttime = new Date();
|
ss.lasttime = new Date();
|
||||||
var buf = new Buffer(datastr);
|
var buf = new Buffer(datastr);
|
||||||
|
|
@ -183,9 +164,6 @@ function TermSession(gname, pname, wsReq) {
|
||||||
this.write = function(data) {
|
this.write = function(data) {
|
||||||
this.term.write(data);
|
this.term.write(data);
|
||||||
};
|
};
|
||||||
this.tag = function() {
|
|
||||||
return this.game.uname + "/" + this.pname;
|
|
||||||
};
|
|
||||||
// Teardown.
|
// Teardown.
|
||||||
this.term.on("exit", function () {
|
this.term.on("exit", function () {
|
||||||
var tag = ss.tag();
|
var tag = ss.tag();
|
||||||
|
|
@ -251,6 +229,30 @@ function TermSession(gname, pname, wsReq) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
TermSession.prototype = new events.EventEmitter();
|
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) {
|
function DglSession(filename) {
|
||||||
var ss = this;
|
var ss = this;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue