blob: 8227e18b35170eb3bb4e8cb7c49381c45cb89dcb [file] [log] [blame]
beccabroek457ca042018-09-07 17:18:24 -05001import {Terminal} from 'xterm';
2import style from 'xterm/dist/xterm.css';
3import * as attach from 'xterm/lib/addons/attach/attach';
4import * as fit from 'xterm/lib/addons/fit/fit';
Yang Cheng6d1d6002019-02-27 11:16:24 +08005var configJSON = require('../../../config.json');
6if (configJSON.keyType == 'VT100+') {
7 var vt100PlusKey = require('./vt100plus');
8}
beccabroek457ca042018-09-07 17:18:24 -05009
Yang Cheng6d1d6002019-02-27 11:16:24 +080010var customKeyHandlers = function(ev) {
11 if (configJSON.keyType == 'VT100+') {
12 return vt100PlusKey.customVT100PlusKey(ev, this);
13 }
14 return true;
15};
beccabroek75697f92018-09-04 09:34:44 -050016
17window.angular && (function(angular) {
18 'use strict';
19
20 angular.module('app.common.directives').directive('serialConsole', [
21 function() {
22 return {
23 'restrict': 'E',
24 'template': require('./serial-console.html'),
beccabroeka788cf02018-09-04 09:38:13 -050025 'scope': {'path': '=', 'showTabBtn': '=?'},
beccabroek75697f92018-09-04 09:34:44 -050026 'controller': [
27 '$scope', '$window', 'dataService',
28 function($scope, $window, dataService) {
29 $scope.dataService = dataService;
30
beccabroek457ca042018-09-07 17:18:24 -050031 // See https://github.com/xtermjs/xterm.js/ for available xterm
32 // options
beccabroek75697f92018-09-04 09:34:44 -050033
beccabroek457ca042018-09-07 17:18:24 -050034 Terminal.applyAddon(attach); // Apply the `attach` addon
35 Terminal.applyAddon(fit); // Apply the `fit` addon
beccabroek75697f92018-09-04 09:34:44 -050036
beccabroek457ca042018-09-07 17:18:24 -050037 var term = new Terminal();
38 term.open(document.getElementById('terminal'));
39 term.fit();
Yang Cheng6d1d6002019-02-27 11:16:24 +080040 if (configJSON.customKeyEnable == true) {
41 term.attachCustomKeyEventHandler(customKeyHandlers);
42 }
beccabroek457ca042018-09-07 17:18:24 -050043 var SOL_THEME = {
44 background: '#19273c',
45 cursor: 'rgba(83, 146, 255, .5)',
46 scrollbar: 'rgba(83, 146, 255, .5)'
47 };
48 term.setOption('theme', SOL_THEME);
beccabroek75697f92018-09-04 09:34:44 -050049 var hostname = dataService.getHost().replace('https://', '');
50 var host = 'wss://' + hostname + '/console0';
51 var ws = new WebSocket(host);
beccabroek457ca042018-09-07 17:18:24 -050052 term.attach(ws);
beccabroek75697f92018-09-04 09:34:44 -050053 ws.onopen = function() {
54 console.log('websocket opened');
55 };
56 ws.onclose = function(event) {
57 console.log(
58 'websocket closed. code: ' + event.code +
59 ' reason: ' + event.reason);
60 };
beccabroeka788cf02018-09-04 09:38:13 -050061 $scope.openTerminalWindow = function() {
62 $window.open(
63 '#/server-control/remote-console-window',
64 'Remote Console Window',
65 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=550');
66 };
beccabroek75697f92018-09-04 09:34:44 -050067 }
68 ]
69 };
70 }
71 ]);
72})(window.angular);