mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add screencast component.
This commit is contained in:
parent
28e6c25f4b
commit
1905d7fcd2
@ -1,7 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="component" class="neko-component">
|
<div ref="component" class="neko-component">
|
||||||
<div ref="container" class="neko-container">
|
<div ref="container" class="neko-container">
|
||||||
<video ref="video" :autoplay="autoplay" :muted="autoplay" playsinline />
|
<video
|
||||||
|
v-show="state.connection.type == 'webrtc'"
|
||||||
|
ref="video"
|
||||||
|
:autoplay="autoplay"
|
||||||
|
:muted="autoplay"
|
||||||
|
playsinline
|
||||||
|
/>
|
||||||
|
<neko-screencast v-if="state.connection.type == 'screencast'" :api="api.room" />
|
||||||
<neko-overlay
|
<neko-overlay
|
||||||
:webrtc="connection.webrtc"
|
:webrtc="connection.webrtc"
|
||||||
:scroll="state.control.scroll"
|
:scroll="state.control.scroll"
|
||||||
@ -32,7 +39,8 @@
|
|||||||
.neko-container {
|
.neko-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
video {
|
video,
|
||||||
|
img {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@ -63,11 +71,13 @@
|
|||||||
|
|
||||||
import NekoState from './types/state'
|
import NekoState from './types/state'
|
||||||
import Overlay from './overlay.vue'
|
import Overlay from './overlay.vue'
|
||||||
|
import Screencast from './screencast.vue'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'neko-canvas',
|
name: 'neko-canvas',
|
||||||
components: {
|
components: {
|
||||||
'neko-overlay': Overlay,
|
'neko-overlay': Overlay,
|
||||||
|
'neko-screencast': Screencast,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
|
53
src/component/screencast.vue
Normal file
53
src/component/screencast.vue
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<img ref="image" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Vue, Component, Ref, Watch, Prop } from 'vue-property-decorator'
|
||||||
|
import { RoomApi } from './api'
|
||||||
|
|
||||||
|
const REFRESH_RATE = 1e3
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
name: 'neko-screencast',
|
||||||
|
})
|
||||||
|
export default class extends Vue {
|
||||||
|
@Ref('image') readonly _image!: HTMLImageElement
|
||||||
|
active = false
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
private readonly api!: RoomApi
|
||||||
|
|
||||||
|
async loop() {
|
||||||
|
while (this.active) {
|
||||||
|
const lastLoad = Date.now()
|
||||||
|
|
||||||
|
if (this._image.src) {
|
||||||
|
URL.revokeObjectURL(this._image.src)
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await this.api.screenCastImage({ responseType: 'blob' })
|
||||||
|
this._image.src = URL.createObjectURL(res.data)
|
||||||
|
|
||||||
|
const delay = lastLoad - Date.now() + REFRESH_RATE
|
||||||
|
if (delay > 0) {
|
||||||
|
await new Promise((res) => setTimeout(res, delay))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async mounted() {
|
||||||
|
this.active = true
|
||||||
|
|
||||||
|
setTimeout(this.loop, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.active = false
|
||||||
|
|
||||||
|
if (this._image.src) {
|
||||||
|
URL.revokeObjectURL(this._image.src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user