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
import {AfterViewInit, Component, Input, OnInit } from '@angular/core';
import {Terminal} from 'xterm';
import {NavList} from '../../pages/control/control/control.component';
import {UUIDService} from '../../app.service';
import {CookieService} from 'ngx-cookie-service';
import {TermWS} from '../../globals';
const ws = TermWS;
@Component({
selector: 'elements-ssh-term',
templateUrl: './ssh-term.component.html',
styleUrls: ['./ssh-term.component.scss']
})
export class ElementSshTermComponent implements OnInit, AfterViewInit {
@Input() host: any;
@Input() userid: any;
@Input() index: number;
@Input() token: string;
term: Terminal;
secret: string;
constructor(private _uuid: UUIDService, private _cookie: CookieService) {
}
ngOnInit() {
this.secret = this._uuid.gen();
const fontSize = localStorage.getItem('fontSize') || '14';
this.term = new Terminal({
fontFamily: 'monaco, Consolas, "Lucida Console", monospace',
fontSize: parseInt(fontSize, 10),
rightClickSelectsWord: true,
theme: {
background: '#1f1b1b'
}
});
}
ngAfterViewInit() {
this.joinRoom();
}
changeWinSize(size: Array<number>) {
ws.emit('resize', {'cols': size[0], 'rows': size[1]});
}
joinRoom() {
NavList.List[this.index].Term = this.term;
console.log(this.term);
console.log('Col: ', this.term.cols, 'rows', this.term.rows);
if (this.host) {
ws.emit('host', {
'uuid': this.host.id,
'userid': this.userid,
'secret': this.secret,
'size': [this.term.cols, this.term.rows]
});
}
if (this.token) {
ws.emit('token', {
'token': this.token, 'secret': this.secret,
'size': [this.term.cols, this.term.rows]
});
}
const that = this;
this.term.on('data', function (data) {
ws.emit('data', {'data': data, 'room': NavList.List[that.index].room});
});
ws.on('data', data => {
const view = NavList.List[that.index];
if (view && data['room'] === view.room) {
that.term.write(data['data']);
}
});
ws.on('disconnect', () => {
that.close();
});
ws.on('logout', (data) => {
if (data['room'] === NavList.List[that.index].room) {
NavList.List[that.index].connected = false;
}
});
ws.on('room', data => {
if (data['secret'] === this.secret) {
NavList.List[that.index].room = data['room'];
}
});
}
close() {
const view = NavList.List[this.index];
if (view) {
NavList.List[this.index].connected = false;
ws.emit('logout', NavList.List[this.index].room);
}
}
active() {
this.term.focus();
}
}