-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
341 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
<template> | ||
<div class="content" v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="加载中"> | ||
<div class="header"> | ||
<el-row> | ||
<el-col :span="2" :offset="1"> | ||
<el-button round @click="$router.push({name:'mainPage'})" size="small">返回</el-button> | ||
</el-col> | ||
<el-col :span="2" :offset="4"> | ||
<el-button round disabled icon="el-icon-d-arrow-left" size="small">取消</el-button> | ||
</el-col> | ||
<el-col :span="3"> | ||
<el-button round icon="el-icon-video-play" @click="play" size="small">播放/暂停</el-button> | ||
</el-col> | ||
<el-col :span="2"> | ||
<el-button round disabled icon="el-icon-d-arrow-right" size="small">快进</el-button> | ||
</el-col> | ||
<el-col :span="2"> | ||
<el-button round icon="el-icon-refresh-right" @click="restart" size="small">重置</el-button> | ||
</el-col> | ||
<el-col :span="2" :offset="2"> | ||
<p style="line-height:32px;text-aligin:center;">{{this.position}}/{{this.duration}}</p> | ||
</el-col> | ||
<el-col :span="20" :offset="2"> | ||
<el-slider v-model="percentageTime" @change="runFrom" :format-tooltip="formatTooltip" :min="0" :max="100"></el-slider> | ||
</el-col> | ||
</el-row> | ||
</div> | ||
<div> | ||
<el-col :span="22" :offset="1" class="terminal"> | ||
<div ref="display" @click="play"></div> | ||
</el-col> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import * as Guacamole from 'guacamole-common-js-jumpserver/dist/guacamole-common' | ||
const fs = require('fs') | ||
const electron = require('electron') | ||
export default { | ||
name: 'guaplayer', | ||
components: {}, | ||
data () { | ||
return { | ||
replayData: '', | ||
fullscreenLoading: true, | ||
recording: '', | ||
display: '', | ||
recordingDisplay: '', | ||
max: 100, | ||
percent: 0, | ||
spend: 0, | ||
duration: '00:00', | ||
position: '00:00' | ||
} | ||
}, | ||
created: function () { | ||
this.loadfile() | ||
}, | ||
methods: { | ||
debugelement: function () { | ||
console.log(this.recording) | ||
}, | ||
formatTooltip: function (time) { | ||
return this.formatTime(time / 100 * this.max) | ||
}, | ||
loadfile: function () { | ||
let configDir = (electron.app || electron.remote.app).getPath('userData') | ||
fs.readFile((configDir + '/' + this.$route.params.name), 'utf-8', (err, basicdata) => { | ||
this.replayData = basicdata | ||
const tunnel = new Guacamole.StaticHTTPTunnel() | ||
this.recording = new Guacamole.SessionRecording(tunnel) | ||
this.display = this.recording.getDisplay() | ||
const displayElm = this.$refs.display | ||
displayElm.appendChild(this.display.getElement()) | ||
displayElm.addEventListener('contextmenu', e => { | ||
e.stopPropagation() | ||
if (e.preventDefault) { | ||
e.preventDefault() | ||
} | ||
e.returnValue = false | ||
}) | ||
this.fullscreenLoading = false | ||
this.recording.connect(this.replayData) | ||
this.initRecording() | ||
console.log(err) | ||
}) | ||
}, | ||
zeroPad: function (num, minLength) { | ||
let str = num.toString() | ||
// Add leading zeroes until string is long enough | ||
while (str.length < minLength) { | ||
str = '0' + str | ||
} | ||
return str | ||
}, | ||
formatTimeWithSeconds: function (seconds) { | ||
let hour = 0 | ||
let minute = 0 | ||
let second = 0 | ||
const ref = [3600, 60, 1] | ||
for (let i = 0; i < ref.length; i++) { | ||
const val = ref[i] | ||
while (val <= seconds) { | ||
seconds -= val | ||
switch (i) { | ||
case 0: | ||
hour++ | ||
break | ||
case 1: | ||
minute++ | ||
break | ||
case 2: | ||
second++ | ||
break | ||
} | ||
} | ||
} | ||
return [hour, minute, second] | ||
}, | ||
formatTime: function (millis) { | ||
const totalSeconds = millis / 1000 | ||
const [hour, minute, second] = this.formatTimeWithSeconds(totalSeconds) | ||
let time = this.zeroPad(minute, 2) + ':' + this.zeroPad(second, 2) | ||
if (hour > 0) { | ||
time = this.zeroPad(hour, 2) + ':' + time | ||
} | ||
return time | ||
}, | ||
initRecording: function () { | ||
this.recording.onplay = () => { | ||
this.isPlaying = true | ||
} | ||
this.recording.onresize = (width, height) => { | ||
console.log(width, height) | ||
// Do not scale if displayRef has no width | ||
// if (!height) { | ||
// return | ||
// } | ||
// Scale displayRef to fit width of container | ||
// const widthScale = this.displayRef.offsetWidth / width | ||
// const heightScale = this.displayRef.offsetHeight / height | ||
// const minScale = widthScale < heightScale ? widthScale : heightScale | ||
// this.recordingDisplay.scale(minScale) | ||
} | ||
this.recording.onseek = (millis) => { | ||
this.position = this.formatTime(millis) | ||
this.percent = millis | ||
} | ||
this.recording.onprogress = (millis) => { | ||
this.duration = this.formatTime(millis) | ||
this.max = millis | ||
this.play() | ||
} | ||
// If paused, the play/pause button should read "Play" | ||
this.recording.onpause = () => { | ||
this.isPlaying = false | ||
} | ||
this.recording.play() | ||
this.max = this.recording.getDuration() | ||
this.duration = this.formatTime(this.max) | ||
}, | ||
restart () { | ||
this.percent = 0 | ||
this.runFrom() | ||
}, | ||
runFrom: function () { | ||
// this.recording.seek(this.percentageTime / 100 * this.max) | ||
this.recording.seek(this.percentageTime / 100 * this.max, () => {}) | ||
}, | ||
cancelSeek: function (e) { | ||
this.recording.play() | ||
e.stopPropagation() | ||
}, | ||
play: function () { | ||
if (!this.recording.isPlaying()) { | ||
this.recording.play() | ||
this.isPlaying = true | ||
} else { | ||
this.recording.pause() | ||
this.isPlaying = false | ||
} | ||
} | ||
}, | ||
computed: { | ||
percentageTime: { | ||
get () { | ||
return this.percent / this.max * 100 | ||
}, | ||
set () { | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
<style lang="scss"> | ||
.content{ | ||
height: 100%; | ||
} | ||
.header{ | ||
padding-top: 15px; | ||
} | ||
.terminal{ | ||
width: 100%; | ||
height: calc(100% - 85px); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.