mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove old connection events.
This commit is contained in:
parent
6ab5978ad0
commit
2c02a0f2f9
@ -1,7 +1,9 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
|
|
||||||
import { NekoWebSocket } from './websocket'
|
import { NekoWebSocket } from './websocket'
|
||||||
import { NekoWebRTC, WebRTCStats } from './webrtc'
|
import { NekoWebRTC, WebRTCStats } from './webrtc'
|
||||||
|
import { Connection } from '../types/state'
|
||||||
|
|
||||||
export interface NekoConnectionEvents {
|
export interface NekoConnectionEvents {
|
||||||
connecting: () => void
|
connecting: () => void
|
||||||
@ -12,15 +14,44 @@ export interface NekoConnectionEvents {
|
|||||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||||
private _url: string
|
private _url: string
|
||||||
private _token: string
|
private _token: string
|
||||||
|
private _state: Connection
|
||||||
|
|
||||||
public websocket = new NekoWebSocket()
|
public websocket = new NekoWebSocket()
|
||||||
public webrtc = new NekoWebRTC()
|
public webrtc = new NekoWebRTC()
|
||||||
|
|
||||||
constructor() {
|
constructor(state: Connection) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this._url = ''
|
this._url = ''
|
||||||
this._token = ''
|
this._token = ''
|
||||||
|
this._state = state
|
||||||
|
|
||||||
|
// initial state
|
||||||
|
Vue.set(this._state, 'type', 'webrtc')
|
||||||
|
Vue.set(this._state, 'websocket', this.websocket.supported ? 'disconnected' : 'unavailable')
|
||||||
|
Vue.set(this._state.webrtc, 'status', this.webrtc.supported ? 'disconnected' : 'unavailable')
|
||||||
|
|
||||||
|
// websocket
|
||||||
|
this.websocket.on('connecting', () => {
|
||||||
|
Vue.set(this._state, 'websocket', 'connecting')
|
||||||
|
})
|
||||||
|
this.websocket.on('connected', () => {
|
||||||
|
Vue.set(this._state, 'websocket', 'connected')
|
||||||
|
})
|
||||||
|
this.websocket.on('disconnected', () => {
|
||||||
|
Vue.set(this._state, 'websocket', 'disconnected')
|
||||||
|
})
|
||||||
|
|
||||||
|
// webrtc
|
||||||
|
this.webrtc.on('connecting', () => {
|
||||||
|
Vue.set(this._state.webrtc, 'status', 'connecting')
|
||||||
|
})
|
||||||
|
this.webrtc.on('connected', () => {
|
||||||
|
Vue.set(this._state.webrtc, 'status', 'connected')
|
||||||
|
})
|
||||||
|
this.webrtc.on('disconnected', () => {
|
||||||
|
Vue.set(this._state.webrtc, 'status', 'disconnected')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
|
@ -9,8 +9,6 @@ import NekoState from '../types/state'
|
|||||||
|
|
||||||
export interface NekoEvents {
|
export interface NekoEvents {
|
||||||
// connection events
|
// connection events
|
||||||
['connection.websocket']: (state: 'connected' | 'connecting' | 'disconnected') => void
|
|
||||||
['connection.webrtc']: (state: 'connected' | 'connecting' | 'disconnected') => void
|
|
||||||
['connection.webrtc.sdp']: (type: 'local' | 'remote', data: string) => void
|
['connection.webrtc.sdp']: (type: 'local' | 'remote', data: string) => void
|
||||||
['connection.webrtc.sdp.candidate']: (type: 'local' | 'remote', data: RTCIceCandidateInit) => void
|
['connection.webrtc.sdp.candidate']: (type: 'local' | 'remote', data: RTCIceCandidateInit) => void
|
||||||
['connection.disconnect']: (message: string) => void
|
['connection.disconnect']: (message: string) => void
|
||||||
|
@ -95,20 +95,15 @@
|
|||||||
@Prop({ type: Boolean })
|
@Prop({ type: Boolean })
|
||||||
private readonly autoplay!: boolean
|
private readonly autoplay!: boolean
|
||||||
|
|
||||||
/////////////////////////////
|
|
||||||
// Public connection manager
|
|
||||||
/////////////////////////////
|
|
||||||
public connection = new NekoConnection()
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Public state
|
// Public state
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
public state = {
|
public state = {
|
||||||
connection: {
|
connection: {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
websocket: this.connection.websocket.supported ? 'disconnected' : 'unavailable',
|
websocket: 'disconnected',
|
||||||
webrtc: {
|
webrtc: {
|
||||||
status: this.connection.webrtc.supported ? 'disconnected' : 'unavailable',
|
status: 'disconnected',
|
||||||
stats: null,
|
stats: null,
|
||||||
video: null,
|
video: null,
|
||||||
videos: [],
|
videos: [],
|
||||||
@ -147,6 +142,11 @@
|
|||||||
sessions: {},
|
sessions: {},
|
||||||
} as NekoState
|
} as NekoState
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Public connection manager
|
||||||
|
/////////////////////////////
|
||||||
|
public connection = new NekoConnection(this.state.connection)
|
||||||
|
|
||||||
public get authenticated() {
|
public get authenticated() {
|
||||||
return this.state.connection.authenticated
|
return this.state.connection.authenticated
|
||||||
}
|
}
|
||||||
@ -281,11 +281,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.connection.webrtc.disconnect()
|
this.connection.webrtc.disconnect()
|
||||||
this.events.emit('connection.webrtc', 'disconnected')
|
|
||||||
this.clearWebRTCState()
|
this.clearWebRTCState()
|
||||||
|
|
||||||
this.connection.disconnect()
|
this.connection.disconnect()
|
||||||
this.events.emit('connection.websocket', 'disconnected')
|
|
||||||
this.clearWebSocketState()
|
this.clearWebSocketState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,20 +382,6 @@
|
|||||||
// video events
|
// video events
|
||||||
VideoRegister(this._video, this.state.video)
|
VideoRegister(this._video, this.state.video)
|
||||||
|
|
||||||
// websocket
|
|
||||||
this.connection.websocket.on('connecting', () => {
|
|
||||||
Vue.set(this.state.connection, 'websocket', 'connecting')
|
|
||||||
this.events.emit('connection.websocket', 'connecting')
|
|
||||||
})
|
|
||||||
this.connection.websocket.on('connected', () => {
|
|
||||||
Vue.set(this.state.connection, 'websocket', 'connected')
|
|
||||||
this.events.emit('connection.websocket', 'connected')
|
|
||||||
})
|
|
||||||
this.connection.websocket.on('disconnected', () => {
|
|
||||||
this.events.emit('connection.websocket', 'disconnected')
|
|
||||||
this.clearWebSocketState()
|
|
||||||
})
|
|
||||||
|
|
||||||
// webrtc
|
// webrtc
|
||||||
this.connection.webrtc.on('track', (event: RTCTrackEvent) => {
|
this.connection.webrtc.on('track', (event: RTCTrackEvent) => {
|
||||||
const { track, streams } = event
|
const { track, streams } = event
|
||||||
@ -450,19 +434,6 @@
|
|||||||
webrtcCongestion = 0
|
webrtcCongestion = 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.connection.webrtc.on('connecting', () => {
|
|
||||||
Vue.set(this.state.connection.webrtc, 'status', 'connecting')
|
|
||||||
this.events.emit('connection.webrtc', 'connecting')
|
|
||||||
})
|
|
||||||
this.connection.webrtc.on('connected', () => {
|
|
||||||
Vue.set(this.state.connection.webrtc, 'status', 'connected')
|
|
||||||
Vue.set(this.state.connection, 'type', 'webrtc')
|
|
||||||
this.events.emit('connection.webrtc', 'connected')
|
|
||||||
})
|
|
||||||
this.connection.webrtc.on('disconnected', () => {
|
|
||||||
this.events.emit('connection.webrtc', 'disconnected')
|
|
||||||
this.clearWebRTCState()
|
|
||||||
})
|
|
||||||
|
|
||||||
// unmute on users first interaction
|
// unmute on users first interaction
|
||||||
if (this.autoplay) {
|
if (this.autoplay) {
|
||||||
|
Loading…
Reference in New Issue
Block a user