Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Controller for server |
| 3 | * |
| 4 | * @module app/serverControl |
| 5 | * @exports remoteConsoleController |
| 6 | * @name remoteConsoleController |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 9 | import { |
| 10 | hterm, |
| 11 | lib |
| 12 | } |
| 13 | from 'hterm-umdjs'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 14 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 15 | window.angular && (function(angular) { |
| 16 | 'use strict'; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 17 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 18 | 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 Davis | 8b52206 | 2017-05-05 09:21:07 -0500 | [diff] [blame] | 27 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 28 | // See https://github.com/macton/hterm for available hterm options |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 29 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 30 | 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 Davis | 8b52206 | 2017-05-05 09:21:07 -0500 | [diff] [blame] | 39 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 40 | //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 Kodihalli | 15374c8 | 2018-04-17 05:49:46 -0500 | [diff] [blame] | 49 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 50 | //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 Davis | 8b52206 | 2017-05-05 09:21:07 -0500 | [diff] [blame] | 60 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 61 | 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 Islam | c4172b5 | 2017-09-06 10:43:20 -0500 | [diff] [blame] | 72 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 73 | $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 Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 79 | |
| 80 | })(angular); |