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) {
|
function receive(data) {
|
||||||
for (var i in data.lines) {
|
for (var i in data.lines) {
|
||||||
var line = data.lines[i];
|
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;
|
var target = document.getElementsByClassName("terminal")[0].id;
|
||||||
if (line && line.terminal) {
|
if (line && line.terminal) {
|
||||||
if (document.getElementById("terminal_" + line.terminal)) {
|
if (document.getElementById("terminal_" + line.terminal)) {
|
||||||
@ -307,6 +328,7 @@ function receive(data) {
|
|||||||
}
|
}
|
||||||
line = line.value;
|
line = line.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line && line.action == "ping") {
|
if (line && line.action == "ping") {
|
||||||
gSocket.send(JSON.stringify({action: "pong"}));
|
gSocket.send(JSON.stringify({action: "pong"}));
|
||||||
} else if (line && line.action == "session") {
|
} else if (line && line.action == "session") {
|
||||||
@ -790,6 +812,9 @@ function connectSocket() {
|
|||||||
['watchPosition', 'options'],
|
['watchPosition', 'options'],
|
||||||
['clearWatch'],
|
['clearWatch'],
|
||||||
|
|
||||||
|
['cork'],
|
||||||
|
['uncork'],
|
||||||
|
|
||||||
['setSendDeviceOrientationEvents', 'value'],
|
['setSendDeviceOrientationEvents', 'value'],
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
|
14
core/core.js
14
core/core.js
@ -321,8 +321,6 @@ async function getProcess(packageOwner, packageName, key, options) {
|
|||||||
'readLine': process.terminal.readLine.bind(process.terminal),
|
'readLine': process.terminal.readLine.bind(process.terminal),
|
||||||
'setEcho': process.terminal.setEcho.bind(process.terminal),
|
'setEcho': process.terminal.setEcho.bind(process.terminal),
|
||||||
'select': process.terminal.select.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) {
|
if (options.terminalApi) {
|
||||||
for (let i in options.terminalApi) {
|
for (let i in options.terminalApi) {
|
||||||
@ -391,10 +389,14 @@ function updateProcesses(packageOwner, packageName) {
|
|||||||
var process = gProcesses[i];
|
var process = gProcesses[i];
|
||||||
if (process.packageOwner == packageOwner
|
if (process.packageOwner == packageOwner
|
||||||
&& process.packageName == packageName) {
|
&& process.packageName == packageName) {
|
||||||
if (process.terminal) {
|
try {
|
||||||
process.terminal.notifyUpdate();
|
if (process.terminal) {
|
||||||
} else {
|
process.terminal.notifyUpdate();
|
||||||
process.task.kill();
|
} else {
|
||||||
|
process.task.kill();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
print(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ function Terminal() {
|
|||||||
this._echo = true;
|
this._echo = true;
|
||||||
this._readLine = null;
|
this._readLine = null;
|
||||||
this._selected = null;
|
this._selected = null;
|
||||||
this._corked = 0;
|
|
||||||
this._onOutput = null;
|
this._onOutput = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -61,9 +60,7 @@ Terminal.prototype.print = function() {
|
|||||||
this._firstLine = this._index - Terminal.kBacklog;
|
this._firstLine = this._index - Terminal.kBacklog;
|
||||||
this._lines = this._lines.slice(this._lines.length - Terminal.kBacklog);
|
this._lines = this._lines.slice(this._lines.length - Terminal.kBacklog);
|
||||||
}
|
}
|
||||||
if (this._corked == 0) {
|
this.dispatch();
|
||||||
this.dispatch();
|
|
||||||
}
|
|
||||||
this._lastWrite = new Date();
|
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) {
|
Terminal.prototype.makeFunction = function(api) {
|
||||||
let self = this;
|
let self = this;
|
||||||
return function() {
|
return function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user