mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add connection skeleton (WIP).
This commit is contained in:
parent
4497a18793
commit
af206457ab
70
src/component/internal/connection.ts
Normal file
70
src/component/internal/connection.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import EventEmitter from 'eventemitter3'
|
||||
|
||||
import { NekoWebSocket } from './websocket'
|
||||
import { NekoWebRTC, WebRTCStats } from './webrtc'
|
||||
|
||||
export interface NekoConnectionEvents {
|
||||
connecting: () => void
|
||||
connected: () => void
|
||||
disconnected: (error?: Error) => void
|
||||
}
|
||||
|
||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
staysConnected = false
|
||||
|
||||
websocket = new NekoWebSocket()
|
||||
webrtc = new NekoWebRTC()
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
//
|
||||
// websocket events
|
||||
//
|
||||
|
||||
this.websocket.on('message', async (event: string, payload: any) => {
|
||||
|
||||
})
|
||||
this.websocket.on('connecting', () => {
|
||||
|
||||
})
|
||||
this.websocket.on('connected', () => {
|
||||
|
||||
})
|
||||
this.websocket.on('disconnected', () => {
|
||||
|
||||
})
|
||||
|
||||
//
|
||||
// webrtc events
|
||||
//
|
||||
|
||||
this.webrtc.on('track', (event: RTCTrackEvent) => {
|
||||
|
||||
})
|
||||
this.webrtc.on('candidate', (candidate: RTCIceCandidateInit) => {
|
||||
|
||||
})
|
||||
this.webrtc.on('stats', (stats: WebRTCStats) => {
|
||||
|
||||
})
|
||||
this.webrtc.on('connecting', () => {
|
||||
|
||||
})
|
||||
this.webrtc.on('connected', () => {
|
||||
|
||||
})
|
||||
this.webrtc.on('disconnected', () => {
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public async connect(): Promise<void> {
|
||||
this.staysConnected = true
|
||||
}
|
||||
|
||||
public async disconnect(): Promise<void> {
|
||||
this.staysConnected = false
|
||||
}
|
||||
}
|
@ -55,7 +55,6 @@
|
||||
|
||||
import { Vue, Component, Ref, Watch, Prop } from 'vue-property-decorator'
|
||||
import ResizeObserver from 'resize-observer-polyfill'
|
||||
import EventEmitter from 'eventemitter3'
|
||||
|
||||
import { NekoApi, MembersApi, RoomApi } from './internal/api'
|
||||
import { NekoWebSocket } from './internal/websocket'
|
||||
@ -257,6 +256,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
public async websocketConnect() {
|
||||
if (!this.authenticated) {
|
||||
throw new Error('client not authenticated')
|
||||
@ -269,6 +269,7 @@
|
||||
await this.websocket.connect()
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
public websocketDisconnect() {
|
||||
if (!this.connected) {
|
||||
throw new Error('client not connected to websocket')
|
||||
@ -277,6 +278,7 @@
|
||||
this.websocket.disconnect(new Error('manual action'))
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
public webrtcConnect(video?: string) {
|
||||
if (!this.connected) {
|
||||
throw new Error('client not connected to websocket')
|
||||
@ -293,6 +295,7 @@
|
||||
this.websocket.send(EVENT.SIGNAL_REQUEST, { video: video })
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
public webrtcDisconnect() {
|
||||
if (!this.watching) {
|
||||
throw new Error('client not connected to webrtc')
|
||||
@ -422,6 +425,7 @@
|
||||
Vue.set(this.state.connection, 'websocket', 'connected')
|
||||
this.events.emit('connection.websocket', 'connected')
|
||||
|
||||
// TODO: Refactor.
|
||||
if (!this.watching && this.autoconnect) {
|
||||
this.webrtcConnect()
|
||||
}
|
||||
@ -516,6 +520,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
// periodically reconnect WebRTC
|
||||
if (this.connected && !webrtcReconnect) {
|
||||
webrtcReconnect = setInterval(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user