1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core';
import {ElementRef} from '@angular/core';
import {term, Terminal, TermWS} from '../../globals';
import {NavList} from '../../ControlPage/control/control.component';
import * as jQuery from 'jquery/dist/jquery.min.js';
import {UUIDService} from '../../app.service';
import {CookieService} from 'ngx-cookie-service';
@Component({
selector: 'app-element-term',
templateUrl: './term.component.html',
styleUrls: ['./term.component.css']
})
export class ElementTermComponent implements OnInit, AfterViewInit {
@Input() host: any;
@Input() userid: any;
@Input() index: number;
@Input() token: string;
@Input() monitor: string;
@ViewChild('term') el: ElementRef;
secret: string;
term: any;
constructor(private _uuid: UUIDService,
private _cookie: CookieService) {
}
ngOnInit() {
this.secret = this._uuid.gen();
this.term = Terminal({
cols: 80,
rows: 24,
useStyle: true,
screenKeys: true,
});
// NavList.List[this.index].room = this.room;
}
ngAfterViewInit() {
if (this.host || this.token) {
if (this._cookie.get('cols')) {
term.col = parseInt(this._cookie.get('cols'), 10);
}
if (this._cookie.get('rows')) {
term.row = parseInt(this._cookie.get('rows'), 10);
}
} else {
term.col = Math.floor(jQuery(this.el.nativeElement).width() / jQuery('#liuzheng').width() * 8) - 3;
term.row = Math.floor(jQuery(this.el.nativeElement).height() / jQuery('#liuzheng').height()) - 3;
term.term = this.term;
}
this.term.open(this.el.nativeElement, true);
const that = this;
window.onresize = function () {
term.col = Math.floor(jQuery(that.el.nativeElement).width() / jQuery('#liuzheng').width() * 8) - 3;
term.row = Math.floor(jQuery(that.el.nativeElement).height() / jQuery('#liuzheng').height()) - 3;
if (term.col < 80) {
term.col = 80;
}
if (term.row < 24) {
term.row = 24;
}
that.term.resize(term.col, term.row);
if (that.host) {
that._cookie.set('cols', term.col.toString(), 99, '/', document.domain);
that._cookie.set('rows', term.row.toString(), 99, '/', document.domain);
TermWS.emit('resize', {'cols': term.col, 'rows': term.row});
}
};
jQuery(window).resize();
NavList.List[this.index].Term = this.term;
if (this.host) {
TermWS.emit('host', {'uuid': this.host.id, 'userid': this.userid, 'secret': this.secret});
}
if (this.token) {
TermWS.emit('token', {'token': this.token, 'secret': this.secret});
}
if (this.monitor) {
TermWS.emit('monitor', {'token': this.monitor, 'secret': this.secret});
} else {
this.term.on('data', function (data) {
TermWS.emit('data', {'data': data, 'room': NavList.List[that.index].room});
});
}
TermWS.on('data', function (data) {
if (data['room'] === NavList.List[that.index].room) {
that.term.write(data['data']);
}
});
TermWS.on('disconnect', function () {
that.TerminalDisconnect();
});
TermWS.on('logout', function (data) {
if (data['room'] === NavList.List[that.index].room) {
NavList.List[this.index].connected = false;
// this.term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
}
});
TermWS.on('room', function (data) {
if (data['secret'] === that.secret) {
NavList.List[that.index].room = data['room'];
}
});
}
TerminalDisconnect() {
NavList.List[this.index].connected = false;
// this.term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
TermWS.emit('logout', NavList.List[this.index].room);
}
}