forked from cory/tildefriends
Do corking client-side. Beside not blowing up on giant packets, it is more snappy for the client.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3405 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
fb776ef6c8
commit
bbf980b672
@ -296,10 +296,31 @@ function split(container, children) {
|
||||
}
|
||||
}
|
||||
|
||||
var gCorkCount = 0;
|
||||
var gCorkLines = [];
|
||||
|
||||
function receive(data) {
|
||||
for (var i in data.lines) {
|
||||
var line = data.lines[i];
|
||||
|
||||
if (line && line[0] && line[0].action == "cork"
|
||||
|| line && line.value && line.value[0].action == "cork") {
|
||||
++gCorkCount;
|
||||
continue;
|
||||
} else if (line && line[0] && line[0].action == "uncork"
|
||||
|| line && line.value && line.value[0].action == "uncork") {
|
||||
if (--gCorkCount <= 0) {
|
||||
receive({lines: gCorkLines});
|
||||
gCorkLines.length = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gCorkCount > 0) {
|
||||
gCorkLines.push(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
var target = document.getElementsByClassName("terminal")[0].id;
|
||||
if (line && line.terminal) {
|
||||
if (document.getElementById("terminal_" + line.terminal)) {
|
||||
@ -307,6 +328,7 @@ function receive(data) {
|
||||
}
|
||||
line = line.value;
|
||||
}
|
||||
|
||||
if (line && line.action == "ping") {
|
||||
gSocket.send(JSON.stringify({action: "pong"}));
|
||||
} else if (line && line.action == "session") {
|
||||
@ -790,6 +812,9 @@ function connectSocket() {
|
||||
['watchPosition', 'options'],
|
||||
['clearWatch'],
|
||||
|
||||
['cork'],
|
||||
['uncork'],
|
||||
|
||||
['setSendDeviceOrientationEvents', 'value'],
|
||||
],
|
||||
}));
|
||||
|
@ -321,8 +321,6 @@ async function getProcess(packageOwner, packageName, key, options) {
|
||||
'readLine': process.terminal.readLine.bind(process.terminal),
|
||||
'setEcho': process.terminal.setEcho.bind(process.terminal),
|
||||
'select': process.terminal.select.bind(process.terminal),
|
||||
'cork': process.terminal.cork.bind(process.terminal),
|
||||
'uncork': process.terminal.uncork.bind(process.terminal),
|
||||
};
|
||||
if (options.terminalApi) {
|
||||
for (let i in options.terminalApi) {
|
||||
@ -391,11 +389,15 @@ function updateProcesses(packageOwner, packageName) {
|
||||
var process = gProcesses[i];
|
||||
if (process.packageOwner == packageOwner
|
||||
&& process.packageName == packageName) {
|
||||
try {
|
||||
if (process.terminal) {
|
||||
process.terminal.notifyUpdate();
|
||||
} else {
|
||||
process.task.kill();
|
||||
}
|
||||
} catch (error) {
|
||||
print(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ function Terminal() {
|
||||
this._echo = true;
|
||||
this._readLine = null;
|
||||
this._selected = null;
|
||||
this._corked = 0;
|
||||
this._onOutput = null;
|
||||
return this;
|
||||
}
|
||||
@ -61,9 +60,7 @@ Terminal.prototype.print = function() {
|
||||
this._firstLine = this._index - Terminal.kBacklog;
|
||||
this._lines = this._lines.slice(this._lines.length - Terminal.kBacklog);
|
||||
}
|
||||
if (this._corked == 0) {
|
||||
this.dispatch();
|
||||
}
|
||||
this._lastWrite = new Date();
|
||||
}
|
||||
|
||||
@ -93,16 +90,6 @@ Terminal.prototype.readLine = function() {
|
||||
});
|
||||
}
|
||||
|
||||
Terminal.prototype.cork = function() {
|
||||
this._corked++;
|
||||
}
|
||||
|
||||
Terminal.prototype.uncork = function() {
|
||||
if (--this._corked == 0) {
|
||||
this.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
Terminal.prototype.makeFunction = function(api) {
|
||||
let self = this;
|
||||
return function() {
|
||||
|
Loading…
Reference in New Issue
Block a user