Create the terminal ws after fit()

part of cloudron/box#549
This commit is contained in:
Girish Ramakrishnan
2018-06-08 12:04:10 -07:00
parent 97f17916f9
commit 3eae49139c

View File

@@ -223,6 +223,25 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
});
};
function createTerminalSocket() {
try {
// websocket cannot use relative urls
var url = Client.apiOrigin.replace('https', 'wss') + '/api/v1/apps/' + $scope.selected.value + '/execws?tty=true&rows=' + $scope.terminal.rows + '&columns=' + $scope.terminal.cols + '&access_token=' + Client.getToken();
$scope.terminalSocket = new WebSocket(url);
$scope.terminal.attach($scope.terminalSocket);
$scope.terminalSocket.onclose = function () {
// retry in one second
$scope.terminalReconnectTimeout = setTimeout(function () {
showTerminal(true);
}, 1000);
};
} catch (e) {
console.error(e);
}
}
function showTerminal(retry) {
reset();
@@ -248,32 +267,20 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
window.terminal = $scope.terminal;
try {
// websocket cannot use relative urls
var url = Client.apiOrigin.replace('https', 'wss') + '/api/v1/apps/' + $scope.selected.value + '/execws?tty=true&rows=' + $scope.terminal.rows + '&columns=' + $scope.terminal.cols + '&access_token=' + Client.getToken();
$scope.terminalSocket = new WebSocket(url);
$scope.terminal.attach($scope.terminalSocket);
$scope.terminalSocket.onclose = function () {
// retry in one second
$scope.terminalReconnectTimeout = setTimeout(function () {
showTerminal(true);
}, 1000);
};
// Let the browser handle paste
$scope.terminal.attachCustomKeyEventHandler(function (e) {
if (e.key === 'v' && (e.ctrlKey || e.metaKey)) return false;
});
} catch (e) {
console.error(e);
}
// Let the browser handle paste
$scope.terminal.attachCustomKeyEventHandler(function (e) {
if (e.key === 'v' && (e.ctrlKey || e.metaKey)) return false;
});
if (retry) $scope.terminal.writeln('Reconnecting...');
else $scope.terminal.writeln('Connecting...');
// we have to give it some time to setup the terminal to make it fit, there is no event unfortunately
setTimeout(function () { if ($scope.terminal) $scope.terminal.fit(); }, 1000);
setTimeout(function () {
if (!$scope.terminal) return;
$scope.terminal.fit();
createTerminalSocket(); // create exec container after we fit() since we cannot resize exec container post-creation
}, 1000);
});
}