blob: 45156fbb1540f8e600b6ded0f7b974674031325b [file] [log] [blame]
Iftekharul Islamcd789502017-04-19 14:37:55 -05001/**
2 * Controller for server
3 *
4 * @module app/serverControl
5 * @exports remoteConsoleController
6 * @name remoteConsoleController
Iftekharul Islamcd789502017-04-19 14:37:55 -05007 */
8
Andrew Geisslerd27bb132018-05-24 11:07:27 -07009import {hterm, lib} from 'hterm-umdjs';
Ed Tanousbbcf6702017-10-06 13:53:06 -070010
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070011window.angular && (function(angular) {
12 'use strict';
Iftekharul Islamcd789502017-04-19 14:37:55 -050013
Andrew Geisslerd27bb132018-05-24 11:07:27 -070014 angular.module('app.serverControl').controller('remoteConsoleController', [
15 '$scope', '$window', 'APIUtils', 'dataService',
16 function($scope, $window, APIUtils, dataService) {
17 $scope.dataService = dataService;
Michael Davis8b522062017-05-05 09:21:07 -050018
Andrew Geisslerd27bb132018-05-24 11:07:27 -070019 // See https://github.com/macton/hterm for available hterm options
Gunnar Millseedefd32018-02-28 17:02:34 -060020
Andrew Geisslerd27bb132018-05-24 11:07:27 -070021 hterm.defaultStorage = new lib.Storage.Local();
22 var term = new hterm.Terminal('host-console');
23 term.decorate(document.querySelector('#terminal'));
24 // Set cursor color
25 term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
26 // Set background color
27 term.prefs_.set('background-color', '#19273c');
28 // Allows keyboard input
29 term.installKeyboard();
Michael Davis8b522062017-05-05 09:21:07 -050030
Andrew Geisslerd27bb132018-05-24 11:07:27 -070031 // The BMC exposes a websocket at /console0. This can be read
32 // or written to access the host serial console.
33 var hostname = dataService.getHost().replace('https://', '');
34 var host = 'wss://' + hostname + '/console0';
35 var ws = new WebSocket(host);
36 ws.onmessage = function(evt) {
37 // websocket -> terminal
38 term.io.print(evt.data);
39 };
40
41 // terminal -> websocket
42 term.onTerminalReady = function() {
43 var io = term.io.push();
44 io.onVTKeystroke = function(str) {
45 ws.send(str);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070046 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -070047 io.sendString = function(str) {
48 ws.send(str);
49 };
50 };
Deepak Kodihalli15374c82018-04-17 05:49:46 -050051
Andrew Geisslerd27bb132018-05-24 11:07:27 -070052 ws.onopen = function() {
53 console.log('websocket opened');
54 };
55 ws.onclose = function() {
56 console.log('websocket closed');
57 };
58 $scope.$on('$destroy', function() {
59 if (ws) {
60 ws.close();
61 }
62 });
Michael Davis8b522062017-05-05 09:21:07 -050063
Andrew Geisslerd27bb132018-05-24 11:07:27 -070064 $scope.openTerminalWindow = function() {
65 dataService.setRemoteWindowActive();
66 $window.open(
67 '#/server-control/remote-console-window', 'Remote Console Window',
68 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=400');
69 };
70 }
71 ]);
Iftekharul Islamcd789502017-04-19 14:37:55 -050072
73})(angular);