From ea2212ebe59567d8ea21778cff5128e1029be045 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 13 Oct 2019 02:51:53 +0000 Subject: [PATCH] Send binary frame in websocket client Websockify 0.9.0 rejected receiving text frame: https://github.com/novnc/websockify/commit/8eb5cb0cdcd1314d6d763df8f226b587a2396aa2 We have to switch to binary frame instead. Change-Id: I2677b8879ccb27def22126811c347d5c08f5aada Closes-Bug: #1847889 --- .../static/js/angular/directives/serialConsole.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/static/js/angular/directives/serialConsole.js b/openstack_dashboard/static/js/angular/directives/serialConsole.js index c6ded3c954..df48e6b898 100644 --- a/openstack_dashboard/static/js/angular/directives/serialConsole.js +++ b/openstack_dashboard/static/js/angular/directives/serialConsole.js @@ -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; + } }());