Commit c9090d26 authored by ibuler's avatar ibuler

[Update] 修改录像播放

parent d0749ce7
...@@ -80,9 +80,6 @@ export class ElementReplayGuacamoleComponent implements OnInit { ...@@ -80,9 +80,6 @@ export class ElementReplayGuacamoleComponent implements OnInit {
recordingElement.style.margin = '0 auto'; recordingElement.style.margin = '0 auto';
this.screenRef.appendChild(recordingElement); this.screenRef.appendChild(recordingElement);
this.initRecording(); this.initRecording();
// this.toggle();
} }
initRecording() { initRecording() {
...@@ -99,7 +96,7 @@ export class ElementReplayGuacamoleComponent implements OnInit { ...@@ -99,7 +96,7 @@ export class ElementReplayGuacamoleComponent implements OnInit {
this.recording.onprogress = (millis) => { this.recording.onprogress = (millis) => {
this.duration = formatTime(millis); this.duration = formatTime(millis);
this.max = millis; this.max = millis;
this.toggle(); this.play();
}; };
// If paused, the play/pause button should read "Play" // If paused, the play/pause button should read "Play"
...@@ -140,13 +137,25 @@ export class ElementReplayGuacamoleComponent implements OnInit { ...@@ -140,13 +137,25 @@ export class ElementReplayGuacamoleComponent implements OnInit {
e.stopPropagation(); e.stopPropagation();
} }
toggle() { play() {
if (!this.recording.isPlaying()) { if (!this.recording.isPlaying()) {
this.recording.play(); this.recording.play();
this.isPlaying = true; this.isPlaying = true;
} else { }
}
pause() {
if (this.recording.isPlaying()) {
this.recording.pause(); this.recording.pause();
this.isPlaying = false; this.isPlaying = false;
} }
} }
toggle() {
if (!this.recording.isPlaying()) {
this.play();
} else {
this.pause();
}
}
} }
...@@ -14,13 +14,19 @@ ...@@ -14,13 +14,19 @@
<input id="scrubber" type="range" [(ngModel)]="time" min=0 [attr.max]="max" (mouseup)="runFrom()"/> <input id="scrubber" type="range" [(ngModel)]="time" min=0 [attr.max]="max" (mouseup)="runFrom()"/>
<span id="position">{{ position }}</span> <span id="position" style="padding-left: 10px">{{ position }}</span>
<span>/</span> <span>/</span>
<span id="duration">{{ duration }}</span> <span id="duration">{{ duration }}</span>
{{"Speed"|trans}}: {{speed}} {{"Speed"|trans}}: {{speed}}
<span style="float: right;padding-top: 5px;padding-right: 20px">
<span style="padding-left: 10px">{{"cols"|trans}}: <input type="number" style="width: 60px" [(ngModel)]="termCols"></span>
<span style="padding-left: 10px">{{"rows"|trans}}: <input type="number" style="width: 60px" [(ngModel)]="termRows"></span>
<span style="padding-left: 10px"><input type="button" value="{{'confirm'|trans}}" (click)="resizeTerm()"></span>
</span>
</div> </div>
<div id="winContainer" style="height: 90%;width: 100%"> <div id="winContainer" style="height: 90%;width: 100%">
<elements-term [term]="term"></elements-term> <elements-term #termRef [term]="term" [stopWatchWinChange]="true" (winSizeChangeTrigger)="onTermSizeChange($event)"></elements-term>
</div> </div>
<!--<asciinema-player></asciinema-player>--> <!--<asciinema-player></asciinema-player>-->
import {Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit, OnChanges} from '@angular/core';
import {Terminal} from 'xterm'; import {Terminal} from 'xterm';
import {HttpService, LogService} from '@app/services'; import {HttpService, LogService} from '@app/services';
import {Replay} from '@app/model'; import {Replay} from '@app/model';
...@@ -67,6 +67,9 @@ export class ElementReplayJsonComponent implements OnInit { ...@@ -67,6 +67,9 @@ export class ElementReplayJsonComponent implements OnInit {
timer: any; // 多长时间播放下一个 timer: any; // 多长时间播放下一个
pos = 0; // 播放点 pos = 0; // 播放点
term: Terminal; term: Terminal;
termCols = 80;
termRows = 24;
get position() { get position() {
return formatTime(this.time); return formatTime(this.time);
} }
...@@ -110,6 +113,7 @@ export class ElementReplayJsonComponent implements OnInit { ...@@ -110,6 +113,7 @@ export class ElementReplayJsonComponent implements OnInit {
clearInterval(this.timer); clearInterval(this.timer);
this.term.reset(); this.term.reset();
this.pos = 0; this.pos = 0;
this.time = 0;
this.isPlaying = true; this.isPlaying = true;
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.advance(); this.advance();
...@@ -173,4 +177,16 @@ export class ElementReplayJsonComponent implements OnInit { ...@@ -173,4 +177,16 @@ export class ElementReplayJsonComponent implements OnInit {
} }
this.advance(); this.advance();
} }
resizeTerm() {
this.term.resize(this.termCols, this.termRows);
this.restart();
}
onTermSizeChange(evt) {
setTimeout(() => {
this.termCols = evt[0];
this.termRows = evt[1];
}, 500);
}
} }
...@@ -3,7 +3,7 @@ import {ElementRef} from '@angular/core'; ...@@ -3,7 +3,7 @@ import {ElementRef} from '@angular/core';
import {Terminal} from 'xterm'; import {Terminal} from 'xterm';
import {fit} from 'xterm/lib/addons/fit/fit'; import {fit} from 'xterm/lib/addons/fit/fit';
import {LogService} from '@app/services'; import {LogService} from '@app/services';
import {Observable, fromEvent} from 'rxjs'; import {Observable, fromEvent, Subscription} from 'rxjs';
import {debounceTime, distinctUntilChanged } from 'rxjs/operators'; import {debounceTime, distinctUntilChanged } from 'rxjs/operators';
import * as $ from 'jquery/dist/jquery.min.js'; import * as $ from 'jquery/dist/jquery.min.js';
import 'rxjs/Observable'; import 'rxjs/Observable';
...@@ -18,12 +18,12 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -18,12 +18,12 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
@ViewChild('term') el: ElementRef; @ViewChild('term') el: ElementRef;
@Input() term: Terminal; @Input() term: Terminal;
@Input() offset: Array<number>; @Input() offset: Array<number>;
@Input() stopWatchWinChange = false;
@Output() winSizeChangeTrigger = new EventEmitter<Array<number>>(); @Output() winSizeChangeTrigger = new EventEmitter<Array<number>>();
winSizeChange$: Observable<any>; winSizeChange$: Observable<any>;
winSizeSub: Subscription;
constructor(private _logger: LogService) { constructor(private _logger: LogService) {}
}
ngOnInit() { ngOnInit() {
this.winSizeChange$ = fromEvent(window, 'resize').pipe( this.winSizeChange$ = fromEvent(window, 'resize').pipe(
...@@ -31,7 +31,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -31,7 +31,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
distinctUntilChanged(), distinctUntilChanged(),
); );
this.winSizeChange$ this.winSizeSub = this.winSizeChange$
.subscribe(() => { .subscribe(() => {
this._logger.debug('Get win size change event'); this._logger.debug('Get win size change event');
this.resizeTerm(); this.resizeTerm();
...@@ -41,6 +41,9 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -41,6 +41,9 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
ngAfterViewInit() { ngAfterViewInit() {
this.term.open(this.el.nativeElement); this.term.open(this.el.nativeElement);
this.resizeTerm(); this.resizeTerm();
if (this.stopWatchWinChange) {
this.winSizeSub.unsubscribe();
}
} }
getWinSize() { getWinSize() {
......
...@@ -74,5 +74,7 @@ ...@@ -74,5 +74,7 @@
"open in new window": "新窗口打开", "open in new window": "新窗口打开",
"setting": "设置", "setting": "设置",
"yes": "是", "yes": "是",
"no": "否" "no": "否",
"cols": "列数",
"rows": "行数"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment