Skip to content

Commit 6eda9a7

Browse files
committed
perf: add viewer on watermark
1 parent 8950b49 commit 6eda9a7

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

src/app/pages/monitor/monitor.component.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
22
import {AppService, HttpService, I18nService, SettingService} from '@app/services';
33
import {ActivatedRoute} from '@angular/router';
4-
import {Session, Ticket} from '@app/model';
4+
import {Session, Ticket, User} from '@app/model';
55
import {ToastrService} from 'ngx-toastr';
66

77
@Component({
@@ -14,27 +14,37 @@ export class PagesMonitorComponent implements OnInit {
1414
iframeURL: string;
1515
sessionDetail: Session = null;
1616
sessionID: string;
17-
isPaused : boolean = false;
17+
isPaused: boolean = false;
1818
ticketID: string;
1919
ticketDetail: Ticket;
2020
supportedLock: boolean = false;
21+
user: User;
2122

2223
constructor(private _appService: AppService,
2324
private _settingSvc: SettingService,
2425
private _http: HttpService,
2526
private _route: ActivatedRoute,
2627
private _toastr: ToastrService,
27-
private _i18n: I18nService,) {
28+
private _i18n: I18nService) {
29+
this.getCurrentUser();
30+
}
31+
32+
getCurrentUser() {
33+
this._http.getUserProfile().subscribe(user => {
34+
this.user = user;
35+
});
2836
}
2937

3038
ngOnInit() {
3139
this._route.params.subscribe(params => {
3240
this.sessionID = params['sid'];
3341
this.generateMonitorURL().then(() => {
42+
const sessionObj = this.sessionDetail;
43+
const auditorUser = `${this._i18n.instant('Viewer')}: ${this.user.name}(${this.user.username})`;
44+
const sessionContent = `${this._i18n.instant('Operator')}: ${sessionObj.user}\n${sessionObj.asset}`;
45+
const content = `${auditorUser}\n${sessionContent}`;
3446
this._settingSvc.createWaterMarkIfNeed(
35-
this.windowRef.nativeElement,
36-
`${this.sessionDetail.user}\n${this.sessionDetail.asset}`
37-
);
47+
this.windowRef.nativeElement, content);
3848
});
3949
});
4050
this._route.queryParams.subscribe(params => {
@@ -81,11 +91,11 @@ export class PagesMonitorComponent implements OnInit {
8191
if (this.ticketID && !this.ticketDetail) {
8292
this._http.toggleLockSessionForTicket(this.ticketID, this.sessionID, !this.isPaused
8393
).then((res) => {
84-
this.handleToggleResponse(res).then()
94+
this.handleToggleResponse(res).then();
8595
});
86-
}else {
96+
} else {
8797
this._http.toggleLockSession(this.sessionID, !this.isPaused).then((res) => {
88-
this.handleToggleResponse(res).then()
98+
this.handleToggleResponse(res).then();
8999
});
90100
}
91101
}
@@ -94,8 +104,8 @@ export class PagesMonitorComponent implements OnInit {
94104
const pauseTaskMsg = await this._i18n.t('Pause task has been send');
95105
const resumeTaskMsg = await this._i18n.t('Resume task has been send');
96106
const session_ids = res['ok'];
97-
const msg = this.isPaused ? resumeTaskMsg:pauseTaskMsg;
98-
this._toastr.success(msg)
107+
const msg = this.isPaused ? resumeTaskMsg : pauseTaskMsg;
108+
this._toastr.success(msg);
99109
if (session_ids.indexOf(this.sessionID) !== -1) {
100110

101111
}

src/app/pages/replay/replay.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute} from '@angular/router';
3-
import {HttpService, LogService, SettingService} from '@app/services';
4-
import {Replay} from '@app/model';
3+
import {HttpService, I18nService, LogService, SettingService} from '@app/services';
4+
import {Replay, User} from '@app/model';
55

66
@Component({
77
selector: 'pages-replay',
@@ -10,11 +10,20 @@ import {Replay} from '@app/model';
1010
})
1111
export class PagesReplayComponent implements OnInit {
1212
replay: Replay = new Replay();
13+
user: User;
1314

1415
constructor(private route: ActivatedRoute,
1516
private _http: HttpService,
1617
private _settingSvc: SettingService,
18+
private _i18n: I18nService,
1719
private _logger: LogService) {
20+
this.getCurrentUser();
21+
}
22+
23+
getCurrentUser() {
24+
this._http.getUserProfile().subscribe(user => {
25+
this.user = user;
26+
});
1827
}
1928

2029
ngOnInit() {
@@ -34,8 +43,11 @@ export class PagesReplayComponent implements OnInit {
3443
Object.assign(this.replay, data);
3544
this.replay.id = sid;
3645
clearInterval(interval);
46+
const auditorUser = `${this._i18n.instant('Viewer')}: ${this.user.name}(${this.user.username})`;
47+
const sessionContent = `${this._i18n.instant('Operator')}: ${this.replay.user}\n${this.replay.asset}`;
48+
const content = `${auditorUser}\n${sessionContent}`;
3749
this._settingSvc.createWaterMarkIfNeed(
38-
document.body, `${this.replay.user}\n${this.replay.asset}`
50+
document.body, `${content}`
3951
);
4052
}
4153
},

src/app/utils/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function createWatermarkDiv(content, {
115115

116116
for (let n = 0; n < words.length; n++) {
117117
line = words[n];
118-
line = truncateCenter(line, 25);
118+
line = truncateCenter(line, 64);
119119
_ctx.fillText(line, x, y);
120120
y += _lineHeight;
121121
}

0 commit comments

Comments
 (0)