1import {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 6 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'), 15 'scope': {'path': '=', 'showTabBtn': '=?'}, 16 'controller': [ 17 '$scope', '$window', 'dataService', 18 function($scope, $window, dataService) { 19 $scope.dataService = dataService; 20 21 // See https://github.com/xtermjs/xterm.js/ for available xterm 22 // options 23 24 Terminal.applyAddon(attach); // Apply the `attach` addon 25 Terminal.applyAddon(fit); // Apply the `fit` addon 26 27 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); 36 var hostname = dataService.getHost().replace('https://', ''); 37 var host = 'wss://' + hostname + '/console0'; 38 var ws = new WebSocket(host); 39 term.attach(ws); 40 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 }; 48 $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 }; 54 } 55 ] 56 }; 57 } 58 ]); 59})(window.angular); 60