Skip to content

Commit

Permalink
perf: add viewer on watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jul 23, 2024
1 parent 8950b49 commit 6eda9a7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
32 changes: 21 additions & 11 deletions src/app/pages/monitor/monitor.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {AppService, HttpService, I18nService, SettingService} from '@app/services';
import {ActivatedRoute} from '@angular/router';
import {Session, Ticket} from '@app/model';
import {Session, Ticket, User} from '@app/model';
import {ToastrService} from 'ngx-toastr';

@Component({
Expand All @@ -14,27 +14,37 @@ export class PagesMonitorComponent implements OnInit {
iframeURL: string;
sessionDetail: Session = null;
sessionID: string;
isPaused : boolean = false;
isPaused: boolean = false;
ticketID: string;
ticketDetail: Ticket;
supportedLock: boolean = false;
user: User;

constructor(private _appService: AppService,
private _settingSvc: SettingService,
private _http: HttpService,
private _route: ActivatedRoute,
private _toastr: ToastrService,
private _i18n: I18nService,) {
private _i18n: I18nService) {
this.getCurrentUser();
}

getCurrentUser() {
this._http.getUserProfile().subscribe(user => {
this.user = user;
});
}

ngOnInit() {
this._route.params.subscribe(params => {
this.sessionID = params['sid'];
this.generateMonitorURL().then(() => {
const sessionObj = this.sessionDetail;
const auditorUser = `${this._i18n.instant('Viewer')}: ${this.user.name}(${this.user.username})`;
const sessionContent = `${this._i18n.instant('Operator')}: ${sessionObj.user}\n${sessionObj.asset}`;
const content = `${auditorUser}\n${sessionContent}`;
this._settingSvc.createWaterMarkIfNeed(
this.windowRef.nativeElement,
`${this.sessionDetail.user}\n${this.sessionDetail.asset}`
);
this.windowRef.nativeElement, content);
});
});
this._route.queryParams.subscribe(params => {
Expand Down Expand Up @@ -81,11 +91,11 @@ export class PagesMonitorComponent implements OnInit {
if (this.ticketID && !this.ticketDetail) {
this._http.toggleLockSessionForTicket(this.ticketID, this.sessionID, !this.isPaused
).then((res) => {
this.handleToggleResponse(res).then()
this.handleToggleResponse(res).then();
});
}else {
} else {
this._http.toggleLockSession(this.sessionID, !this.isPaused).then((res) => {
this.handleToggleResponse(res).then()
this.handleToggleResponse(res).then();
});
}
}
Expand All @@ -94,8 +104,8 @@ export class PagesMonitorComponent implements OnInit {
const pauseTaskMsg = await this._i18n.t('Pause task has been send');
const resumeTaskMsg = await this._i18n.t('Resume task has been send');
const session_ids = res['ok'];
const msg = this.isPaused ? resumeTaskMsg:pauseTaskMsg;
this._toastr.success(msg)
const msg = this.isPaused ? resumeTaskMsg : pauseTaskMsg;
this._toastr.success(msg);
if (session_ids.indexOf(this.sessionID) !== -1) {

}
Expand Down
18 changes: 15 additions & 3 deletions src/app/pages/replay/replay.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {HttpService, LogService, SettingService} from '@app/services';
import {Replay} from '@app/model';
import {HttpService, I18nService, LogService, SettingService} from '@app/services';
import {Replay, User} from '@app/model';

@Component({
selector: 'pages-replay',
Expand All @@ -10,11 +10,20 @@ import {Replay} from '@app/model';
})
export class PagesReplayComponent implements OnInit {
replay: Replay = new Replay();
user: User;

constructor(private route: ActivatedRoute,
private _http: HttpService,
private _settingSvc: SettingService,
private _i18n: I18nService,
private _logger: LogService) {
this.getCurrentUser();
}

getCurrentUser() {
this._http.getUserProfile().subscribe(user => {
this.user = user;
});
}

ngOnInit() {
Expand All @@ -34,8 +43,11 @@ export class PagesReplayComponent implements OnInit {
Object.assign(this.replay, data);
this.replay.id = sid;
clearInterval(interval);
const auditorUser = `${this._i18n.instant('Viewer')}: ${this.user.name}(${this.user.username})`;
const sessionContent = `${this._i18n.instant('Operator')}: ${this.replay.user}\n${this.replay.asset}`;
const content = `${auditorUser}\n${sessionContent}`;
this._settingSvc.createWaterMarkIfNeed(
document.body, `${this.replay.user}\n${this.replay.asset}`
document.body, `${content}`
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function createWatermarkDiv(content, {

for (let n = 0; n < words.length; n++) {
line = words[n];
line = truncateCenter(line, 25);
line = truncateCenter(line, 64);
_ctx.fillText(line, x, y);
y += _lineHeight;
}
Expand Down

0 comments on commit 6eda9a7

Please sign in to comment.