state: move authenticated out of connection.

This commit is contained in:
Miroslav Šedivý 2021-06-19 18:14:45 +02:00
parent 8960bb319f
commit a451d6a536
2 changed files with 10 additions and 14 deletions

View File

@ -99,8 +99,8 @@
// Public state // Public state
///////////////////////////// /////////////////////////////
public state = { public state = {
authenticated: false,
connection: { connection: {
authenticated: false,
websocket: 'disconnected', websocket: 'disconnected',
webrtc: { webrtc: {
status: 'disconnected', status: 'disconnected',
@ -147,10 +147,6 @@
///////////////////////////// /////////////////////////////
public connection = new NekoConnection(this.state.connection) public connection = new NekoConnection(this.state.connection)
public get authenticated() {
return this.state.connection.authenticated
}
public get connected() { public get connected() {
return this.state.connection.websocket == 'connected' return this.state.connection.websocket == 'connected'
} }
@ -189,8 +185,8 @@
this.disconnect() this.disconnect()
} }
if (this.authenticated) { if (this.state.authenticated) {
Vue.set(this.state.connection, 'authenticated', false) Vue.set(this.state, 'authenticated', false)
} }
// check if is user logged in // check if is user logged in
@ -202,7 +198,7 @@
} }
await this.api.session.whoami() await this.api.session.whoami()
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state, 'authenticated', true)
if (this.autoconnect) { if (this.autoconnect) {
await this.connect() await this.connect()
@ -211,7 +207,7 @@
} }
public async login(username: string, password: string) { public async login(username: string, password: string) {
if (this.authenticated) { if (this.state.authenticated) {
throw new Error('client already authenticated') throw new Error('client already authenticated')
} }
@ -225,7 +221,7 @@
} }
} }
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state, 'authenticated', true)
if (this.autoconnect) { if (this.autoconnect) {
await this.connect() await this.connect()
@ -233,7 +229,7 @@
} }
public async logout() { public async logout() {
if (!this.authenticated) { if (!this.state.authenticated) {
throw new Error('client not authenticated') throw new Error('client not authenticated')
} }
@ -251,13 +247,13 @@
localStorage.removeItem('neko_session') localStorage.removeItem('neko_session')
} }
Vue.set(this.state.connection, 'authenticated', false) Vue.set(this.state, 'authenticated', false)
} }
} }
// TODO: Refactor. // TODO: Refactor.
public async connect(video?: string) { public async connect(video?: string) {
if (!this.authenticated) { if (!this.state.authenticated) {
throw new Error('client not authenticated') throw new Error('client not authenticated')
} }

View File

@ -1,4 +1,5 @@
export default interface State { export default interface State {
authenticated: boolean
connection: Connection connection: Connection
video: Video video: Video
control: Control control: Control
@ -12,7 +13,6 @@ export default interface State {
///////////////////////////// /////////////////////////////
export interface Connection { export interface Connection {
authenticated: boolean
websocket: 'unavailable' | 'disconnected' | 'connecting' | 'connected' websocket: 'unavailable' | 'disconnected' | 'connecting' | 'connected'
webrtc: WebRTC webrtc: WebRTC
type: 'webrtc' | 'fallback' | 'none' type: 'webrtc' | 'fallback' | 'none'