feat: support windows replay and need api support

需要API支持
api 修改 http.get('/api/terminal/v1/sessions/' + token + '/replay');
该API返回值应修改成
{ id: string, // session id
src: string, // 录像地址,例如/media/2018-04-23/xxxx.gz,
/media/2018-04-23/xxxx.mp4
type: string, // mp4 , json
height: int, // 高度
width: int, // 宽度
}

https://trello.com/c/DYNi38DI/285-windows%E5%BD%95%E5%83%8F%E6%92%AD%E6%94%BE%E5%92%8C%E4%BC%98%E5%8C%96linux%E6%92%AD%E6%94%BE
parent 5314efa1
...@@ -4,6 +4,7 @@ from flask import Flask, send_from_directory, render_template, request, jsonify, ...@@ -4,6 +4,7 @@ from flask import Flask, send_from_directory, render_template, request, jsonify,
from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room
import paramiko import paramiko
import uuid import uuid
from flask import Flask, request, current_app, redirect
app = Flask(__name__, template_folder='dist') app = Flask(__name__, template_folder='dist')
...@@ -55,6 +56,7 @@ class SSHws(Namespace): ...@@ -55,6 +56,7 @@ class SSHws(Namespace):
"room": str(uuid.uuid4()), "room": str(uuid.uuid4()),
"chan": dict() "chan": dict()
} }
print(request.sid)
join_room(self.clients[request.sid]["room"]) join_room(self.clients[request.sid]["room"])
# self.socketio.start_background_task(self.send_data, self) # self.socketio.start_background_task(self.send_data, self)
......
{ {
"/api": { "/api": {
"target": "http://127.0.0.1:5000", "target": "http://127.0.0.1:8088",
"secure": false "secure": false
}, },
"/luna/i18n": { "/luna/i18n": {
......
...@@ -24,7 +24,7 @@ const appRoutes: Routes = [ ...@@ -24,7 +24,7 @@ const appRoutes: Routes = [
// {path: 'users/login', component: LoginComponent}, // {path: 'users/login', component: LoginComponent},
{path: 'replay/:token', component: ReplayPageComponent}, {path: 'replay/:token', component: ReplayPageComponent},
{path: 'monitor/:token', component: MonitorPageComponent}, {path: 'monitor/:token', component: MonitorPageComponent},
// {path: 'test', component: TestPageComponent}, {path: 'test', component: TestPageComponent},
{path: 'connect', component: ConnectPageComponent}, {path: 'connect', component: ConnectPageComponent},
// {path: 'setting', component: SettingPageComponent}, // {path: 'setting', component: SettingPageComponent},
{path: 'undefined', component: BlankPageComponent}, {path: 'undefined', component: BlankPageComponent},
......
...@@ -126,6 +126,10 @@ export class HttpService { ...@@ -126,6 +126,10 @@ export class HttpService {
return this.http.get('/api/terminal/v1/sessions/' + token + '/replay'); return this.http.get('/api/terminal/v1/sessions/' + token + '/replay');
} }
get_replay_json(src: string) {
return this.http.get(src);
}
get_user_id_from_token(token: string) { get_user_id_from_token(token: string) {
const params = new HttpParams() const params = new HttpParams()
.set('user-only', '1') .set('user-only', '1')
......
...@@ -26,13 +26,17 @@ export let Video: { ...@@ -26,13 +26,17 @@ export let Video: {
id: string, id: string,
src: string, src: string,
type: string, type: string,
height: number,
width: number,
json: object; json: object;
timelist: Array<number>; timelist: Array<number>;
totalTime: number; totalTime: number;
} = { } = {
id: 'sss', id: '',
src: 'sss', src: '',
type: 'json', type: '',
width: 0,
height: 0,
json: {}, json: {},
timelist: [], timelist: [],
totalTime: 0, totalTime: 0,
......
import {Component, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {Video, term} from '../../globals'; import {Video, term} from '../../globals';
import {HttpService, LogService} from '../../app.service';
@Component({ @Component({
selector: 'app-json', selector: 'app-replay-json',
templateUrl: './json.component.html', templateUrl: './json.component.html',
styleUrls: ['./json.component.css'] styleUrls: ['./json.component.css']
}) })
...@@ -17,10 +18,26 @@ export class JsonComponent implements OnInit { ...@@ -17,10 +18,26 @@ export class JsonComponent implements OnInit {
pos = 0; pos = 0;
scrubber: number; scrubber: number;
constructor() { constructor(private _http: HttpService,
private _logger: LogService) {
} }
ngOnInit() { ngOnInit() {
this._http.get_replay_json(Video.src)
.subscribe(
data => {
Video.json = data;
Video.timelist = Object.keys(Video.json).map(Number);
Video.timelist = Video.timelist.sort(function (a, b) {
return a - b;
});
Video.totalTime = Video.timelist[Video.timelist.length - 1] * 1000;
},
err => {
alert('无法下载');
this._logger.error(err);
}
);
const that = this; const that = this;
let r = true; let r = true;
window.onresize = function () { window.onresize = function () {
......
<p> <div [ngStyle]="{'width.px': Video.width,'height.px':Video.height}">
mp4 works! <video controls>
</p> <source [src]="Video.src" type="video/mp4">
Your browser does not support the video tag.
<br>
您的浏览器不支持,请升级
</video>
</div>
import { Component, OnInit } from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {Video} from '../../globals';
@Component({ @Component({
selector: 'app-mp4', selector: 'app-replay-mp4',
templateUrl: './mp4.component.html', templateUrl: './mp4.component.html',
styleUrls: ['./mp4.component.css'] styleUrls: ['./mp4.component.css']
}) })
export class Mp4Component implements OnInit { export class Mp4Component implements OnInit {
Video = Video;
constructor() { } constructor() {
}
ngOnInit() { ngOnInit() {
} }
......
<app-json></app-json> <app-replay-json *ngIf="Video.type=='json'"></app-replay-json>
<app-replay-mp4 *ngIf="Video.type=='mp4'"></app-replay-mp4>
...@@ -26,18 +26,16 @@ export class ReplayPageComponent implements OnInit { ...@@ -26,18 +26,16 @@ export class ReplayPageComponent implements OnInit {
this._http.get_replay(token) this._http.get_replay(token)
.subscribe( .subscribe(
data => { data => {
Video.type = 'json'; Video.type = data['type'];
Video.json = data; Video.src = data['src'];
Video.timelist = Object.keys(Video.json).map(Number); Video.id = data['id'];
Video.timelist = Video.timelist.sort(function (a, b) { Video.width = data['width'];
return a - b; Video.height = data['height'];
});
Video.totalTime = Video.timelist[Video.timelist.length - 1] * 1000;
}, },
err => { err => {
alert('无法下载'); alert('API请求出错');
this._logger.error(err); this._logger.error(err);
}, }
); );
} }
......
<app-element-elfinder></app-element-elfinder> <app-replay-mp4></app-replay-mp4>
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {DataStore} from '../globals'; import {Video, DataStore} from '../globals';
@Component({ @Component({
selector: 'app-test-page', selector: 'app-test-page',
...@@ -7,12 +7,17 @@ import {DataStore} from '../globals'; ...@@ -7,12 +7,17 @@ import {DataStore} from '../globals';
styleUrls: ['./test-page.component.scss'] styleUrls: ['./test-page.component.scss']
}) })
export class TestPageComponent implements OnInit { export class TestPageComponent implements OnInit {
Video = Video;
constructor() { constructor() {
DataStore.NavShow = false; DataStore.NavShow = false;
} }
ngOnInit() { ngOnInit() {
this.Video.id = 'asfafdasd';
this.Video.src = 'https://www.w3schools.com/tags/movie.mp4';
this.Video.height = 240;
this.Video.width = 320;
} }
} }
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