1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import {hterm, lib} from 'hterm-umdjs';
window.angular && (function(angular) {
'use strict';
angular.module('app.common.directives').directive('serialConsole', [
function() {
return {
'restrict': 'E',
'template': require('./serial-console.html'),
'scope': {'path': '=', 'showTabBtn': '=?'},
'controller': [
'$scope', '$window', 'dataService',
function($scope, $window, dataService) {
$scope.dataService = dataService;
// See https://github.com/macton/hterm for available hterm options
hterm.defaultStorage = new lib.Storage.Local();
var term = new hterm.Terminal('host-console');
term.decorate(document.querySelector('#terminal'));
// Set cursor color
term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
// Set background color
term.prefs_.set('background-color', '#19273c');
// Allows keyboard input
term.installKeyboard();
// The BMC exposes a websocket at /console0. This can be read
// or written to access the host serial console.
var hostname = dataService.getHost().replace('https://', '');
var host = 'wss://' + hostname + '/console0';
var ws = new WebSocket(host);
ws.onmessage = function(evt) {
// websocket -> terminal
term.io.print(evt.data);
};
// terminal -> websocket
term.onTerminalReady = function() {
var io = term.io.push();
io.onVTKeystroke = function(str) {
ws.send(str);
};
io.sendString = function(str) {
ws.send(str);
};
};
ws.onopen = function() {
console.log('websocket opened');
};
ws.onclose = function(event) {
console.log(
'websocket closed. code: ' + event.code +
' reason: ' + event.reason);
};
$scope.openTerminalWindow = function() {
$window.open(
'#/server-control/remote-console-window',
'Remote Console Window',
'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=550');
};
}
]
};
}
]);
})(window.angular);
|