Skip to content

Commit

Permalink
perf: support mp4 replay
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Apr 28, 2023
1 parent 270e814 commit 9f428ff
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {ElementDownloadDialogComponent} from './elements/connect/download-dialog
import {ElementACLDialogComponent} from './elements/connect/acl-dialog/acl-dialog.component';
import {ElementDialogAlertComponent} from './elements/dialog/dialog.service';
import {ClipboardService} from 'ngx-clipboard';
import { ElementsReplayMp4Component } from './elements/replay/mp4/mp4.component';

export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, '/luna/assets/i18n/');
Expand Down Expand Up @@ -62,6 +63,7 @@ export function HttpLoaderFactory(http: HttpClient) {
...Pipes,
...ElementComponents,
...PagesComponents,
ElementsReplayMp4Component,
],
entryComponents: [
ChangLanWarningDialogComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/app/elements/elements.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {ElementAdvancedOptionComponent} from './connect/connect-dialog/advanced-
import {ElementConnectMethodComponent} from './connect/connect-dialog/connect-method/connect-method.component';
import {ElementDownloadDialogComponent} from './connect/download-dialog/download-dialog.component';
import {ElementACLDialogComponent} from './connect/acl-dialog/acl-dialog.component';
import { ElementsReplayMp4Component } from './replay/mp4/mp4.component';


export const ElementComponents = [
Expand Down Expand Up @@ -59,4 +60,5 @@ export const ElementComponents = [
ElementReplayAsciicastComponent,
ElementAdvancedOptionComponent,
ElementConnectMethodComponent,
ElementsReplayMp4Component,
];
Empty file.
31 changes: 31 additions & 0 deletions src/app/elements/replay/mp4/mp4.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="controls">
<span id="user" style="padding-left: 20px" *ngIf="replay.user">{{"user"| translate}} : {{replay.user}}</span>
<span id="asset" style="padding-left: 20px" *ngIf="replay.asset">{{"asset"| translate}} : {{replay.asset}}</span>
<span id="system_user" style="padding-left: 20px" *ngIf="replay.system_user">{{"system user"| translate}} : {{replay.system_user}}</span>
<span id="date_start" style="padding-left: 20px" *ngIf="replay.date_start">{{"start time"| translate}} : {{startTime}} </span>
<span id="download" style="padding-left: 30px" *ngIf="replay.download_url"><a type="button" [href]="replay.download_url">{{"download"| translate}}</a></span>
</div>
<div id="player">
<as-split direction="horizontal" gutterSize="0">
<as-split-area *ngIf="commands.length" [size]="15" [maxSize]="15" [minSize]="0" order="0">
<div class="command-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="50"
(scrolled)="onScroll()"
[scrollWindow]="false">
<div class="item" *ngFor="let item of commands" (click)="commandClick(item)">
<div class="command" [title]="item.input">{{ item.input }}</div>
<div class="timestamp">{{ item.atime }}</div>
</div>
</div>
</as-split-area>
<as-split-area [size]="85" [maxSize]="100" [minSize]="85" order="1">
<div id="screen">
<video controls [height]="height" [width]="width">
<source [src]="replay.src" type="video/mp4">
</video>
</div>
</as-split-area>
</as-split>
</div>
25 changes: 25 additions & 0 deletions src/app/elements/replay/mp4/mp4.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ElementsReplayMp4Component } from './mp4.component';

describe('ElementsReplayMp4Component', () => {
let component: ElementsReplayMp4Component;
let fixture: ComponentFixture<ElementsReplayMp4Component>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ElementsReplayMp4Component ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ElementsReplayMp4Component);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
66 changes: 66 additions & 0 deletions src/app/elements/replay/mp4/mp4.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Component, OnInit,Input } from '@angular/core';
import {Replay,Command} from '@app/model';
import {HttpService} from '@app/services';
import {TranslateService} from '@ngx-translate/core';
import {formatTime} from '@app/utils/common';

@Component({
selector: 'elements-replay-mp4',
templateUrl: './mp4.component.html',
styleUrls: ['./mp4.component.css']
})
export class ElementsReplayMp4Component implements OnInit {
@Input() replay: Replay;
startTime = null;
startTimeStamp = null;
commands: Command[];
page = 0;
height = 0;
width = 0;

constructor(private _http: HttpService, private _translate: TranslateService) { }

ngOnInit() {
this.commands = new Array<Command>();
const date = new Date(Date.parse(this.replay.date_start));
this.startTime = this.toSafeLocalDateStr(date);
this.startTimeStamp = Date.parse(this.replay.date_start);
this.getCommands(this.page);
this.height = window.innerHeight - 100;
this.width = window.innerWidth - 100;
}

toSafeLocalDateStr(d) {
const date_s = d.toLocaleString(this.getUserLang(), {hour12: false});
return date_s.split('/').join('-');
}

getUserLang() {
const userLangEN = document.cookie.indexOf('django_language=en');
if (userLangEN === -1) {
return 'zh-CN';
} else {
return 'en-US';
}
}

getCommands(page: number) {
if (!this.startTimeStamp) {
return;
}
this._http.getCommandsData(this.replay.id, page)
.subscribe(
data => {
const results = data.results;
results.forEach(element => {
element.atime = formatTime(element.timestamp * 1000 - this.startTimeStamp);
});
this.commands = this.commands.concat(results);
},
err => {
alert('没找到命令记录');
}
);
}

}
1 change: 1 addition & 0 deletions src/app/pages/replay/replay.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<elements-replay-json [replay]="replay" *ngIf="replay.type=='json'"></elements-replay-json>
<elements-replay-guacamole [replay]="replay" *ngIf="replay.type=='guacamole'"></elements-replay-guacamole>
<elements-replay-asciicast [replay]="replay" *ngIf="replay.type=='asciicast'"></elements-replay-asciicast>
<elements-replay-mp4 [replay]="replay" *ngIf="replay.type=='mp4'"></elements-replay-mp4>
<div id="loading">
<div class="lds-spinner" *ngIf="isLoad()">
<div></div>
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/replay/replay.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class PagesReplayComponent implements OnInit {
const supportedType = {
'json': true,
'guacamole': true,
'asciicast': true};
'asciicast': true,
'mp4': true,};
return !supportedType[tp];
}
}

0 comments on commit 9f428ff

Please sign in to comment.