add authenticate function.

This commit is contained in:
Miroslav Šedivý 2021-06-19 21:32:09 +02:00
parent 45c6c33647
commit 5c8c8c1330

View File

@ -184,9 +184,18 @@
Vue.set(this.state, 'authenticated', false)
}
// check if is user logged in
if (this.autologin) {
const token = localStorage.getItem('neko_session')
if (!this.autologin) return
await this.authenticate()
if (!this.autoconnect) return
await this.connect()
}
public async authenticate(token?: string) {
if (!token && this.autologin) {
token = localStorage.getItem('neko_session') ?? undefined
}
if (token) {
this.api.setToken(token)
this.connection.setToken(token)
@ -195,9 +204,8 @@
await this.api.session.whoami()
Vue.set(this.state, 'authenticated', true)
if (this.autoconnect) {
await this.connect()
}
if (token && this.autologin) {
localStorage.setItem('neko_session', token)
}
}
@ -217,10 +225,6 @@
}
Vue.set(this.state, 'authenticated', true)
if (this.autoconnect) {
await this.connect()
}
}
public async logout() {
@ -246,7 +250,6 @@
}
}
// TODO: Refactor.
public async connect(video?: string) {
if (!this.state.authenticated) {
throw new Error('client not authenticated')
@ -312,7 +315,6 @@
this.connection.setVideo(video)
}
// TODO: Refactor.
public setWebRTCAuto(auto: boolean = true) {
Vue.set(this.state.connection.webrtc, 'auto', auto)
}
@ -363,7 +365,6 @@
this.clear()
})
// webrtc
this.connection.webrtc.on('track', (event: RTCTrackEvent) => {
const { track, streams } = event
if (track.kind === 'audio') return