blob: 71340df5017ccfaa77610a93ceb2a10782b42279 [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';
5
beccabroek75697f92018-09-04 09:34:44 -05006
7window.angular && (function(angular) {
8 'use strict';
9
10 angular.module('app.common.directives').directive('serialConsole', [
11 function() {
12 return {
13 'restrict': 'E',
14 'template': require('./serial-console.html'),
beccabroeka788cf02018-09-04 09:38:13 -050015 'scope': {'path': '=', 'showTabBtn': '=?'},
beccabroek75697f92018-09-04 09:34:44 -050016 'controller': [
17 '$scope', '$window', 'dataService',
18 function($scope, $window, dataService) {
19 $scope.dataService = dataService;
20
beccabroek457ca042018-09-07 17:18:24 -050021 // See https://github.com/xtermjs/xterm.js/ for available xterm
22 // options
beccabroek75697f92018-09-04 09:34:44 -050023
beccabroek457ca042018-09-07 17:18:24 -050024 Terminal.applyAddon(attach); // Apply the `attach` addon
25 Terminal.applyAddon(fit); // Apply the `fit` addon
beccabroek75697f92018-09-04 09:34:44 -050026
beccabroek457ca042018-09-07 17:18:24 -050027 var term = new Terminal();
28 term.open(document.getElementById('terminal'));
29 term.fit();
30 var SOL_THEME = {
31 background: '#19273c',
32 cursor: 'rgba(83, 146, 255, .5)',
33 scrollbar: 'rgba(83, 146, 255, .5)'
34 };
35 term.setOption('theme', SOL_THEME);
beccabroek75697f92018-09-04 09:34:44 -050036 var hostname = dataService.getHost().replace('https://', '');
37 var host = 'wss://' + hostname + '/console0';
38 var ws = new WebSocket(host);
beccabroek457ca042018-09-07 17:18:24 -050039 term.attach(ws);
beccabroek75697f92018-09-04 09:34:44 -050040 ws.onopen = function() {
41 console.log('websocket opened');
42 };
43 ws.onclose = function(event) {
44 console.log(
45 'websocket closed. code: ' + event.code +
46 ' reason: ' + event.reason);
47 };
beccabroeka788cf02018-09-04 09:38:13 -050048 $scope.openTerminalWindow = function() {
49 $window.open(
50 '#/server-control/remote-console-window',
51 'Remote Console Window',
52 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=550');
53 };
beccabroek75697f92018-09-04 09:34:44 -050054 }
55 ]
56 };
57 }
58 ]);
59})(window.angular);