blob: c2e14357faf232711e3942932e3037807b721d4b [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 Geisslerba5e3f32018-05-24 10:58:00 -07009import {
10 hterm,
11 lib
12}
13from 'hterm-umdjs';
Ed Tanousbbcf6702017-10-06 13:53:06 -070014
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070015window.angular && (function(angular) {
16 'use strict';
Iftekharul Islamcd789502017-04-19 14:37:55 -050017
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070018 angular
19 .module('app.serverControl')
20 .controller('remoteConsoleController', [
21 '$scope',
22 '$window',
23 'APIUtils',
24 'dataService',
25 function($scope, $window, APIUtils, dataService) {
26 $scope.dataService = dataService;
Michael Davis8b522062017-05-05 09:21:07 -050027
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070028 // See https://github.com/macton/hterm for available hterm options
Gunnar Millseedefd32018-02-28 17:02:34 -060029
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070030 hterm.defaultStorage = new lib.Storage.Local();
31 var term = new hterm.Terminal('host-console');
32 term.decorate(document.querySelector('#terminal'));
33 //Set cursor color
34 term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
35 //Set background color
36 term.prefs_.set('background-color', '#19273c');
37 //Allows keyboard input
38 term.installKeyboard();
Michael Davis8b522062017-05-05 09:21:07 -050039
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070040 //The BMC exposes a websocket at /console0. This can be read
41 //or written to access the host serial console.
42 var hostname = dataService.getHost().replace('https://', '');
43 var host = 'wss://' + hostname + '/console0';
44 var ws = new WebSocket(host);
45 ws.onmessage = function(evt) {
46 //websocket -> terminal
47 term.io.print(evt.data);
48 };
Deepak Kodihalli15374c82018-04-17 05:49:46 -050049
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070050 //terminal -> websocket
51 term.onTerminalReady = function() {
52 var io = term.io.push();
53 io.onVTKeystroke = function(str) {
54 ws.send(str);
55 };
56 io.sendString = function(str) {
57 ws.send(str);
58 };
59 };
Michael Davis8b522062017-05-05 09:21:07 -050060
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070061 ws.onopen = function() {
62 console.log('websocket opened');
63 };
64 ws.onclose = function() {
65 console.log('websocket closed');
66 };
67 $scope.$on('$destroy', function() {
68 if (ws) {
69 ws.close();
70 }
71 });
Iftekharul Islamc4172b52017-09-06 10:43:20 -050072
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070073 $scope.openTerminalWindow = function() {
74 dataService.setRemoteWindowActive();
75 $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=no,width=600,height=400');
76 };
77 }
78 ]);
Iftekharul Islamcd789502017-04-19 14:37:55 -050079
80})(angular);