mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add websocket and webrtc to state.
This commit is contained in:
parent
ff7eafd5bd
commit
b38696596a
@ -50,5 +50,11 @@
|
|||||||
this.container.style.width = this.width
|
this.container.style.width = this.width
|
||||||
this.container.style.height = this.height
|
this.container.style.height = this.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.neko.events.on('connected', () => {
|
||||||
|
console.log('connected...')
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="component" class="component">
|
<div ref="component" class="component">
|
||||||
<div ref="container" class="player-container">
|
<div ref="container" class="player-container" v-show="state.websocket == 'connected' && state.webrtc == 'connected'">
|
||||||
<video ref="video" />
|
<video ref="video" />
|
||||||
<neko-overlay
|
<neko-overlay
|
||||||
v-if="websocket_state == 'connected' && webrtc_state == 'connected'"
|
|
||||||
:webrtc="webrtc"
|
:webrtc="webrtc"
|
||||||
:screenWidth="state.screen_size.width"
|
:screenWidth="state.screen_size.width"
|
||||||
:screenHeight="state.screen_size.height"
|
:screenHeight="state.screen_size.height"
|
||||||
@ -43,6 +42,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Vue, Component, Ref, Watch, Prop } from 'vue-property-decorator'
|
import { Vue, Component, Ref, Watch, Prop } from 'vue-property-decorator'
|
||||||
import ResizeObserver from 'resize-observer-polyfill'
|
import ResizeObserver from 'resize-observer-polyfill'
|
||||||
|
import EventEmitter from 'eventemitter3'
|
||||||
|
|
||||||
import { NekoWebSocket } from '~/internal/websocket'
|
import { NekoWebSocket } from '~/internal/websocket'
|
||||||
import { NekoWebRTC } from '~/internal/webrtc'
|
import { NekoWebRTC } from '~/internal/webrtc'
|
||||||
@ -51,6 +51,12 @@
|
|||||||
import NekoState from '~/types/state'
|
import NekoState from '~/types/state'
|
||||||
import Overlay from './overlay.vue'
|
import Overlay from './overlay.vue'
|
||||||
|
|
||||||
|
export interface NekoEvents {
|
||||||
|
connecting: () => void
|
||||||
|
connected: () => void
|
||||||
|
disconnected: (error?: Error) => void
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'neko-canvas',
|
name: 'neko-canvas',
|
||||||
components: {
|
components: {
|
||||||
@ -66,6 +72,7 @@
|
|||||||
private websocket = new NekoWebSocket()
|
private websocket = new NekoWebSocket()
|
||||||
private webrtc = new NekoWebRTC()
|
private webrtc = new NekoWebRTC()
|
||||||
private messages = new NekoMessages()
|
private messages = new NekoMessages()
|
||||||
|
public readonly events = new EventEmitter<NekoEvents>()
|
||||||
|
|
||||||
private state = {
|
private state = {
|
||||||
id: null,
|
id: null,
|
||||||
@ -76,11 +83,10 @@
|
|||||||
rate: 30,
|
rate: 30,
|
||||||
},
|
},
|
||||||
is_controlling: false,
|
is_controlling: false,
|
||||||
|
websocket: 'disconnected',
|
||||||
|
webrtc: 'disconnected',
|
||||||
} as NekoState
|
} as NekoState
|
||||||
|
|
||||||
private websocket_state = 'disconnected'
|
|
||||||
private webrtc_state = 'disconnected'
|
|
||||||
|
|
||||||
public control = {
|
public control = {
|
||||||
request: () => {
|
request: () => {
|
||||||
this.websocket.send('control/request')
|
this.websocket.send('control/request')
|
||||||
@ -146,13 +152,13 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.websocket.on('connecting', () => {
|
this.websocket.on('connecting', () => {
|
||||||
this.websocket_state = 'connecting'
|
Vue.set(this.state, 'websocket', 'connecting')
|
||||||
})
|
})
|
||||||
this.websocket.on('connected', () => {
|
this.websocket.on('connected', () => {
|
||||||
this.websocket_state = 'connected'
|
Vue.set(this.state, 'websocket', 'connected')
|
||||||
})
|
})
|
||||||
this.websocket.on('disconnected', () => {
|
this.websocket.on('disconnected', () => {
|
||||||
this.websocket_state = 'disconnected'
|
Vue.set(this.state, 'websocket', 'disconnected')
|
||||||
this.webrtc.disconnect()
|
this.webrtc.disconnect()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -174,13 +180,14 @@
|
|||||||
this.video.play()
|
this.video.play()
|
||||||
})
|
})
|
||||||
this.webrtc.on('connecting', () => {
|
this.webrtc.on('connecting', () => {
|
||||||
this.webrtc_state = 'connecting'
|
Vue.set(this.state, 'webrtc', 'connecting')
|
||||||
})
|
})
|
||||||
this.webrtc.on('connected', () => {
|
this.webrtc.on('connected', () => {
|
||||||
this.webrtc_state = 'connected'
|
Vue.set(this.state, 'webrtc', 'connected')
|
||||||
|
this.events.emit('connected')
|
||||||
})
|
})
|
||||||
this.webrtc.on('disconnected', () => {
|
this.webrtc.on('disconnected', () => {
|
||||||
this.webrtc_state = 'disconnected'
|
Vue.set(this.state, 'webrtc', 'disconnected')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,6 @@ export default interface State {
|
|||||||
id: string | null
|
id: string | null
|
||||||
display_name: string | null
|
display_name: string | null
|
||||||
screen_size: ScreenSize
|
screen_size: ScreenSize
|
||||||
|
websocket: 'connected' | 'connecting' | 'disconnected'
|
||||||
|
webrtc: 'connected' | 'connecting' | 'disconnected'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user