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:
2017-05-18 19:18:22 +00:00
parent fb776ef6c8
commit bbf980b672
3 changed files with 34 additions and 20 deletions

View File

@ -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'],
],
}));