blob: ee6a5910c5c8b92297c1bd935ea30f693fd70b57 [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
Ed Tanousbbcf6702017-10-06 13:53:06 -07009import {hterm, lib} from 'hterm-umdjs';
10
Iftekharul Islamcd789502017-04-19 14:37:55 -050011window.angular && (function (angular) {
12 'use strict';
13
14 angular
15 .module('app.serverControl')
16 .controller('remoteConsoleController', [
Gunnar Millseedefd32018-02-28 17:02:34 -060017 '$scope',
18 '$window',
19 'APIUtils',
Iftekharul Islamcd789502017-04-19 14:37:55 -050020 'dataService',
21 function($scope, $window, APIUtils, dataService){
22 $scope.dataService = dataService;
Michael Davis8b522062017-05-05 09:21:07 -050023
24 // See https://github.com/macton/hterm for available hterm options
Gunnar Millseedefd32018-02-28 17:02:34 -060025
Michael Davis8b522062017-05-05 09:21:07 -050026 hterm.defaultStorage = new lib.Storage.Local();
Deepak Kodihalli15374c82018-04-17 05:49:46 -050027 var term = new hterm.Terminal("host-console");
28 term.decorate(document.querySelector('#terminal'));
29 //Set cursor color
30 term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
31 //Set background color
32 term.prefs_.set('background-color', '#19273c');
33 //Allows keyboard input
34 term.installKeyboard();
Michael Davis8b522062017-05-05 09:21:07 -050035
Deepak Kodihalli15374c82018-04-17 05:49:46 -050036 //The BMC exposes a websocket at /console0. This can be read
37 //or written to access the host serial console.
38 var hostname = dataService.getHost().replace("https://", '');
39 var host = "wss://" + hostname + "/console0";
40 var ws = new WebSocket(host);
41 ws.onmessage = function (evt) {
42 //websocket -> terminal
43 term.io.print(evt.data);
44 };
45
46 //terminal -> websocket
Michael Davis8b522062017-05-05 09:21:07 -050047 term.onTerminalReady = function() {
48 var io = term.io.push();
49 io.onVTKeystroke = function(str) {
Deepak Kodihalli15374c82018-04-17 05:49:46 -050050 ws.send(str);
Michael Davis8b522062017-05-05 09:21:07 -050051 };
52 io.sendString = function(str) {
Deepak Kodihalli15374c82018-04-17 05:49:46 -050053 ws.send(str);
Michael Davis8b522062017-05-05 09:21:07 -050054 };
55 };
Michael Davis8b522062017-05-05 09:21:07 -050056
Deepak Kodihalli15374c82018-04-17 05:49:46 -050057 ws.onopen = function() {
58 console.log("websocket opened");
59 };
60 ws.onclose = function() {
61 console.log("websocket closed");
62 };
63 $scope.$on("$destroy", function() {
64 if(ws) {
65 ws.close();
66 }
67 });
Iftekharul Islamc4172b52017-09-06 10:43:20 -050068
69 $scope.openTerminalWindow = function(){
70 dataService.setRemoteWindowActive();
71 $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');
72 }
Iftekharul Islamcd789502017-04-19 14:37:55 -050073 }
74 ]
75 );
76
77})(angular);