diff --git a/src/app.vue b/src/app.vue index 49b9047e..500edadc 100644 --- a/src/app.vue +++ b/src/app.vue @@ -1,48 +1,146 @@ @@ -55,7 +153,11 @@ } th { - text-align: right; + text-align: left; + } + + .ok { + background: #97f197; } } @@ -80,10 +182,6 @@ return this.neko.state.member.is_controlling } - get available_screen_sizes() { - return this.neko.state.screen.configurations - } - connect() { this.neko.connect('ws://192.168.1.20:3000/', 'admin', 'test') } @@ -128,11 +226,8 @@ this.neko.events.on('clipboard.update', (text) => { console.log('clipboard.update', text) }) - this.neko.events.on('screen.configuration', (configurations) => { - console.log('screen.configuration', configurations) - }) - this.neko.events.on('screen.size', (width, height, rate) => { - console.log('screen.size', width, height, rate) + this.neko.events.on('screen.size', (id) => { + console.log('screen.size', id) }) this.neko.events.on('broadcast.status', (payload) => { console.log('broadcast.status', payload) diff --git a/src/components/canvas.vue b/src/components/canvas.vue index f8b3d638..7a47595a 100644 --- a/src/components/canvas.vue +++ b/src/components/canvas.vue @@ -12,7 +12,7 @@ :screenHeight="state.screen.size.height" :isControling="state.member.is_controlling" :scrollSensitivity="state.control.scroll.sensitivity" - :scrollInvert="state.control.scroll.invert" + :scrollInvert="state.control.scroll.inverse" /> @@ -51,6 +51,7 @@ import { NekoWebSocket } from '~/internal/websocket' import { NekoWebRTC } from '~/internal/webrtc' import { NekoMessages } from '~/internal/messages' + import { register as VideoRegister } from '~/internal/video' import NekoState from '~/types/state' import Overlay from './overlay.vue' @@ -93,7 +94,7 @@ control: { scroll: { inverse: true, - sensitivity: 10, + sensitivity: 1, }, host: null, }, @@ -125,6 +126,11 @@ return this.state.connection.websocket == 'connected' && this.state.connection.webrtc == 'connected' } + @Watch('state.screen.size') + onScreenSizeChanged() { + this.onResize() + } + public control = { request: () => { this.websocket.send('control/request') @@ -174,6 +180,9 @@ Vue.set(this.state.member, 'is_controlling', id != null && id === this.state.member.id) }) + // Video + VideoRegister(this.video, this.state.video) + // WebSocket this.websocket.on('message', async (event: string, payload: any) => { switch (event) { @@ -185,40 +194,6 @@ this.websocket.send('signal/answer', { sdp, displayname: this.state.member.name }) } catch (e) {} break - case 'screen/resolution': - Vue.set(this.state.screen, 'size', payload) - this.onResize() - break - case 'screen/configurations': - let data = [] - for (const i of Object.keys(payload.configurations)) { - const { width, height, rates } = payload.configurations[i] - if (width >= 600 && height >= 300) { - for (const j of Object.keys(rates)) { - const rate = rates[j] - if (rate === 30 || rate === 60) { - data.push({ - width, - height, - rate, - }) - } - } - } - } - - let conf = data.sort((a, b) => { - if (b.width === a.width && b.height == a.height) { - return b.rate - a.rate - } else if (b.width === a.width) { - return b.height - a.height - } - return b.width - a.width - }) - - Vue.set(this.state.screen, 'configurations', conf) - this.onResize() - break } }) this.websocket.on('connecting', () => { @@ -261,6 +236,8 @@ this.webrtc.on('disconnected', () => { Vue.set(this.state.connection, 'webrtc', 'disconnected') this.events.emit('system.webrtc', 'disconnected') + // @ts-ignore + this.video.src = null }) } diff --git a/src/internal/messages.ts b/src/internal/messages.ts index 2e0ccc98..3f4cce5a 100644 --- a/src/internal/messages.ts +++ b/src/internal/messages.ts @@ -1,3 +1,4 @@ +import Vue from 'vue' import { Member, ScreenConfigurations } from '../types/structs' import { EVENT } from '../types/events' import { @@ -31,8 +32,7 @@ export interface NekoEvents { ['control.request']: (id: string) => void ['control.requesting']: (id: string) => void ['clipboard.update']: (text: string) => void - ['screen.configuration']: (configurations: ScreenConfigurations) => void - ['screen.size']: (width: number, height: number, rate: number) => void + ['screen.size']: (id: string) => void ['broadcast.status']: (url: string, isActive: boolean) => void ['member.ban']: (id: string, target: string) => void ['member.kick']: (id: string, target: string) => void @@ -132,15 +132,38 @@ export class NekoMessages extends EventEmitter { // Screen Events ///////////////////////////// protected [EVENT.SCREEN.CONFIGURATIONS]({ configurations }: ScreenConfigurationsPayload) { - console.log('EVENT.SCREEN.CONFIGURATIONS') - this.emit('screen.configuration', configurations) - //video.setConfigurations(configurations) + let data = [] + for (const i of Object.keys(configurations)) { + const { width, height, rates } = configurations[i] + if (width >= 600 && height >= 300) { + for (const j of Object.keys(rates)) { + const rate = rates[j] + if (rate === 30 || rate === 60) { + data.push({ + width, + height, + rate, + }) + } + } + } + } + + let conf = data.sort((a, b) => { + if (b.width === a.width && b.height == a.height) { + return b.rate - a.rate + } else if (b.width === a.width) { + return b.height - a.height + } + return b.width - a.width + }) + + Vue.set(this.state.screen, 'configurations', conf) } protected [EVENT.SCREEN.RESOLUTION]({ id, width, height, rate }: ScreenResolutionPayload) { - console.log('EVENT.SCREEN.RESOLUTION') - this.emit('screen.size', width, height, rate) - //video.setResolution({ width, height, rate }) + Vue.set(this.state.screen, 'size', { width, height, rate }) + if (id) this.emit('screen.size', id) } ///////////////////////////// diff --git a/src/internal/video.ts b/src/internal/video.ts new file mode 100644 index 00000000..fdd99800 --- /dev/null +++ b/src/internal/video.ts @@ -0,0 +1,25 @@ +import Vue from 'vue' +import { Video } from '~/types/state' + +export function register(el: HTMLVideoElement, state: Video) { + el.addEventListener('canplaythrough', () => { + Vue.set(state, 'playable', true) + }) + el.addEventListener('playing', () => { + Vue.set(state, 'playing', true) + }) + el.addEventListener('pause', () => { + Vue.set(state, 'playing', false) + }) + el.addEventListener('emptied', () => { + Vue.set(state, 'playable', false) + Vue.set(state, 'playing', false) + }) + el.addEventListener('error', () => { + Vue.set(state, 'playable', false) + Vue.set(state, 'playing', false) + }) + el.addEventListener('volumechange', (value) => { + Vue.set(state, 'volume', value) + }) +}