add autoconnect prop.

This commit is contained in:
Miroslav Šedivý 2021-05-09 20:33:43 +02:00
parent 9d4740f7e5
commit 31cfacd1df

View File

@ -86,14 +86,17 @@
height: 0, height: 0,
} }
@Prop({ type: Boolean }) @Prop({ type: String })
private readonly autoplay!: boolean private readonly server!: string
@Prop({ type: Boolean }) @Prop({ type: Boolean })
private readonly autologin!: boolean private readonly autologin!: boolean
@Prop({ type: String }) @Prop({ type: Boolean })
private readonly server!: string private readonly autoconnect!: boolean
@Prop({ type: Boolean })
private readonly autoplay!: boolean
///////////////////////////// /////////////////////////////
// Public state // Public state
@ -171,7 +174,7 @@
// Public methods // Public methods
///////////////////////////// /////////////////////////////
@Watch('server', { immediate: true }) @Watch('server', { immediate: true })
public setUrl(url: string) { public async setUrl(url: string) {
if (!url) { if (!url) {
url = location.href url = location.href
} }
@ -200,10 +203,12 @@
this.websocket.setToken(token) this.websocket.setToken(token)
} }
this.api.session.whoami().then(() => { await this.api.session.whoami()
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state.connection, 'authenticated', true)
if (this.autoconnect) {
this.websocket.connect() this.websocket.connect()
}) }
} }
} }
@ -223,8 +228,11 @@
} }
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state.connection, 'authenticated', true)
if (this.autoconnect) {
this.websocket.connect() this.websocket.connect()
} }
}
public async logout() { public async logout() {
if (!this.authenticated) { if (!this.authenticated) {