Send binary frame in websocket client

Websockify 0.9.0 rejected receiving text frame:
8eb5cb0cdc
We have to switch to binary frame instead.

Change-Id: I2677b8879ccb27def22126811c347d5c08f5aada
Closes-Bug: #1847889
(cherry picked from commit ea2212ebe5)
This commit is contained in:
Hongbin Lu 2019-10-13 02:51:53 +00:00
parent 4b693661b5
commit 6443c4f83d
1 changed files with 10 additions and 2 deletions

View File

@ -62,7 +62,7 @@ limitations under the License.
socket.onopen = function() {
scope.$apply(scope.status);
// initialize by "hitting enter"
socket.send(String.fromCharCode(13));
socket.send(str2ab(String.fromCharCode(13)));
};
socket.onclose = function() {
scope.$apply(scope.status);
@ -111,7 +111,7 @@ limitations under the License.
resizeTerminal();
term.on('data', function(data) {
socket.send(data);
socket.send(str2ab(data));
});
socket.onmessage = function(e) {
@ -141,4 +141,12 @@ limitations under the License.
};
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length); // 2 bytes for each char
var bufView = new Uint8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
}());