Skip to content

Commit

Permalink
[update]v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
orangemio committed Feb 8, 2020
1 parent d4f27d0 commit d085b5e
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"file-loader": "^1.1.11",
"guacamole-common-js-jumpserver": "^1.1.0-c",
"html-webpack-plugin": "^3.2.0",
"inject-loader": "^4.0.1",
"karma": "^2.0.2",
Expand Down
21 changes: 18 additions & 3 deletions src/renderer/components/mainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<div class="el-upload__tip" slot="tip">只能上传录像文件,且不超过500mb</div>
</el-upload>
</el-col>
<el-col :span="8" :offset="8" style="margin-top:20px;">
<el-radio v-model="type" label="1">Linux录像</el-radio>
<el-radio v-model="type" label="2">Windows录像</el-radio>
</el-col>
<el-col :span="4" :offset="10" style="margin-top:20px;">
<el-button round @click="play" type="primary">播放</el-button>
</el-col>
</el-row>
</div>
</template>
Expand All @@ -30,6 +37,8 @@ export default {
components: {},
data () {
return {
type: '1',
filename: '',
fullscreenLoading: false
}
},
Expand All @@ -41,16 +50,22 @@ export default {
},
uploadfile: function (data) {
const configDir = (electron.app || electron.remote.app).getPath('userData')
let filename = data.file.name.substring(0, data.file.name.length - 3)
compressing.gzip.uncompress(data.file.path, (configDir + '/' + filename))
this.filename = data.file.name.substring(0, data.file.name.length - 3)
compressing.gzip.uncompress(data.file.path, (configDir + '/' + this.filename))
.then(files => {
this.fullscreenLoading = true
return this.delay(5000).then(() => {
this.fullscreenLoading = false
this.$router.push({ name: 'linuxplayer', params: {name: filename} })
}
)
})
},
play: function () {
if (this.type === '1') {
this.$router.push({ name: 'linuxplayer', params: {name: this.filename} })
} else {
this.$router.push({ name: 'guaplayer', params: {name: this.filename} })
}
}
}
}
Expand Down
209 changes: 209 additions & 0 deletions src/renderer/components/player/guaPlayer.vue
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>
5 changes: 2 additions & 3 deletions src/renderer/components/player/linuxPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<el-button round @click="$router.push({name:'mainPage'})" size="small">返回</el-button>
</el-col>
<el-col :span="2" :offset="4">
<el-button round @click="speedDown" icon="el-icon-d-arrow-left" size="small">取消</el-button>
<el-button round @click="speedDown" disable icon="el-icon-d-arrow-left" size="small">取消</el-button>
</el-col>
<el-col :span="3">
<el-button round @click="toggle" icon="el-icon-video-play" size="small">播放/暂停</el-button>
</el-col>
<el-col :span="2">
<el-button round @click="speedUp" icon="el-icon-d-arrow-right" size="small">快进</el-button>
<el-button round @click="speedUp" disable icon="el-icon-d-arrow-right" size="small">快进</el-button>
</el-col>
<el-col :span="2">
<el-button round @click="restart" icon="el-icon-refresh-right" size="small">重置</el-button>
Expand All @@ -29,7 +29,6 @@
</el-row>
</div>
<el-main class="terminal">
<div></div>
<pre>{{term}}</pre>
</el-main>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default new Router({
name: 'linuxplayer',
component: require('@/components/player/linuxPlayer').default
},
{
path: '/guaplayer',
name: 'guaplayer',
component: require('@/components/player/guaPlayer').default
},
{
path: '*',
redirect: '/'
Expand Down
Loading

0 comments on commit d085b5e

Please sign in to comment.